Tag Archives: Snippet

Calculate an MD5 Hash in Objective-C

First place this line after the UIKit #import of the .h file:

And then add this function to your .m file:

Use it like:

 

Prevent First TableViewCell to be Sorted Over or Moved in UITableView

I was creating a small todo app for fun, had a UITableView Set Up populated by an SQLite database, wanted to keep the first cell the “Inbox” and have it not be moved, or have any other cell be able to be sorted above it. After hours of trying to figure out the method to do this I figured out that a few things needed to be done in a few methods:

First, tell the <b>canMoveRowAtIndexPath</b> method that the first row can not be moved when the table is in edit mode:

Second, tell the <b>canEditRowAtIndexPath</b> that the row can not be deleted:

Finally, tell the <b>targetIndexPathForMoveFromRowAtIndexPath</b> method to not let anything be dragged above the first cell, but let the rest of the cells swap any where else they want:

Hope this helps anyone that was having the same problem.

Prevent Double Submit on Forms with jQuery

The following snippet disables the submit button of all forms in scope of the function after the submit button has been initially clicked. To prevent users from submitting your forms more than once.

How does it work?

When the submit button of the form is clicked, it triggers the form submit function of jquery, then takes the submit handler of the current form and makes it return false so it can’t submit the same form again.

Equal Column Heights with jQuery

The function:

This function loops through each of the elements passed in as parameters and sets each one equal to the tallest element in the group.

Usage:

 

Zebra Stripe a Table or List with jQuery

This snippet lets you strip the even/odd rows of your tables/lists different colors for easier reading:

 

Enable HTML5 Markup on Older Browsers

HTML5 is definitely the future of client-side web development. Unfortunately, some old browsers do not even recognize new tags such as header or section. This code will force old browsers to recognize the new tags introduced by HTML5.

A better solution is to link the .js file to the <head> part of your HTML page:

Source: http://remysharp.com/2009/01/07/html5-enabling-script/

PHP E-mail Validation

Use:

 

Insert Pieces of WordPress Into A Custom Website

WordPress is an Amazing tool, and it has 99% of what most people look for in a website. However, if you’re a Web Designer and design and code custom websites for your clients and don’t want to conform to the constraints of WordPress, BUT your clients still want to be able to update their own website, WordPress has a solution for you.

WordPress provides you with very powerful tools to embed its content into custom websites. So you built this gorgeous website frame with no content right? You install WordPress and add the content as either a post, or a page. Just throw one of the snippets below into your HTML, XHTML, HTML5 page where you want the WordPress content to appear:

Embed a WordPress Page:

The page ID is the ID generated by WordPress for that specific page, located in the Query String of the URL.

The  require('blog/wp-blog-header.php');  line refers to the location of the wp-blog-header.php file on your server.

Embed All The Posts

Use the Query Parameters of the get_posts() functions provided by WordPress to narrow down the list of results returned.

You can also substitute get_posts() with query_posts() for a different set of results. For Example:

Which returns the last three posts.

Get Posts Published Between Two Dates

Insert Ads After the First Post

Obviously replace //place your ad code here with your preferred advertisement code.

So now you can keep the amazing look you worked so hard on, and have your client be able to update his/her own content.

PHP Encrypt & Decrypt

Encrypt:

Decrypt:

Key can be specific for whatever application you’re using the encryption for. For example, if you’re using it to encrypt passwords you would do something along the lines of:

Now whenever you wanted to decrypt the user password you would have to use the same key:

Which leaves the functions open to an infinite number of applications.