Aug 01

HOWTO: Using Paypal buttons with ASP.net the easy way

A couple of years ago I wanted to add a donation button to an ASP.net website. Specifically I wanted a Paypal based donation button. It should have been really easy. Paypal will let you make buttons on their site and they’ll generate the code for you to put onto your own web page. But unfortunately… it’s just not really that easy.  I recently needed to do this again (just today actually) and couldn’t bring myself to use one of the old hacks I had done, and I finally found a super easy solution. I don’t understand why it was so hard to find this information, but I decided to write it up for all to see and use.

The problem is that the code that PayPal generate is html form code. The “action” of the form is a page on their website. The reason that this is a problem is because most people use masterpages within their ASP.net webpages and those masterpages typically have form tags already in them. Since webpages are only supposed to have one “form” per page then adding the PayPal generated form in the content area of a page that is wrapped within a form on the masterpage is just not going to work. What happens is that when the user clicks on the PayPal submit button it just posts back to local website instead of posting to PayPal. Very annoying.

I read about 20 web pages / tutorials today about how one can use PayPal generated buttons within an ASP.net, and I was about to finally give up and do it the old way when it occurred to me that maybe I could control the current page’s masterpage’s form’s action programatically. (By the way that was the most possessives in a row ever!)

So here’s the deal, and it is so easy. Let’s say that the PayPal code generated for you looks like:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
 <input type="hidden" name="cmd" value="_s-xclick">
 <input type="hidden" name="hosted_button_id" value="blablablabla">
 <table>
 <tr><td><input type="hidden" name="on0" value="Subscription Level">Subscription Level</td></tr><tr><td><select name="os0">
 <option value="Pro">Pro $5.00 USD</option>
 <option value="Allstar">Allstar $15.00 USD</option>
 <option value="Superstar">Superstar $25.00 USD</option>
 </select> </td></tr>
 </table>
 <input type="hidden" name="currency_code" value="USD">
 <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
 <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
 </form>

Go ahead and paste the generated code into your page wherever it is you want it to go. You don’t have to jump through any hoops here. Now go to your codebehind and add a couple of lines to the “PageLoad” method for the page in question. Here’s a super simple PageLoad with the two new lines:

protected void Page_Load(object sender, EventArgs e)
 {
 if (!IsPostBack) 
 {  } 
 else  {  } 
 Form.Action = "https://www.paypal.com/cgi-bin/webscr";  
Form.Method = "post"; 
}

That’s it! What we did was we just programmatically set our Masterpage’s form’s action and method to whatever the PayPal form’s action / method was. So, now, when you click on the PayPal button your MasterPage form will still be the one that handles it, but it will handle it the exact same way that the PayPal form would have. Enjoy!

Please let me know how it works for you!

Jul 09

Things to consider when writing (and immediately after writing) an ebook

What are the things to consider when writing (and immediately after writing) an ebook?

Well, you’ve got to price it. How do you determine a correct price though?

You’ve got to proof read. Actually you need someone else to do it! Who can do this for you?

You’ve got to market it. How do you get the conversions up?

You’ve got to make sure that when people want to buy it that your sales system works. What are some good systems for doing this?

All of these items are atleast somewhat discussed in the article linked here. They also have a “most read articles” section that looks like those alone might be worth the read. Enjoy.

http://theadventurouswriter.com/blogwriting/after-writing-ebook-pricing-marketing-landing-pages/

Please share your ideas about any of these topics. I’m very interested to hear from those who have published successfully.

Jul 09

Ebook formatting suggestions from other site

When creating an ebook there are all kinds of questions to ask about how it should be formatted, what sections there ought to be, and more. I’m working on my first ebook which I’ve almost finished writing and I’m starting to wonder how it’s going to “look” when the time comes. I was originally just wondering if ebooks should be double spaced so I took to Google and asked “Should ebooks be double spaced?”. Genius, I know. The first link I got back was very informative and answered a whole lot more questions than just that so I figured I’d post the link so I can get to it later. So here’s the link and a few useful tidbits I got from it. Please please please visit the original page as it is more complete! These are just my notes in case the page ever disappears from the web:

http://workingwritersandbloggers.com/2010/10/07/how-to-format-a-manuscript-for-an-ebook/

In Word, format the paper using the following settings:

  • Page orientation should always be portrait. Go to Page Layout, Orientation, and choose Portrait.
  • Use double spacing. Go to Page Layout, Paragraph, and choose “double” for line spacing.
  • Use one-inch margins all the way around the manuscript. Go to Page Layout, Margins, and choose the “Normal” setting, which assigns one inch evenly around the page. Or, go to Page Layout, Margins, Custom Margins, and choose one inch for the Top, Bottom, Left, and Right settings. Leave the Gutter Setting at zero and Gutter Position at left.
  • Use Times New Roman font, 12.
  • Use a 0.5 space indent for paragraph formatting. When you arrive at a new paragraph, hit “tab” and the cursor will indent to the 0.5 mark. Use this instead of an extra line to indicate a new paragraph.

Cover

If you choose to use a graphic cover for your ebook, it will go on the very first page. This is a personal preference, however, as some authors choose to start their ebook with a typewritten title page instead. The cover image of the ebook might then be used as a graphical selling point on a website, and not used in the ebook itself.

If you are using a cover image, save the file to fit an 8.5 x 11 inch size. Any size inside of this dimension will work. Make sure the cover image is saved to 100 dpi or less to ensure that it does not increase the file size of your ebook. Save the cover image as a JPG or TIFF file.

Header

Place a header at the top of each page of your manuscript except the first (title) page. Your book title, name, and page number should be at the top. Create a separate header for even and odd pages.

Format the even pages first. Go to Insert, then Header. Scroll down through the options until you see Contrast (Even Page). Select it.

This header style is built in with page numbers/text already formatted. Enter your first and last name (or pen name) in the text section. Hit the Escape button to return to your document.

Now, choose the header for the odd pages. Go to Insert, then Header, and scroll down to Contrast (Odd Page). Click on it.

As with the even header box, you’ll see that Word has already formatted the page numbers here. Go to the top text section where it says “Type the company name” and highlight it. Type in the title of your book or manuscript.

Where it says “Type the document title” (below where you now have your book title) you can type your subtitle, or highlight the area and hit “cut” to remove. Please note: if you highlight it and just hit delete, the text “Type the document title” will remain once you return to your document. When you are finished with your header, hit Escape (“Esc”) and you are back into your document.

Notice to the Reader

The next page should be a “notice to the reader.” This page tells the reader they are allowed to download your ebook file but not sell it or pass it along to anyone else. The Notice to the Reader page will have your title once again, this time typed in about 14 point font. The copyright information, which is “Copyright © by AUTHOR NAME” should be typed in 10 point font.

On the next line, type your title in all caps in about 10 point font.

The next lines contain your publishing company information. Type the name of your publishing company and website address. If you have a post office box number for your company, this information can also be included. If the address for your publishing company is your home address, then leave that information off.

Following the publishing company name and address, list the cover art information. This should say “Cover art by NAME.” Fill in the person’s name who created the cover art. If that person is you, use your name. If you do not have a cover image for your ebook, you can skip this.

Next should be the following paragraph:

By purchasing this ebook you are stating that you are fully aware that you will be sent the ebook or download link via email and that this purchase is NOT refundable. Legally, you can save one copy of the purchased ebook to disk for your own personal use. However, it is illegal to distribute your copy to those who did not pay for it. You may not distribute the ebook to other individuals by using email, floppy discs, zip files, burning them to CD/DVD, selling them on any type of auction website, making them available for free public viewing or download on any website, offering them to the general public offline in any way, or any other method currently known or yet to be invented. You may not print copies of your downloaded book and distribute those copies to other persons. Doing any of these things is a violation of international copyright law and would subject you to possible fines or imprisonment. Violators will be prosecuted to the fullest extent of the law.

All rights reserved. Except for use in any review, the reproduction or utilization of this work in whole or in part in any form by any electronic, mechanical or other means, now known or hereafter invented, including xerography, photocopying and recording, or in any information or retrieval system, is forbidden without the prior written permission of both the publisher and copyright owner of this book.

On the next line, list the ISBN if you have one. Not all ebooks will. For example, you can list an ebook on Amazon.com with their Kindle  reader without an ISBN. However, if you plan on selling your ebook on your website or blog, it’s a good idea to have an ISBN.

Accomplishments

The page following the Notice to the Reader generally lists an author’s other works or accomplishments. If you have written other books, then type out “Also by” and follow with the names of the books. If you have created a game, teaching system, or any other accomplishment related to the ebook, then list it briefly on this page. If you don’t have these items, just leave the page blank.

Table of Contents

The next page allows for an optional table of contents. Type the name of each chapter, followed by the page number. If your ebook is short and you don’t have a table of contents, you can leave this section blank.

Text

Now you’re ready to start your text! This is the exciting part of writing. Craft your ebook text using double spacing.

Resources

At the end of your ebook, you may want to include resources to direct the reader to further information. These could be links to sites, books, or any other help information related to your ebook topic.

Including links is a great idea with an ebook, but the Internet changes quickly. It’s always a good idea to put a page on your website or blog that includes updates to the links you have in your ebook. Direct readers to your website for a list of current links. That way you only have to update one location (your website or blog) and you don’t need to re-issue copies of your ebook with corrected links.

Author Page

Following the resources, include an author page. This page should be brief, with a list of your other related accomplishments or writing works. Include a small photo of yourself as well. End the bio with your website, where readers can find out more about you.

ISBN

If you have an ISBN, end your book with its listing. Put the ISBN on the final page, in the bottom right corner.

Ebook Creation

When you are finished with your entire ebook manuscript, save the file as a PDF. This is the standard format for ebooks that are sold off of personal websites or blogs, as well as distributors such as Lightning Source.

May 26

Writing, Creating, Publishing, and Selling Ebooks

I’m going to be trying to finish creating my first ebook and then offer it for sale over the next month or so and this page is my initial “notes” for how to go about it. When I come across some useful concept  I’ll either add a link here or add a page to the new Ebook Publishing HowTo category.

The first resource I have to recommend is a website called smashwords to which you basically upload your manuscript and it converts and then sends it to various publishing sites like Amazon, Barnes and Noble, Apple, and more. The first link describes their service, but at the bottom of the page it has a link to several articles about how to be successful in publishing ebooks. They look like pretty good resources.

http://www.smashwords.com/about/how_to_publish_on_smashwords

The second link is a to a page where you can download their free book about how to format your ebook.

http://www.smashwords.com/books/view/52

I haven’t used the smashwords.com service so I’m only recommending them as a potential option and as a resource to learn from. If I decide to use them as my distributor then I’ll definitely post a review.

May 23

Fixed – I was not receiving emails of wordpress comments and updates

I finally got around to investigating what I had thought was probably a problem. I have a few wordpress sites that I wasn’t receiving emails when comments were made.

Basically, what I found was that the email address under the User->Admin profile didn’t match the one under the Settings->Email Address blank. I fixed that and poof I started getting the emails saying there were comments to approve… now I’ll actually be able to know when someone responds!

To be honest, I’m not sure if they have to be the same, or if they have to be somewhere that won’t be “blocked”. I host my own email so I changed them from an old “aol.com” address to an address within their own domain. I plan to stick with this model, even though it may not be required.

 

Feb 21

Quick notes on my first book scanner

I’ve been working on my first scanner. I decided to build the “new standard scanner”. The step by step guide to building it can be found here, but as it is fresh in my mind I want to throw out a couple of notes.

First, you only have to be pretty accurate in your measurements and cuts. For the most part the tolerance is quite large… which is good for me. 🙂

Second, this is a 90 degree scanner. That is, the book is held open at 90 degrees. Between 100 and 110 degrees is going to be a little better. The thing is that at 90 you are very close to ideal partly because your book bindings won’t get messed up from being opened too far. However, if you make it closer to 100 degrees you will get most of the same   benefit while also removing a small amount of “reflection” where the camera picks up the page across from what it’s shooting. It’s just a suggestion, but I’ll be building my second version to 100 degrees or maybe even up to  110 degrees. What would be awesome is if you angle was adjustable. And now that I think about it that might not be that hard and would be worth looking in to.

Third, do pre-drill holes before you screw them, especially on pieces of wood that you just spent a long time cutting! The screw can split your wood if you’re not careful.

references:

http://www.diybookscanner.org/

http://www.diybookscanner.org/forum/viewtopic.php?f=1&t=333

As a super final last note I have to mention that while writing this post I went to the  main diybookscanner.org page and then clicked on forum. When I did I was  redirected to some other site… I think it  was either an “ru” or an “nu” and had ff in it somewhere, I think. I was unable to reproduce it, and nothing ever loaded on the page,  but it somehow caused me to be logged out of most sites.  I’ve never had any problems visiting the diy site before, but I thought I’d mention it just in case.

 

Feb 05

Hashing library for iOS and how it can be used in conjunction with .Net hashing

I’m working on an iPhone / iPad app that needs to be able to authenticate itself to the server from which it requests data. The users of the app will have an account with the website so they will already have a username / password. There is no SSL functionality, so I needed a way to authenticate over plaintext without giving away the password or even the hash of it.

Let’s talk about what the webserver does in relation to storing the password. It doesn’t actually store the password.  It stores a hashed value where the actual password was combined with a salt (random string of a descent length) and that combined string was hashed using SHA256. The result is stored as the “password” for the user and the salt used to compute the hash is also stored for that user. When the user logs in the password they send (using ssl, so it is encrypted between the user and server) is combined with the stored salt and hashed. If the result is the same as the stored hash then the user is authenticated, otherwise they are not.

Here’s a little helper class written in C# for doing the Hash. It’s server side and .net specific.


#region HashingLogic
public class Hash
 {
 public Hash() { }
public enum HashType : int
 {
 MD5,
 SHA1,
 SHA256,
 SHA512
 }
public static string GetHash(string text, HashType hashType)
 {
 HashAlgorithm _algorithm;
 switch (hashType)
 {
 case HashType.MD5:
 _algorithm = MD5.Create();
 break;
 case HashType.SHA1:
 _algorithm = SHA1.Create();
 break;
 case HashType.SHA256:
 _algorithm = SHA256.Create();
 break;
 case HashType.SHA512:
 _algorithm = SHA512.Create();
 break;
 default:
 throw new ArgumentException("Invalid hash type", "hashType");
 }
byte[] bytes = Encoding.Unicode.GetBytes(text);
 byte[] hash = _algorithm.ComputeHash(bytes);
string hashString = string.Empty;
 foreach (byte x in hash)
 {
 hashString += String.Format("{0:x2}", x);
 }
 return hashString;
 }
public static bool CheckHash(string original, string hashString, HashType hashType)
 {
 string originalHash = GetHash(original, hashType);
 return (originalHash == hashString);
 }
}
 #endregion

And here’s the webserver checking the Hash. It should be pretty easy to see how to store it as well when a user sets their password in the first place.

 // ran a query that returned the hashed password and salt for the user in question
 // note: password is the value sent by the user trying to log in
 string the_hashed_password = dt.Rows[0]["vcHashedPass"].ToString().Trim();
 string the_salt = dt.Rows[0]["vcPassSalt"].ToString().Trim();
 string the_salted_password = password.Trim() + the_salt;
 string hashedvalue = Hash.GetHash(the_salted_password, Hash.HashType.SHA256);
     if (hashedvalue == the_hashed_password)
         loginSuccessful = true;

 

Now that we have the background, I can talk about what really screwed with me. I was trying to implement part of this on the iOS side. , but I was getting a different value back for my hash. I used a Hash library for iOS from this site. It was easy to use. Just copy the files to your project and import the .h into whatever file you need to do hashing.  Before hashing an NSString you must first convert it to an NSData. But this conversion requires you to specify the encoding. To use it in conjunction with the .Net helper class above you have to choose the right encoding or it will has to the wrong value. Code first, then discussion.

NSString *usernameex = [keychainwrapper objectForKey:(id)kSecAttrAccount];
 NSString *passwordex = [keychainwrapper objectForKey:(id)kSecValueData];
 // I'm hardcoding the salt for this example, now we need to talk to the server  to see if it will let us log in with it
NSString *retrievedSalt = [NSString stringWithFormat:@"b3b5c979-3438-4f56-aa1a-1d85bda78b7e"];
 NSString *saltedpassword =  [NSString stringWithFormat:@"%@%@", passwordex, retrievedSalt];
// Webserver thinks that hashed(password+salt)  =
 // 14083e601f136a42bb17f37a6dedfd03c1f53f2c93f2cc886de5b44ed4a452c1 -- looking for
// but this library was returning various results... here's one
 // ed87d50a50937361f17f9b3c32c6db04e6b7779e5f3c42dfa20e44cac7bf112e -- getting
 // there are lots of example of how the "encoding" can be done and what the hashed value that results is
 // I included them in this sample code because I had to try a ton to finally find the one that matched the .net
HashValue *hashvalue;
//NSUTF16StringEncoding 762ce0d893b64032f11562e4ee0be3f4ed08ca6b801ab892d319af3942ca788c
 NSData* datasaltedpassword0a=[saltedpassword dataUsingEncoding:NSUTF16StringEncoding];
 hashvalue = [HashValue sha256HashWithData:datasaltedpassword0a];
 ASLog(@"hashedvalue0a - %@", hashvalue.description); // password - whatever you entered
NSData* datasaltedpassword0b=[saltedpassword dataUsingEncoding:NSUTF16BigEndianStringEncoding];
hashvalue = [HashValue sha256HashWithData:datasaltedpassword0b];
ASLog(@"hashedvalue0b - %@", hashvalue.description); // password - whatever you entered
NSData* datasaltedpassword0c=[saltedpassword dataUsingEncoding:NSUTF16LittleEndianStringEncoding];
hashvalue = [HashValue sha256HashWithData:datasaltedpassword0c];
ASLog(@"hashedvalue0c - %@", hashvalue.description); // password - whatever you entered
NSData* datasaltedpassword0d=[saltedpassword dataUsingEncoding:NSUTF32StringEncoding];
hashvalue = [HashValue sha256HashWithData:datasaltedpassword0d];
ASLog(@"hashedvalue0d - %@", hashvalue.description); // password - whatever you entered
NSData* datasaltedpassword0e=[saltedpassword dataUsingEncoding:NSUTF32BigEndianStringEncoding];
hashvalue = [HashValue sha256HashWithData:datasaltedpassword0e];
ASLog(@"hashedvalue0e - %@", hashvalue.description); // password - whatever you entered
NSData* datasaltedpassword0f=[saltedpassword dataUsingEncoding:NSUTF32LittleEndianStringEncoding];
hashvalue = [HashValue sha256HashWithData:datasaltedpassword0f];
ASLog(@"hashedvalue0f - %@", hashvalue.description); // password - whatever you entered
//NSUTF8StringEncoding
NSData* datasaltedpassword1=[saltedpassword dataUsingEncoding:NSUTF8StringEncoding];
hashvalue = [HashValue sha256HashWithData:datasaltedpassword1];
ASLog(@"hashedvalue1 - %@", hashvalue.description); // password - whatever you entered
//[NSString defaultCStringEncoding]
NSData* datasaltedpassword2=[saltedpassword dataUsingEncoding:[NSString defaultCStringEncoding]];
hashvalue = [HashValue sha256HashWithData:datasaltedpassword2];
ASLog(@"hashedvalue2 - %@", hashvalue.description); // password - whatever you entered
//NSUnicodeStringEncoding allowLossyConversion:NO
NSData* datasaltedpassword3=[saltedpassword dataUsingEncoding:NSUnicodeStringEncoding allowLossyConversion:NO];
hashvalue = [HashValue sha256HashWithData:datasaltedpassword3];
ASLog(@"hashedvalue3 - %@", hashvalue.description); // password - whatever you entered
//NSWindowsCP1252StringEncoding
NSData* datasaltedpassword4=[saltedpassword dataUsingEncoding:NSWindowsCP1252StringEncoding];
hashvalue = [HashValue sha256HashWithData:datasaltedpassword4];
ASLog(@"hashedvalue4 - %@", hashvalue.description); // password - whatever you entered
//NSMacOSRomanStringEncoding
NSData* datasaltedpassword5=[saltedpassword dataUsingEncoding:NSMacOSRomanStringEncoding];
hashvalue = [HashValue sha256HashWithData:datasaltedpassword5];
ASLog(@"hashedvalue5 - %@", hashvalue.description); // password - whatever you entered
ASLog(@"targetvalue - 14083e601f136a42bb17f37a6dedfd03c1f53f2c93f2cc886de5b44ed4a452c1", hashvalue.description); // password - whatever you entered

And the output:

2012-02-05 16:13:38.077 [11082:560f] LoginViewController.m:121 -[LoginViewController workOfDoLogin] password – ocelot

2012-02-05 16:13:38.078 [11082:560f] LoginViewController.m:140 -[LoginViewController workOfDoLogin] salt – b3b5c979-3438-4f56-aa1a-1d85bda78b7e

2012-02-05 16:13:38.078 [11082:560f] LoginViewController.m:144 -[LoginViewController workOfDoLogin] saltedpassword – ocelotb3b5c979-3438-4f56-aa1a-1d85bda78b7e

2012-02-05 16:13:38.080 [11082:560f] LoginViewController.m:152 -[LoginViewController workOfDoLogin] hashedvalue0a – 762ce0d893b64032f11562e4ee0be3f4ed08ca6b801ab892d319af3942ca788c

2012-02-05 16:13:38.080 [11082:560f] LoginViewController.m:156 -[LoginViewController workOfDoLogin] hashedvalue0b – df7e828a1df0664ff42756960ab7f63e83f0504437c59286e217df32147d8815

2012-02-05 16:13:38.081 [11082:560f] LoginViewController.m:160 -[LoginViewController workOfDoLogin] hashedvalue0c – 14083e601f136a42bb17f37a6dedfd03c1f53f2c93f2cc886de5b44ed4a452c1

2012-02-05 16:13:38.082 [11082:560f] LoginViewController.m:164 -[LoginViewController workOfDoLogin] hashedvalue0d – 4276b8d7ff791492f537379bf7353095d8ce40c717f15dc242f2847b376b88de

2012-02-05 16:13:38.083 [11082:560f] LoginViewController.m:168 -[LoginViewController workOfDoLogin] hashedvalue0e – 45838174fdf6cb95b7ed6bdbd7409f065c75f12958e58ae84ec5d28235b6cf0e

2012-02-05 16:13:38.083 [11082:560f] LoginViewController.m:172 -[LoginViewController workOfDoLogin] hashedvalue0f – 492adfab98090cf9319684aa707d368a2689495480a59ffd7a9b2a514ea9362d

2012-02-05 16:13:38.084 [11082:560f] LoginViewController.m:178 -[LoginViewController workOfDoLogin] hashedvalue1 – ed87d50a50937361f17f9b3c32c6db04e6b7779e5f3c42dfa20e44cac7bf112e

2012-02-05 16:13:38.085 [11082:560f] LoginViewController.m:183 -[LoginViewController workOfDoLogin] hashedvalue2 – ed87d50a50937361f17f9b3c32c6db04e6b7779e5f3c42dfa20e44cac7bf112e

2012-02-05 16:13:38.086 [11082:560f] LoginViewController.m:188 -[LoginViewController workOfDoLogin] hashedvalue3 – 762ce0d893b64032f11562e4ee0be3f4ed08ca6b801ab892d319af3942ca788c

2012-02-05 16:13:38.086 [11082:560f] LoginViewController.m:193 -[LoginViewController workOfDoLogin] hashedvalue4 – ed87d50a50937361f17f9b3c32c6db04e6b7779e5f3c42dfa20e44cac7bf112e

2012-02-05 16:13:38.087 [11082:560f] LoginViewController.m:198 -[LoginViewController workOfDoLogin] hashedvalue5 – ed87d50a50937361f17f9b3c32c6db04e6b7779e5f3c42dfa20e44cac7bf112e

2012-02-05 16:13:38.088 [11082:560f] LoginViewController.m:201 -[LoginViewController workOfDoLogin] targetvalue – 14083e601f136a42bb17f37a6dedfd03c1f53f2c93f2cc886de5b44ed4a452c1

 

The right Encoding to use on the iOS side was “NSUTF16LittleEndianStringEncoding”. I had to do all of those tests to finally find which one matched the values being produced on the web side (.Net)… so just keep in mind that if your getting two different hashes then you might need to use a different Encoding during the conversion from String to Byte / Data in order to make them sync up.

 

Feb 04

Hiding the Keyboard when touching background

If you are working on an iOS app and have the need for the user the enter input then you usually use a textfield or textview. I was working on a login screen and had a very annoying experience where the keyboard wouldn’t go away after I had finished entering my text. What was especially annoying was that I had encountered it before and had simply forgotten how to resolve it. So I’m writing this up for myself or anyone else who needs the info.

All you have to do is make sure that your view has ‘User Interaction Enabled’ checked under the ‘Attributes Inspector’. Then add the following block of code to your view’s implementation. You can see that I have two textFields called txtUsername and txtPassword. You’ll want to change them to match the names of all the text fields on your form (you don’t know which one is actually the first responder at the time, but from what I’ve read it doesn’t hurt to resign if you are not it anyway). So that’s it.

– (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch * touch = [touches anyObject];

if(touch.phase == UITouchPhaseBegan) {

[self.txtPassword resignFirstResponder];

[self.txtUserName resignFirstResponder];

}

}

Here’s another place that discusses it in a bit more detail.

I’ll also mention that some people use a hidden button the size of the view. Then they tie that button to a “hideKeyboard” method. That solution is also discussed in that thread. I found a better explanation of it a Sams Publishing teach yourself Iphone Development book, but the discussion on that thread will suffice. For my own reference it is on page 179-182. It also discusses how to release the keyboard when the “Done” button is pressed. You will probably want to implement BOTH.

Dec 28

Prolog Language References

I’m currently reviewing an existing system written in vb6 that management at the company I work for has finally decided to get behind porting it. Their plan is to port it to Visual Studio (VB.net) as that is what they are comfortable with. I understand this desire, but I’m also hesitant to jump right in and do so because they are also looking for “better ways to do things” during the transition. This particular system is very “rules driven” and we have a massive amount of code dedicated to supporting these rules. In my opinion this is just screaming for Prolog to be a part of the solution, and since I have some say in the matter I’ll be as neck deep in prolog over the next couple of months. I’ll be trying to get a proof of concept in place before the conversion gets underway so I can prove its value. Either that, or I might just prove that it won’t do the job I want it to and I will be able to dive into the rewrite as previously planned without hesitation or hinderance.

While I can’t tell you what the project is I can tell you that in just one of my fact databases I expect to have well over 1/2 million facts. The facts are relatively static so that’s good. The facts will be queried upon often over 1million times per day and it should be able to handle that without breaking a sweat as this is only about 5% of the total volume we expect to see.

So, that being said, I’m working on compiling a list of Prolog references (websites mainly) that will help me progress as quickly and painlessly as possible. If you have any suggestions for books I’d also love to hear them and will likely be adding them to the post or as seperate posts as I go.

So, here come my links on into topics:

http://boklm.eu/prolog/page_0.html

SWI-Prolog
A short Introduction to Prolog
A Short Tutorial On Prolog
Introduction to Prolog for Mathematicians
iProlog Programmer’s Manual
Prolog Tutorials
A Concise Introduction to Prolog

 

Dec 04

IF (by Rudyard Kipling)

True in sports, business, and life in general:

IF you can keep your head when all about you
Are losing theirs and blaming it on you,
If you can trust yourself when all men doubt you,
But make allowance for their doubting too;
If you can wait and not be tired by waiting,
Or being lied about, don’t deal in lies,
Or being hated, don’t give way to hating,
And yet don’t look too good, nor talk too wise:

If you can dream – and not make dreams your master;
If you can think – and not make thoughts your aim;
If you can meet with Triumph and Disaster
And treat those two impostors just the same;
If you can bear to hear the truth you’ve spoken
Twisted by knaves to make a trap for fools,
Or watch the things you gave your life to, broken,
And stoop and build ’em up with worn-out tools:

If you can make one heap of all your winnings
And risk it on one turn of pitch-and-toss,
And lose, and start again at your beginnings
And never breathe a word about your loss;
If you can force your heart and nerve and sinew
To serve your turn long after they are gone,
And so hold on when there is nothing in you
Except the Will which says to them: ‘Hold on!’

If you can talk with crowds and keep your virtue,
‘ Or walk with Kings – nor lose the common touch,
if neither foes nor loving friends can hurt you,
If all men count with you, but none too much;
If you can fill the unforgiving minute
With sixty seconds’ worth of distance run,
Yours is the Earth and everything that’s in it,
And – which is more – you’ll be a Man, my son!