Daily Archives

Articles indexed Wednesday December 22 2010

Page 12/32 | < Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >

  • 2 ways to create new object by setting property values

    - by Samvel Siradeghyan
    Hi all I have a class Question which has a property Text public class Question { public string Text { get; set; } } Now I wont create on object of this type by giving value to property. I can do that in this two ways: Question q = new Question { Text = "Some question" }; and Question q = new Question() { Text = "Some question" }; Is there any difference between this two cases and if they are the same, why we need both? Thanks.

    Read the article

  • Redirect faster with Greasemonkey

    - by Chad
    I'm using Greasemonkey to redirect certain URLs to another but I would like to redirect before the URL to be redirect loads. Currently I'm using this simple script: //==UserScript== // @name Redirect Google // @description Redirect Google to Yahoo! // @include http://*.google.com/* //==/UserScript== window.location.replace("http://www.yahoo.com") In the above, google appears for a second and then redirected to google. I want to go yahoo immediately. Is it possible, and how?

    Read the article

  • How to properly clean up JDBC resources in Java?

    - by user523086
    What is considered best practices when cleaning up JDBC resources and why? I kept the example short, thus just the cleaning up of the ResultSet. finally { if(rs != null) try{ rs.close(); } catch(SQLException ignored) {} } versus finally { try{ rs.close(); } catch(Exception ignored) {} } Personally I favour the second option since it is a bit shorter. Any input on this is much appreciated.

    Read the article

  • L2S DataContext out of synch: row not found or changed

    - by awrigley
    The Problem I am getting a number of errors that imply that the DataContext, or rather, the way I am using the DataContext is getting out of synch. The error occurs on db.SubmitChanges() where db is my DataContext instance. The error is: Row not found or changed. The problem only occurs intermitently, for example, adding a row then deleting it. If I stop the dev server and restart, the added row is there and I can delete it no problem. Ie, it seems that the problem is related to the DataContext losing track of the rows that have been added. IMPORTANT: Before anyone votes to close this thread, on the basis of it being a duplicate, I have checked the sql server profiler and there is no "Where 0 = 1" in the SQL. I have also recreated the dbml file, so am satisfied that the database schema is in synch with the schema represented by the dbml file. Ie, no cases of mismatched nullable/not nullable columns, etc. My Diagnosis (for what it is worth): It seems to be a problem related to how I am using the DataContext. I am new to MVC, Repositories and Services patterns, so suspect that I have wired things up wrong. The Setup Simple eLearning app in its early stages. Pupils need to be able to add and delete courses (Courses table) to their UserCourses. To do this, I have a service that gets a specific DataContext instance Dependency Injected into its constructor. Service Class Constructor: public class SqlPupilBlockService : IPupilBlockService { DataContext db; public SqlPupilBlockService(DataContext db) { this.db = db; CoursesRepository = new SqlRepository<Course>(db); UserCoursesRepository = new SqlRepository<UserCourse>(db); } // Etc, etc } The CoursesRepository and UserCoursesRepository are both private properties of the service class that are of Type IRepository (just a simple generic repository interface). Sql Respoitory Code: public class SqlRepository<T> : IRepository<T> where T : class { DataContext db; public SqlRepository(DataContext db) { this.db = db; } #region IRepository<T> Members public IQueryable<T> Query { get { return db.GetTable<T>(); } } public List<T> FetchAll() { return Query.ToList(); } public void Add(T entity) { db.GetTable<T>().InsertOnSubmit(entity); } public void Delete(T entity) { db.GetTable<T>().DeleteOnSubmit(entity); } public void Save() { db.SubmitChanges(); } #endregion } The two methods for adding and deleting UserCourses are: Service Methods for Adding and Deleting UserCourses: public void AddUserCourse(int courseId) { UserCourse uc = new UserCourse(); uc.IdCourse = courseId; uc.IdUser = UserId; uc.DateCreated = DateTime.Now; uc.DateAmended = DateTime.Now; uc.Role = "Pupil"; uc.CourseNotes = string.Empty; uc.ActiveStepIndex = 0; UserCoursesRepository.Add(uc); UserCoursesRepository.Save(); } public void DeleteUserCourse(int courseId) { var uc = (UserCoursesRepository.Query.Where(x => x.IdUser == UserId && x.IdCourse == courseId)).Single(); UserCoursesRepository.Delete(uc); UserCoursesRepository.Save(); } Ajax I am using Ajax via Ajax.BeginForm I don't think that is relevant. ASP.NET MVC 3 I am using mvc3, but don't think that is relevant: the errors are related to model code.

    Read the article

  • C# Expression Tree Simple Arithmetic

    - by Richard Adnams
    Hello, I've been trying to figure out how to achieve some simple maths using the Expression class. What I'm trying to do is this (1 + 10 * 15) When I try to do this via Expression.Add and Expression.Constant but the result I get is this ((1 + 10) * 15) Which is not right as it evaluates the 1 + 10 first instead of 10 * 15. Is there a way to combine Expression.Add/Multiply etc.. without it creating the brackets? I assume there is but I just can't find where or how! The test code I have is this var v1 = Expression.Constant(1, typeof(int)); var v2 = Expression.Constant(10, typeof(int)); var v3 = Expression.Constant(15, typeof(int)); var a1 = Expression.Add(v1, v2); var m2 = Expression.Multiply(a1, v3); Thanks for your time, Richard.

    Read the article

  • jQuery find value then replace SRC

    - by Charles Web Dev
    Hello all, Can anyone see anything that is wrong with this code it just isn't working... I am tring to: get the value of #product-variants-option-0 search #preload for the relevant image and then change div.image img src to that image jQuery(document).ready(function($) { $('#product-variants-option-0').change(function() { // What is the sku of the current variant selection. var select_value = $(this).find(':selected').val(); if (select_value == "Kelly Green") { var keyword = "kly"; }; var new_src = $('#preload img[src*=keyword]'); $('div.image img').attr('src', new_src); }); }); The selection: <select class="single-option-selector-0" id="product-variants-option-0"> <option value="Kelly Green">Kelly Green</option> <option value="Navy">Navy</option> <option value="Olive">Olive</option> <option value="Cocoa">Cocoa</option> </select> I'm trying to search an unordered list: <ul id="preload" style="display:none;"> <li><img src="0z-kelly-green-medium.jpg"/></li> <li><img src="0z-olive-medium.jpg"/></li> </ul> The image I'm trying to replace is this:

    Read the article

  • Devise within namespace

    - by Harm de Wit
    Hey, I'm trying to split my rails project in a front-end for regular users and a back-end for admins. Therefore i have created a namespace 'admin' so that i can easily control admin specific controller methods/layouts/authentication in the map admin. I'm using Devise to register/authenticate my admins only. Because it is only used for admins only i'm trying to move Devise to the admin namespace. I could not find exactly what i was looking for in the documentation of Devise but i tried something like this in routes.rb: namespace 'admin'do devise_for :admins end I also tried to make a custom Devise::Sessions controller but that too didn't seem to work out. Does anyone know how to do this? Should i just use the regular routes for devise with a custom(admin) layout?

    Read the article

  • How to add a Web Part Zone to a SharePoint wiki page?

    - by Hitesh
    Hi, I have a team site. I understand that the default home page of a team site is a wiki page. I want to add a web part zone to this page. How can I do that? By default it already has Web Part Zone -. You can use SharePoint designer to add a web part to this zone and it works fine. But you are not able to add a web part to this zone using SharePoint web UI? Ususally when you have a web part zone in a page, using SharePoint web UI, it allows to you add/remove a web part. But it is not the case with the web part zone on the default home page of a team site. Also is there any way I can add a web part zone to this page? I do know that you can easily add web parts into wiki page content. But I want to add a new web part zone where users can add/remove web parts. Thanks, Hitesh

    Read the article

  • Setting selected item on Listbox in Silverlight - Windows Phone 7

    - by Fishcake
    I have a databound Listbox bound to a generic list as follows (Provider is a very simple class that just includes a single property (Name). ProviderList = new List<Provider>(); //Populate list Providers.ItemsSource = ProviderList; I can save the selected item with no problem but I can't manage to set the selected item from code afterwards. I am trying to do so as follows: int x = Providers.Items.IndexOf((Provider)_Settings["provider"]); However IndexOf() is always returning -1. If I inspect both Providers.Items[1] and _Setting["provider"] at runtime using the immediate window they both return {StoreRetrieveData.Provider} Name: "Greenflag" Am I doing something wrong (well clearly I am)?

    Read the article

  • Setting timeout for embedded Lua

    - by skyeagle
    I have embedded Lua in a C/C+= application. I want to be able to set a timeout value to prevent getting trapped with badly written scripts that can result in infinite loops (or even string searches that take an infinite time to complete). Basically, I want to be able to set a time interval and if the script fails to complete running at the end of that time interval, I want to be able to kill the Lua script engine (gracefully, if possible). Anyone knows of best practise way to do this?

    Read the article

  • C# Array number sorting

    - by athgap
    Hi, I have an array of numbers jumbled up from 0-9. How do I sort them in ascending order? Array.Sort doesn't work for me. Is there another way to do it? Thanks in advance. EDIT: Array.Sort gives me this error. Argument 1: cannot convert from 'string' to 'System.Array' Right now it gives me this output: 0) VersionInfo.xml 2) luizafroes_singapore2951478702.xml 3) virua837890738.xml 4) darkwizar9102314425644.xml 5) snarterz_584609551.xml 6) alysiayeo594136055.xml 1) z-a-n-n2306499277.xml 7) zhangliyi_memories932668799030.xml 8) andy_tan911368887723.xml 9) config.xml k are the numbers from 0-9 string[] valnames = rk2.GetValueNames(); foreach (string k in valnames) { if (k == "MRUListEx") { continue; } Byte[] byteValue = (Byte[])rk2.GetValue(k); UnicodeEncoding unicode = new UnicodeEncoding(); string val = unicode.GetString(byteValue); Array.Sort(k); //Error here richTextBoxRecentDoc.AppendText("\n" + k + ") " + val + "\n"); }

    Read the article

  • scrollTo (jQuery) won't work in firefox

    - by William
    For some reason, firefox seems to ignore my scrollTo function even though it works in chrome and safari. Here's an example link: http://blog.rainbird.me/post/2358248459/blowholes-are-awesome Chrome and Safari will automatically scroll to the top of the image (with an offset of 20 pixels) It doesn't work in firefox. I'm baffled! code: $(document).ready(function() { $(".photoShell img").lazyload({ placeholder: "http://william.rainbird.me/boston-polaroid/white.gif", threshold: 200 }); window.viewport = { height: function() { return $(window).height(); }, width: function() { return $(window).width(); }, scrollTop: function() { return $(window).scrollTop(); }, scrollLeft: function() { return $(window).scrollLeft(); } }; $(".photoShell img").hide(); $(".photoShell .caption").hide(); $(".photoShell img").load(function() { var maxWidth = viewport.width() - 40; // Max width for the image if(maxWidth > 960){ maxWidth = 960; } var maxHeight = viewport.height() - 50; // Max height for the image var ratio = 0; // Used for aspect ratio var width = $(this).width(); // Current image width var height = $(this).height(); // Current image height // Check if the current width is larger than the max if(width > maxWidth){ ratio = maxWidth / width; // get ratio for scaling image $(this).css("width", maxWidth); // Set new width $(this).css("height", height * ratio); // Scale height based on ratio height = height * ratio; // Reset height to match scaled image width = width * ratio; // Reset width to match scaled image } // Check if current height is larger than max if(height > maxHeight){ ratio = maxHeight / height; // get ratio for scaling image $(this).css("height", maxHeight); // Set new height $(this).css("width", width * ratio); // Scale width based on ratio width = width * ratio; // Reset width to match scaled image } $(this).parents('div.photoShell').css("width", $(this).width() + 22); $(this).parents('div.photoShell').addClass('loaded'); $(this).next(".caption").show(); var scrollNum = $(this).parents('div.photoShell').offset().top; $.scrollTo(scrollNum - 20, {duration: 700, axis:"y"}); $(this).fadeIn("slow"); }).each(function() { // trigger the load event in case the image has been cached by the browser if(this.complete) $(this).trigger('load'); });

    Read the article

  • migrating innodb ib* files to different server and distribution.

    - by 3molo
    One of our customers had a break in on an old centos 4.4 machine, so I booted a debian live cd and copied the whole /var/lib/mysql. I then, on a new debian, copied the desired database and ibdata+iblogfiles, and removed the "autoextend" bits from my.cnf - restarted mysql. But I get 'Incorrect information in file'. Paths are the same as the old centos server, and permissions and ownership is correct. What am I missing?

    Read the article

  • Does Exchange support plussed users (e.g. [email protected]) or a similar mechanism?

    - by Jens Bannmann
    Sendmail supports a feature called 'plussed users'. Once enabled, emails sent to [email protected], [email protected] and [email protected] are automatically delivered just like mails to [email protected]. There is no need to register or set up these 'plus suffixes'. The user can just use them and set up client-side filtering rules on his own. Does Exchange support a similar mechanism? If so, how to enable it? Note that I don't want answers about other means of filtering, e.g. spam/junk filtering, server-side or client-side rules, email aliases/addresses that are configured explicitly and so on.

    Read the article

  • What does "Endcode #816" stand for in Canon iR-ADV C5035 printer logs?

    - by Odin Kroeger
    We are using the Canon iR-ADV C5035. Today a worker has reported that some Word documents cannot be printed via that device (others do). I could confirm that and found that the Canon iR-ADV C5035 logs showed an "Endcode" "#816" for every print job that was not printed (whereas other print jobs show an "Encode" "OK"). Unfortunately, neither the manual that came with the Canon copy machine nor the web seems to know what this "Endcode" means. Canon support has been informed, but I'm still waiting for them to call me back. Does anyone know how I could find out what this "Endcode" stands for? Or, preferably, where I can look up the meaning of such Canon "Endcodes" in the future? Thanks in advance for any hints.

    Read the article

  • BixData or Zabbix?

    - by Arafat
    Hi all, I've been using Ganglia to monitor my single Mac OSX server which runs Apache and MySQL. I'm ok with it. Now we are upgrading our servers, 6 IBM X3650 M3 and 2 Fujitsu servers. 2 IBM for Apache cluster and 4 IBM for MySQL NDB Cluster. The other two servers are for Load balancers. All servers are going to run Debian Lenny 5 on it. Now I need to decide on which monitoring tool I should go for. I found that BixData and Zabbix does an excellent job than Ganglia, in terms of sensors and reporting. Have anyone tried the above two tools? And which tool would you suggest me? For Debian. As I'm writing this, I'm installing BixData to try.... Thanks in advance.

    Read the article

  • debian lenny : problem modifying static ip

    - by supertiti
    hello all, i'm trying to change a static ip assigned to a debian VM. I modified the /etc/network/interfaces file but my debian doesn't seem to like the new settings currently the machine's ip is set to 192.168.1.136 and i want the machine's ip to be set to 192.168.1.8 here's my modified /etc/network/interfaces : auto lo iface lo inet loopback allow-hotplug eth0 auto eth0 iface eth0 inet static address 192.168.1.8 gateway 192.168.1.1 netmask 255.255.255.0

    Read the article

  • Internal Linux machine with Apache that I can access by IP address but not computer name

    - by Parris
    I have an Ubuntu machine running LAMP. While on the machine I can type localhost or the computers name to access htdocs. From another machine I can only access the machine via its IP Address. This just started happening recently when someone rearranged the network cables and removed a hub sitting between the machine and the network, which makes me think it wasn't all the stable to begin with anyways. Any suggestions on where I should start looking?

    Read the article

  • How to rename dir under Mac (10.6.4) via super user?

    - by user56990
    This is my dir list on my NFS: macbook-pro-andrey-k:Download Andrey$ ls 1289816143_PL_t1181913 1289816171_PL_t1183807 1290117075_BFD_DVD02(Drums) I can't delete "1290117075_BFD_DVD02(Drums)" using sudo rm -Rf 1290117075_BFD_DVD02(Drums) because I get error message -bash: syntax error near unexpected token `(' Hlp plz, how can I either rename the dir so that the error message would not show up or delete the dir right away omitting rename procedure? Thank you.

    Read the article

  • PDF Converter wanted: Convert 8.5*11 PDF images into 600*800px PDF images for the Nook

    - by Astro
    I have PDF files that are maritime charts, For example this one from the Delaware Bay http://ocsdata.ncd.noaa.gov/BookletChart/12304_BookletChart_HomeEd.pdf There is a lot of detailed information in the image. When I show them on a monitor the details are shown. When I put them on the Nook they are sized to fit the Nook screen (about 3*5) and all the details are lost. Since the Nook pdf reader does not have a zoom feature, the charts are unreadable. I'd like to convert them to fit on the Nook screen(600*800px). This means the images would need to be sliced into multiple images. (ie a single image (page) would get split into 5 rows and 4 columns) In a perfect world they would get converted with a slight overlap, left to right, top to bottom. I could then page through the smaller slices to find the section I need. I had used PaperCrop in the past to convert two col PDF's (highly recommended) but it can't do anything with the images. ImageMagick does a lot with combining images, but I didn't see any split options to split the image into tiles. Windows program preferred. Thanks!

    Read the article

  • Make Thundirbird use and sync with Gmail Spam facility

    - by Senthil
    I am using Thundirbird 3.1.7. I am using Gmail with it. When I mark a message as spam in Thunderbird, I want it to go to Gmail's spam folder. But it is not happening. The mail is only marked as spam and stays in Gmail's inbox. How can I setup Thunderbird so that when I mark a message as spam in thundirbird, it goes to spam folder in both Thunderbird and Gmail? FYI: I have disabled Thunderbird's own adaptive spam controls so that it doesn't interfere. I am perfectly fine with Gmail's spam facility and don't want Thunderbird to add another layer of spam filtering. Still Thunderbird doesn't send emails to Gmail's spam. Update I figured that dragging and dropping the email to the spam folder in Thunderbird does the job. But is it the same as marking the email as spam in Gmail's interface? i.e. Gmail will do stuff when you mark an email as spam so that it can filter out similar messages in the future. Does it happen when I do this drag and drop thing too? Are they the same?

    Read the article

  • How to read public key from PFX file in java

    - by articlestack
    I am able to read private key from PFX file but not public key. I am using following code to read public key. InputStream inStream = new FileInputStream(certFile); CertificateFactory cf = CertificateFactory.getInstance("X.509"); BufferedInputStream bis = new BufferedInputStream(inStream); // if (bis.available() > 0) { java.security.cert.Certificate cert = cf.generateCertificate(bis); System.out.println("This part is not getting printed in case of PFX file"); // } puk = (PublicKey) cert.getPublicKey(); This code is working properly when i read from .cer file. Please help

    Read the article

  • Using gmail as SMTP server in Java web app is slow

    - by Annie
    Hi, I was wondering if anyone might be able to explain to me why it's taking nearly 30 seconds each time my Java web app sends an email using Gmail's SMTP server? See the following timestamps: 13/04/2010-22:24:27:281 DEBUG test.service.impl.SynchronousEmailService - Before sending mail. 13/04/2010-22:24:52:625 DEBUG test.service.impl.SynchronousEmailService - After sending mail. I'm using spring's JavaMailSender class with the following settings: email.host=smtp.gmail.com [email protected] email.password=mypassword email.port=465 mail.smtp.auth.required=true Note that the mail is getting sent and I'm receiving it fine, there's just this delay which is resulting in a slow experience for the application user. If you know how I can diagnose the problem myself that would be good too :)

    Read the article

  • How much time should it take to find the sum of all prime numbers less than 2 million?

    - by Shahensha
    I was trying to solve this Project Euler Question. I implemented the sieve of euler as a helper class in java. It works pretty well for the small numbers. But when I input 2 million as the limit it doesn't return the answer. I use Netbeans IDE. I waited for a lot many hours once, but it still didn't print the answer. When I stopped running the code, it gave the following result Java Result: 2147483647 BUILD SUCCESSFUL (total time: 2,097 minutes 43 seconds) This answer is incorrect. Even after waiting for so much time, this isn't correct. While the same code returns correct answers for smaller limits. Sieve of euler has a very simple algo given at the botton of this page. My implementation is this: package support; import java.util.ArrayList; import java.util.List; /** * * @author admin */ public class SieveOfEuler { int upperLimit; List<Integer> primeNumbers; public SieveOfEuler(int upperLimit){ this.upperLimit = upperLimit; primeNumbers = new ArrayList<Integer>(); for(int i = 2 ; i <= upperLimit ; i++) primeNumbers.add(i); generatePrimes(); } private void generatePrimes(){ int currentPrimeIndex = 0; int currentPrime = 2; while(currentPrime <= Math.sqrt(upperLimit)){ ArrayList<Integer> toBeRemoved = new ArrayList<Integer>(); for(int i = currentPrimeIndex ; i < primeNumbers.size() ; i++){ int multiplier = primeNumbers.get(i); toBeRemoved.add(currentPrime * multiplier); } for(Integer i : toBeRemoved){ primeNumbers.remove(i); } currentPrimeIndex++; currentPrime = primeNumbers.get(currentPrimeIndex); } } public List getPrimes(){ return primeNumbers; } public void displayPrimes(){ for(double i : primeNumbers) System.out.println(i); } } I am perplexed! My questions is 1) Why is it taking so much time? Is there something wrong in what I am doing? Please suggest ways for improving my coding style, if you find something wrong.

    Read the article

  • How to use pipes for nonblocking IPC (UART emulation)

    - by codebauer
    I would like to write some test/emulation code that emulates a serial port connection. The real code looks like this: DUT <- UART - testtool.exe My plan is to use create a test application (CodeUnderTest.out) on linux that forks to launch testool.out with two (read & write) named pipes as arguments. But I cannot figure out how to make all the pipe IO non-blocking! The setup would look like this:. CodeUnderTest.out <- named pipes - testTool.out (lauched from CodeUnderTest.out) I have tried opening the pipes as following: open(wpipe,O_WRONLY|O_NONBLOCK); open(rpipe,O_RDONLY|O_NONBLOCK); But the write blocks until the reader opens the wpipe. Next I tried the following: open(wpipe,O_RDWR|O_NONBLOCK); open(rpipe,O_RDONLY|O_NONBLOCK); But then the reader of the first message never gets any data (doesn't block though) I also tried adding open and close calls around each message, but that didn't work either... Here is some test code: #include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <fcntl.h> pid_t pid; char* rpipe, *wpipe,*x; FILE *rh,*wh; int rfd,wfd; void openrpipe( void ) { rfd = open(rpipe,O_RDONLY|O_NONBLOCK); rh = fdopen(rfd,"rb"); printf("%sopeningr %x\n",x,rh); } void openwpipe( void ) { //Fails when reader not already opened //wfd = open(wpipe,O_WRONLY|O_NONBLOCK); wfd = open(wpipe,O_RDWR|O_NONBLOCK); wh = fdopen(wfd,"wb"); printf("%sopeningw %x\n",x,wh); } void closerpipe( void ) { int i; i = fclose(rh); printf("%sclosingr %d\n",x,i); } void closewpipe( void ) { int i; i = fclose(wh); printf("%sclosingw %d\n",x,i); } void readpipe( char* expect, int len) { char buf[1024]; int i=0; printf("%sreading\n",x); while(i==0) { //printf("."); i = fread(buf,1,len,rh); } printf("%sread (%d) %s\n",x,i,buf); } void writepipe( char* data, int len) { int i,j; printf("%swriting\n",x); i = fwrite(data,1,len,rh); j = fflush(rh); //No help! printf("%sflush %d\n",x,j); printf("%swrite (%d) %s\n",x,i,data); } int main(int argc, char **argv) { rpipe = "readfifo"; wpipe = "writefifo"; x = ""; pid = fork(); if( pid == 0) { wpipe = "readfifo"; rpipe = "writefifo"; x = " "; openrpipe(); openwpipe(); writepipe("paul",4); readpipe("was",3); writepipe("here",4); closerpipe(); closewpipe(); exit(0); } openrpipe(); openwpipe(); readpipe("paul",4); writepipe("was",3); readpipe("here",4); closerpipe(); closewpipe(); return( -1 ); } BTW: To use the testocd above you need to pipes in the cwd: mkfifo ./readfifo mkfifo ./writefifo

    Read the article

< Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >