Daily Archives

Articles indexed Saturday May 15 2010

Page 15/78 | < Previous Page | 11 12 13 14 15 16 17 18 19 20 21 22  | Next Page >

  • Passenger not working with SSL on Apache 2

    - by Zak
    I have a Rails app running on Passenger; It works as expected over unencrypted connections. I also have a working Apache SSL setup; I can access any static file available via http with https. When I try to access the Rails app via https, I get a 403 error (Directory index forbidden by rule). Turning on indexes for the directory simply causes Apache to display an index. I do have +ExecCGI set for the appropriate directory in the SSL version of the VirtualHost directive. I'm sure there's something obvious I'm overlooking. I'm just not sure where I need to be looking.

    Read the article

  • How to configure my local server to send email.

    - by George Edison
    The title is a bit misleading... what I want to do is a little complicated: I want to set up my server (running Ubuntu 10.04 Desktop) to send email using PHP's mail() function. I tried just using it, but the messages don't go anywhere and the return value of mail() is not FALSE, so I really don't know what's going on. Any advice/ideas for configuring this?

    Read the article

  • Problem opening password encrypted .docx file on Word 2003

    - by molecule
    Hi all, I am having a problem opening a .docx file on my Word 2003. I have installed the Compatibility pack for 2007 but when i try to open this particular file, I receive the error "Word experienced an error trying to open the file. Try these suggestions. 1. Check the file permissions for the document, 2. Make sure there is sufficient free memory and disk space, 3. Open the file with the Text Recovery converter. I do not think it is any of the errors as I am able to open it on a different PC with Word 2003 as well. I also do not have any issues opening any non-password encrypted .docx files. Has anyone experienced the same issue? Most posts on the internet relate to "open and repair" but as mentioned, I am able to open this file on another PC without any problems. Any advice is greatly appreciated. Thanks, George

    Read the article

  • Preserving Bitmap values when creating a new Bitmap from System.Drawing.Image

    - by Otaku
    I'm trying to create a resized image from a bitmap, set a new height/width and a new resolution and save it to PNG. I can do this either from directly A) Image.FromFile(filename) or B) New Bitmap(imageSource) to create the the A Bitmap to be passed to B. Both work okay schmokay, but A does not allow me to set a new width/height on creation (but it does allow me to preserve values with useIcm=True) and B does not allow me to preseve values. Okay, now on to some code and examples: Dim sourceBitmap As New Bitmap(imagePath & myImage1Name) <-not good at all (#1 overload). Doesn't preserve things like HorizontalResolution or PixelFormat on .Save Dim sourceBitmap2 As Bitmap = Image.FromFile(imagePath & myImage1Name, True) <-not good (#5 overload). it does preserve things like HorizontalResolution or PixelFormat on .Save, but it doesn't allow me to initialize image at a new size. Dim targetBitmap As New Bitmap(sourceBitmap2, newWidth, newHeight) <-not good. Even though sourceBitmap2 (see #2 above) was initialized with useIcm=True, it doesn't matter once I've passed it in as the source in targetBitmap. Basically, I'm looking for a way to contruct a New Bitmap with both something like useIcm=True and set the width/height at the same time (Width/Height are read-only properties once it's created). I've gone down the Graphics.DrawImage route as well and it's the same - Graphics.FromImage(sourceBitmap) does not preserve values. Why do I need these values to be preserved? Because I need to convert these pictures to PNG (for file size) with a new resolution and keep the same physical dimensions (w/h in inches) for printing. I know the new pixel width/height needed based on the resolution values I'll pass in with .SetResolution(xDpi,yDpi) to preserve physical dimensions, so that's not the problem. The issue is things like the PixelFormatSize need to remain unchanged (yes, I've tried EncoderParameters - they don't work. I can give you the gory details if you like, but suffice it to say for now, they just don't work). Whew, got that off my chest! Okay, anyone who really knows how all this works can help?

    Read the article

  • C# 4: Real-World Example of Dynamic Types

    - by routeNpingme
    I think I have my brain halfway wrapped around the Dynamic Types concept in C# 4, but can't for the life of me figure out a scenario where I'd actually want to use it. I'm sure there are many, but I'm just having trouble making the connection as to how I could engineer a solution that is better solved with dynamics as opposed to interfaces, dependency injection, etc. So, what's a real-world application scenario where dynamic type usage is appropriate?

    Read the article

  • Winforms: How to speed up Invalidate()?

    - by Pedery
    I'm developing a retained mode drawing application in GDI+. The application can draw simple shapes to a canvas and perform basic editing. The math that does this is optimized to the last byte and is not an issue. I'm drawing on a panel that is using the built-in Controlstyles.DoubleBuffer. Now, my problem arises if I run my app maximized on a big monitor (HD in my case). If I try to draw a line from one corner of the (big) canvas to the diagonally oposite other, it will start to lag and the CPU goes high up. Each graphical object in my app has a boundingbox. Thus, when I invalidate the boundingbox of a line that goes from one corner of the maximized app to the oposite diagonal one, that boundingbox is virtually as big as the canvas. When a user is drawing a line, this invalidation of the boundingbox thus happens on the mousemove event, and there is a clear lag visible. This lag also exists if the line is the only object on the canvas. I've tried to optimize this in many ways. If I draw a shorter line, the CPU and the lag goes down. If I remove the Invalidate() and keep all other code, the app is quick. If I use a Region (that only spans the figure) to invalidate instead of the boundingbox, it is just as slow. If I split the boundingbox into a range of smaller boxes that lie back to back, thus reducing the invalidation area, no visible performance gain can be seen. Thus I'm at a loss here. How can I speed up the invalidation? On a side note, both Paint.Net and Mspaint suffers from the same shortcommings. Word and PowerPoint however, seem to be able to paint a line as described above with no lag and no CPU load at all. Thus it's possible to achieve the desired results, the question is how?

    Read the article

  • Perl coding to PHP coding conversion

    - by Haskella
    Hi, I am trying to convert some Perl into PHP using this guideline: http://www.cs.wcupa.edu/~rkline/perl2php/#basedir Basically I know next to nothing about these two languages. Please give me some simple English explanation of what each line does, I'll be more than happy. Thanks for reading :D Perl CGI program: #!/usr/bin/perl -T use strict; use warnings; use CGI (); my %fruit_codes = ( apple => '2321.html', banana => '1234.html', coconut => '8889.html', ); my $c = CGI->new; my $fruit_parameter = $c->param('fruit_name'); my $iframe_document; if (defined $fruit_parameter and exists $fruit_codes{$fruit_parameter}) { $iframe_document = $fruit_codes{$fruit_parameter}; } else { $iframe_document = 'sorry-no-such-fruit.html'; } $c->header('application/xhtml+xml'); print <<"END_OF_HTML"; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Fruits</title> </head> <body> <form action="fruits.cgi"> <fieldset> <label for="fruit">Name of the fruit:</label> <input id="fruit" name="fruit_name" type="text" /> <input type="submit" /> </fieldset> </form> <iframe src="$iframe_document"> <a href="$iframe_document">resulting fruit</a> </iframe> </body> </html> END_OF_HTML 1;

    Read the article

  • Error while excuting a simple boost thread program

    - by Eternal Learner
    Hi All, Could you tell mw what is the problem with the below boost::thread program #include<iostream> #include<boost/thread/thread.hpp> boost::mutex mutex; class A { public: A() : a(0) {} void operator()() { boost::mutex::scoped_lock lock(mutex); } private: int a; }; int main() { boost::thread thr1(A()); boost::thread thr2(A()); thr1.join(); thr2.join(); } I get the error message: error: request for member 'join' in 'thr1', which is of non-class type 'boost::thread()(A ()())' BoostThread2.cpp:30: error: request for member 'join' in 'thr2', which is of non-class type 'boost::thread ()(A ()())'

    Read the article

  • attempt to write a readonly database in Android2.1

    - by JoJo
    This is the error: android.database.sqlite.SQLiteException: attempt to write a readonly database This is my code: SQLiteDatabase db = mDatabase.getWritableDatabase(); db.beginTransaction(); try { // add new records ContentValues newRecord = new ContentValues(); newRecord.put(Emergencydetails.EMERGENCYNUMBER, emergencyNumber.getText().toString()); db.insert(Emergencydetails.EMERGENCY_TABLE_NAME, null, newRecord); db.setTransactionSuccessful(); } finally { db.endTransaction(); }

    Read the article

  • Where do I control the behavior of the "X" close button in the upper right of a winform?

    - by John at CashCommons
    I'm venturing into making my VB.NET application a little better to use by making some of the forms modeless. I think I've figured out how to use dlg.Show() and dlg.Hide() instead of calling dlg.ShowDialog(). I have an instance of my modeless dialog in my main application form: Public theModelessDialog As New dlgModeless To fire up the modeless dialog I call theModelessDialog.Show() and within the OK and Cancel button handlers in dlgModeless I have Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click Me.DialogResult = System.Windows.Forms.DialogResult.OK Me.Hide() End Sub Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click Me.DialogResult = System.Windows.Forms.DialogResult.Cancel Me.Hide() End Sub and that seems to work fine. The "X" button in the upper right is getting me, though. When I close the form with that button, then try to reopen the form, I get ObjectDisposedException was unhandled. Cannot access a disposed object. I feel like I'm most of the way there but I can't figure out how to do either of the following: Hide that "X" button Catch the event so I don't dispose of the object (just treat it like I hit Cancel) Any ideas? The class of this dialog is System.Windows.Forms.Form. Thanks as always!

    Read the article

  • How do I get entity for primary key using EntityDataSource in ASP.NET

    - by drasto
    I have a GridView in my ASP.NET application that takes data to be rendered from EntityDataSource. GridView allows user to select rows. I want to get the entity that corresponds to the row user selected. I can get from GridView the ID(primary key) of the entity that corresponds to the row selected. How can I get the Entity that has that ID(primary key) ?

    Read the article

  • How do I make PHP's Magic __set work like a natural variable?

    - by Navarr
    Basically, what I want to do is create a class called Variables that uses sessions to store everything in it, allowing me to quickly get and store data that needs to be used throughout the entire site without working directly with sessions. Right now, my code looks like this: <?php class Variables { public function __construct() { if(session_id() === "") { session_start(); } } public function __set($name,$value) { $_SESSION["Variables"][$name] = $value; } public function __get($name) { return $_SESSION["Variables"][$name]; } public function __isset($name) { return isset($_SESSION["Variables"][$name]); } } However, when I try to use it like a natural variable, for example... $tpl = new Variables; $tpl->test[2] = Moo; echo($tpl->test[2]); I end up getting "o" instead of "Moo" as it sets test to be "Moo," completely ignoring the array. I know I can work around it by doing $tpl->test = array("Test","Test","Moo"); echo($tpl->test[2]); but I would like to be able to use it as if it was a natural variable. Is this possible?

    Read the article

  • CakePHP hasAndBelongsToMany (HABTM) Delete Joining Record

    - by Jason McCreary
    I have a HABTM relationship between Users and Locations. Both Models have the appropriate $hasAndBelongsToMany variable set. When I managing User Locations, I want to delete the association between the User and Location, but not the Location. Clearly this Location could belong to other users. I would expect the following code to delete just the join table record provided the HABTM associations, but it deleted both records. $this->Weather->deleteAll(array('Weather.id' => $this->data['weather_ids'], false); However, I am new to CakePHP, so I am sure I am missing something. I have tried setting cascade to false and changing the Model order with User, User-Weather, Weather-User. No luck. Thanks in advance for any help.

    Read the article

  • In scala can I pass repeated parameters to other methods?

    - by Fred Haslam
    Here is something I can do in java, take the results of a repeated parameter and pass it to another method: public void foo(String ... args){bar(args);} public void bar(String ... args){System.out.println("count="+args.length);} In scala it would look like this: def foo(args:String*) = bar(args) def bar(args:String*) = println("count="+args.length) But this won't compile, the bar signature expects a series of individual strings, and the args passed in is some non-string structure. For now I'm just passing around arrays. It would be very nice to use starred parameters. Is there some way to do it?

    Read the article

  • A null value should be considered as 0 when addition of it is done with decimal value.

    - by Harikrishna
    There are three column in the datatable A,B and C. Now each column is type of decimal. Now I am doing like dt.Columns["A"].Expression="B+C"; to make addition of Column B's record and column C's record. Now if there is any value of B or C is null then addition of B and C will be null like B's value is 3 and C's value is null for first row then B+C(3+null) will be null which is not appropriate, the result of addition should be 3.If I replace 0 instead of null then it will be ok.But whereever there is null value in the records it should be remain it is and it should not be replaced by 0.That is null value should not be replaced by 0 and when addition of null value is done with any decimal value null value should be considered as 0. Is it possible,how can we do this ?

    Read the article

  • gif file outside the Cycle plugin control is not working

    - by Geetha
    Hi All, I am creating application using jquery in asp.net. I am displaying images(664 x 428) with fade effect using cycle plugin and also a gif file outside the control. Problem: The gif file animation is working only if i pause the cycle fade effect the gif file animation is working. Coding: $('#mainBanner').cycle({ fx: 'fade', continuous: true, speed: 7500, timeout: 55000, pause: 1, sync: 1 }); <img src="Images/HomePageImages/scan.gif" alt="" width="124" border="0" height="124" />

    Read the article

  • Sorting in Hash Maps in Java

    - by Crystal
    I'm trying to get familiar with Collections. I have a String which is my key, email address, and a Person object (firstName, lastName, telephone, email). I read in the Java collections chapter on Sun's webpages that if you had a HashMap and wanted it sorted, you could use a TreeMap. How does this sort work? Is it based on the compareTo() method you have in your Person class? I overrode the compareTo() method in my Person class to sort by lastName. But it isn't working properly and was wondering if I have the right idea or not. getSortedListByLastName at the bottom of this code is where I try to convert to a TreeMap. Also, if this is the correct way to do it, or one of the correct ways to do it, how do I then sort by firstName since my compareTo() is comparing by lastName. import java.util.*; public class OrganizeThis { /** Add a person to the organizer @param p A person object */ public void add(Person p) { staff.put(p.getEmail(), p); //System.out.println("Person " + p + "added"); } /** * Remove a Person from the organizer. * * @param email The email of the person to be removed. */ public void remove(String email) { staff.remove(email); } /** * Remove all contacts from the organizer. * */ public void empty() { staff.clear(); } /** * Find the person stored in the organizer with the email address. * Note, each person will have a unique email address. * * @param email The person email address you are looking for. * */ public Person findByEmail(String email) { Person aPerson = staff.get(email); return aPerson; } /** * Find all persons stored in the organizer with the same last name. * Note, there can be multiple persons with the same last name. * * @param lastName The last name of the persons your are looking for. * */ public Person[] find(String lastName) { ArrayList<Person> names = new ArrayList<Person>(); for (Person s : staff.values()) { if (s.getLastName() == lastName) { names.add(s); } } // Convert ArrayList back to Array Person nameArray[] = new Person[names.size()]; names.toArray(nameArray); return nameArray; } /** * Return all the contact from the orgnizer in * an array sorted by last name. * * @return An array of Person objects. * */ public Person[] getSortedListByLastName() { Map<String, Person> sorted = new TreeMap<String, Person>(staff); ArrayList<Person> sortedArrayList = new ArrayList<Person>(); for (Person s: sorted.values()) { sortedArrayList.add(s); } Person sortedArray[] = new Person[sortedArrayList.size()]; sortedArrayList.toArray(sortedArray); return sortedArray; } private Map<String, Person> staff = new HashMap<String, Person>(); public static void main(String[] args) { OrganizeThis testObj = new OrganizeThis(); Person person1 = new Person("J", "W", "111-222-3333", "[email protected]"); Person person2 = new Person("K", "W", "345-678-9999", "[email protected]"); Person person3 = new Person("Phoebe", "Wang", "322-111-3333", "[email protected]"); Person person4 = new Person("Nermal", "Johnson", "322-342-5555", "[email protected]"); Person person5 = new Person("Apple", "Banana", "123-456-1111", "[email protected]"); testObj.add(person1); testObj.add(person2); testObj.add(person3); testObj.add(person4); testObj.add(person5); System.out.println(testObj.findByEmail("[email protected]")); System.out.println("------------" + '\n'); Person a[] = testObj.find("W"); for (Person p : a) System.out.println(p); System.out.println("------------" + '\n'); a = testObj.find("W"); for (Person p : a) System.out.println(p); System.out.println("SORTED" + '\n'); a = testObj.getSortedListByLastName(); for (Person b : a) { System.out.println(b); } } } Person class: public class Person implements Comparable { String firstName; String lastName; String telephone; String email; public Person() { firstName = ""; lastName = ""; telephone = ""; email = ""; } public Person(String firstName) { this.firstName = firstName; } public Person(String firstName, String lastName, String telephone, String email) { this.firstName = firstName; this.lastName = lastName; this.telephone = telephone; this.email = email; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getTelephone() { return telephone; } public void setTelephone(String telephone) { this.telephone = telephone; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public int compareTo(Object o) { String s1 = this.lastName + this.firstName; String s2 = ((Person) o).lastName + ((Person) o).firstName; return s1.compareTo(s2); } public boolean equals(Object otherObject) { // a quick test to see if the objects are identical if (this == otherObject) { return true; } // must return false if the explicit parameter is null if (otherObject == null) { return false; } if (!(otherObject instanceof Person)) { return false; } Person other = (Person) otherObject; return firstName.equals(other.firstName) && lastName.equals(other.lastName) && telephone.equals(other.telephone) && email.equals(other.email); } public int hashCode() { return this.email.toLowerCase().hashCode(); } public String toString() { return getClass().getName() + "[firstName = " + firstName + '\n' + "lastName = " + lastName + '\n' + "telephone = " + telephone + '\n' + "email = " + email + "]"; } }

    Read the article

  • Does this have anything to do with endian-ness?

    - by eSKay
    This piece of code: #include<stdio.h> void hello() { printf("hello\n"); } void bye() { printf("bye\n"); } int main() { printf("%p\n", hello); printf("%p\n", bye); return 0; } output on my machine: 0x80483f4 0x8048408 [second address is bigger in value] on Codepad 0x8048541 0x8048511 [second address is smaller in value] Does this have anything to do with endian-ness of the machines? If not, Why the difference in the ordering of the addresses? Also, Why the difference in the difference? 0x8048541 - 0x8048511 = 0x30 0x8048408 - 0x80483f4 = 0x14 Btw, I just checked. This code (taken from here) says that both the machines are Little-Endian #include<stdio.h> int main() { int num = 1; if(*(char *)&num == 1) printf("Little-Endian\n"); else printf("Big-Endian\n"); return 0; }

    Read the article

  • Help With Lisp Code for a Binary Tree

    - by iulia
    I have (setq l2 '(1 (2 b (c 1 b))(a (1 2) d))) ( defun drumuri (l3) ( cond ( (atom l3) ( cons l3 nil)) ( t ( append ( cons ( car l3 ) nil) ( drumuri ( cadr l3)) (cons (car l3)nil) ( drumuri ( caddr l3)) )))) ( drumuri l2) and it gives me: Break 2 [4]> DRUMURI Break 2 [4]> (1 2 B 2 C 1 C B 1 A 1 2 1 NIL A D) but i need: ((1 2 B)(1 2 C 1)(1 2 C B)(1 A 1 2)(1 A D))

    Read the article

  • emacs: force ido-mode to forget history...

    - by Stephen
    Hi, I wonder if I can keep ido from not remembering my history and only show completions for files that are in the current directory when I am searching for a file. I understand that this history feature is useful at times, but I often end up editing the incorrect file because I think I am editing file called 'abc.txt' in the current directory but in fact I am editing the file by the same name in another one that I previously visited (often happens when there is not an 'abc.txt' in the current directory, as I mistakenly assume). From reading the ido.el file I thought to set in my .emacs file (also evaluated these expressions in running emacs instance): (custom-set-variables '(ido-enable-last-directory-history nil) '(ido-record-commands nil) ) and deleted a file called .ido.last in ~/, but still it remembers some previous files I've visited before making these changes. How can I purge my previous history, and I am not entirely sure what the difference between the two variables above are but seems to have done the trick to keep ido from remembering files I visit in the future? Thanks for your help!

    Read the article

  • help with sql query - in access 2007

    - by Gold
    hi i have 2 tables table items has 144602 records table A has 27721 records code in items = BAR8 in A i want to show all records that equal i try this: SELECT Items.Code, A.BAR8 FROM Items INNER JOIN A ON Items.Code = A.BAR8; and i get 28048 records !!! i need to get 27721 , how to do it ? thank's in advance

    Read the article

  • NSUserDefaults loses 3 rows each time it's called

    - by Jeff Decker
    Hello Everyone! Brand new programmer here, so off-topic help/constructive criticism welcome. I am saving a default state (such as "New York") in a UIPickerView which is in a FlipSideView. It certainly saves for the first and second time I check to make sure it's the same state (I am clicking "done" and then "info" repeatedly), but on the third check the picker has moved up three states (to "New Hampshire") and then every time I check the picker progresses three more states. Here's the .h and .m files of the FlipSideViewController: #import <UIKit/UIKit.h> import "Calculator.h" @protocol FlipsideViewControllerDelegate; @interface FlipsideViewController : UIViewController { id delegate; UIPickerView *myPickerView; NSArray *pickerViewArray; } @property (nonatomic, assign) id delegate; @property (nonatomic, retain) UIPickerView *myPickerView; @property (nonatomic, retain) NSArray *pickerViewArray; (IBAction)done; @end @protocol FlipsideViewControllerDelegate - (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller; @end import "FlipsideViewController.h" @implementation FlipsideViewController @synthesize delegate; @synthesize myPickerView, pickerViewArray; -(CGRect)pickerFrameWithSize:(CGSize)size;{ CGRect screenRect = [[UIScreen mainScreen] applicationFrame]; CGRect pickerRect = CGRectMake( 0.0, screenRect.size.height - size.height, size.width, size.height); return pickerRect; } (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor]; [self createPicker]; } -(void)viewWillAppear:(BOOL)animated;{ [super viewWillAppear:NO]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [myPickerView selectRow:[defaults integerForKey:@"pickerRow"] inComponent:0 animated:NO]; } -(void)createPicker;{ pickerViewArray = [[NSArray arrayWithObjects: @"Alabama",@"Alaska", @"Arizona",@"Arkansas",@"California",@"Colorado",@"Connecticut",@"Delaware", @"District of Columbia",@"Florida",@"Georgia",@"Hawaii",@"Idaho",@"Illinois",@"Indiana",@"Iowa", @"Kansas",@"Kentucky",@"Louisiana",@"Maine",@"Maryland",@"Massachusetts",@"Michigan", @"Minnesota",@"Mississippi",@"Missouri",@"Montana",@"Nebraska",@"Nevada",@"New Hampshire",@"New Jersey", @"New Mexico",@"New York",@"North Carolina",@"North Dakota",@"Ohio",@"Oklahoma", @"Oregon",@"Pennsylvania",@"Rhode Island",@"South Carolina",@"South Dakota",@"Tennessee", @"Texas",@"Utah",@"Vermont",@"Virginia",@"Washington",@"West Virginia",@"Wisconsin",@"Wyoming", nil] retain]; myPickerView = [[UIPickerView alloc] initWithFrame:CGRectZero]; CGSize pickerSize = [myPickerView sizeThatFits:CGSizeZero]; myPickerView.frame = [self pickerFrameWithSize:pickerSize]; myPickerView.autoresizingMask = UIViewAutoresizingFlexibleWidth; myPickerView.showsSelectionIndicator = YES; myPickerView.delegate = self; myPickerView.dataSource = self; [self.view addSubview:myPickerView]; } (IBAction)done { [self.delegate flipsideViewControllerDidFinish:self]; } pragma mark - pragma mark UIPickerViewDataSource (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setInteger:row forKey:@"pickerRow"]; [defaults setObject:[pickerViewArray objectAtIndex:row] forKey:@"pickerString"]; return [pickerViewArray objectAtIndex:row]; } (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setInteger:row forKey:@"pickerRow"]; [defaults setObject:[pickerViewArray objectAtIndex:row] forKey:@"pickerString"]; } (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component { return 240.0; } (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component { return 40.0; } (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { return [pickerViewArray count]; } (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 1; } call me mystified! Thanks for any help. Please let me know if I can make myself more clear...

    Read the article

  • Connect Rails model to non-rails database

    - by the_snitch
    I'm creating a new web application (Rails 3 beta), of which pieces of it will access data from a legacy mysql database that a current php application is using. I do not wish to modify the legacy db schema, I just want to be able to read/write to it, as well as the rails application having it's own database using activerecord for the newer stuff. I'm using mysql for the rails app, so I have the adapter installed. How is the best way to do this? For example, I want contacts to come from the old database. Should I create a contacts controller, and manually call sql to get the variables for the views? Or should I create a Contact model, and define attributes that match the fields in the database, and am I able to use it like Contact.mail_address to have it call "SELECT mailaddr FROM contacts WHERE id=Contact.id". Sorry, I've never done much in Rails outside of the standard stuff that is documented well. I'm not sure of what the best approach would be. Ideally, I want the contacts to be presented to my rails application as native as possible, so that I can expose them RESTfully for API access. Any suggestions and code examples would be much appreciated

    Read the article

  • Why doesn't my implementation of ElGamal work for long text strings?

    - by angstrom91
    I'm playing with the El Gamal cryptosystem, and my goal is to be able to encipher and decipher long sequences of text. I have come up with a method that works for short sequences, but does not work for long sequences, and I cannot figure out why. El Gamal requires the plaintext to be an integer. I have turned my string into a byte[] using the .getBytes() method for Strings, and then created a BigInteger out of the byte[]. After encryption/decryption, I turn the BigInteger into a byte[] using the .toByteArray() method for BigIntegers, and then create a new String object from the byte[]. This works perfectly when i call ElGamalEncipher with strings up to 129 characters. With 130 or more characters, the output produced from ElGamalDecipher is garbled. Can someone suggest how to solve this issue? Is this an issue with my method of turning the string into a BigInteger? If so, is there a better way to turn my string of text into a BigInteger and back? Below is my encipher/decipher code with a program to demonstrate the problem. import java.math.BigInteger; public class Main { static BigInteger P = new BigInteger("15893293927989454301918026303382412" + "2586402937727056707057089173871237566896685250125642378268385842" + "6917261652781627945428519810052550093673226849059197769795219973" + "9423619267147615314847625134014485225178547696778149706043781174" + "2873134844164791938367765407368476144402513720666965545242487520" + "288928241768306844169"); static BigInteger G = new BigInteger("33234037774370419907086775226926852" + "1714093595439329931523707339920987838600777935381196897157489391" + "8360683761941170467795379762509619438720072694104701372808513985" + "2267495266642743136795903226571831274837537691982486936010899433" + "1742996138863988537349011363534657200181054004755211807985189183" + "22832092343085067869"); static BigInteger R = new BigInteger("72294619754760174015019300613282868" + "7219874058383991405961870844510501809885568825032608592198728334" + "7842806755320938980653857292210955880919036195738252708294945320" + "3969657021169134916999794791553544054426668823852291733234236693" + "4178738081619274342922698767296233937873073756955509269717272907" + "8566607940937442517"); static BigInteger A = new BigInteger("32189274574111378750865973746687106" + "3695160924347574569923113893643975328118502246784387874381928804" + "6865920942258286938666201264395694101012858796521485171319748255" + "4630425677084511454641229993833255506759834486100188932905136959" + "7287419551379203001848457730376230681693887924162381650252270090" + "28296990388507680954"); public static void main(String[] args) { FewChars(); System.out.println(); ManyChars(); } public static void FewChars() { //ElGamalEncipher(String plaintext, BigInteger p, BigInteger g, BigInteger r) BigInteger[] cipherText = ElGamal.ElGamalEncipher("This is a string " + "of 129 characters which works just fine . This is a string " + "of 129 characters which works just fine . This is a s", P, G, R); System.out.println("This is a string of 129 characters which works " + "just fine . This is a string of 129 characters which works " + "just fine . This is a s"); //ElGamalDecipher(BigInteger c, BigInteger d, BigInteger a, BigInteger p) System.out.println("The decrypted text is: " + ElGamal.ElGamalDecipher(cipherText[0], cipherText[1], A, P)); } public static void ManyChars() { //ElGamalEncipher(String plaintext, BigInteger p, BigInteger g, BigInteger r) BigInteger[] cipherText = ElGamal.ElGamalEncipher("This is a string " + "of 130 characters which doesn’t work! This is a string of " + "130 characters which doesn’t work! This is a string of ", P, G, R); System.out.println("This is a string of 130 characters which doesn’t " + "work! This is a string of 130 characters which doesn’t work!" + " This is a string of "); //ElGamalDecipher(BigInteger c, BigInteger d, BigInteger a, BigInteger p) System.out.println("The decrypted text is: " + ElGamal.ElGamalDecipher(cipherText[0], cipherText[1], A, P)); } } import java.math.BigInteger; import java.security.SecureRandom; public class ElGamal { public static BigInteger[] ElGamalEncipher(String plaintext, BigInteger p, BigInteger g, BigInteger r) { // returns a BigInteger[] cipherText // cipherText[0] is c // cipherText[1] is d SecureRandom sr = new SecureRandom(); BigInteger[] cipherText = new BigInteger[2]; BigInteger pText = new BigInteger(plaintext.getBytes()); // 1: select a random integer k such that 1 <= k <= p-2 BigInteger k = new BigInteger(p.bitLength() - 2, sr); // 2: Compute c = g^k(mod p) BigInteger c = g.modPow(k, p); // 3: Compute d= P*r^k = P(g^a)^k(mod p) BigInteger d = pText.multiply(r.modPow(k, p)).mod(p); // C =(c,d) is the ciphertext cipherText[0] = c; cipherText[1] = d; return cipherText; } public static String ElGamalDecipher(BigInteger c, BigInteger d, BigInteger a, BigInteger p) { //returns the plaintext enciphered as (c,d) // 1: use the private key a to compute the least non-negative residue // of an inverse of (c^a)' (mod p) BigInteger z = c.modPow(a, p).modInverse(p); BigInteger P = z.multiply(d).mod(p); byte[] plainTextArray = P.toByteArray(); return new String(plainTextArray); } }

    Read the article

< Previous Page | 11 12 13 14 15 16 17 18 19 20 21 22  | Next Page >