Category Archives: Snippets

Take Screenshot Programmatically in iOS

This snippet of code can be added to any event handler to take a current screenshot of whatever is on the screen of the iOS device:

 

Unzipping Files with PHP

Many web applications require users to upload files to perform an action on. Say you have an image hosting website and you allow bulk uploading (meaning more than one image at a time), it may be un user friendly for the person uploading to have to click ‘Browse’ and choose ten images. Why not give the ability to upload a zip file of images to your server, and have your server unzip the archive and place the files where need be. Consider the small function below:

The function takes two parameters, the location of the zip file, and the location where you’d like the contents of the zip file to be stored. You can format it to fit your needs.

Call it like so:

PHP Database Connect Class

Save the following code as something like db_connect.php

Replace the host, username, and password with your own, and then replace DATABASE NAME with the database you will be working with.

Include it in any file working with database connections:  include("db_connect.php");

After this file is included you may do all of your database work between these two calls:

Database manipulation here…

PHP E-mail Validation

Use:

 

HTML Country Lists

Short Values:

Long Values:

 

Floating Corners With CSS

Ever wonder how some websites put banners or other graphics in the corners of your screen that stay where they are no matter how you manipulate the window?

Use one of the four options below to add whatever you want to the corners of your website. The absolute positioning and z-index assures nothing on the page will be disturbed.

The CSS:

And place it with:

 

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.

Get Path to Documents Directory of iOS in Xcode

 

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.