Skip to content

Instantly share code, notes, and snippets.

View ahmednuaman's full-sized avatar
💭
I'm hiring! https://firemind.io/careers

Ahmed Nuaman ahmednuaman

💭
I'm hiring! https://firemind.io/careers
View GitHub Profile
public function check_youtube_url($s, $c=FALSE)
{
$page = 'youtube.com/watch?';
$player = 'youtube.com/v/';
$short = 'youtu.be/';
$clean = str_replace( array( 'http://', 'www.' ), '', $s );
if ( strpos( $clean, $page ) === 0 )
{
@ahmednuaman
ahmednuaman / check_for_touch_device.js
Created November 16, 2010 15:55
A simple little script to check for a touch enabled device
var el = document.createElement( 'div' );
el.setAttribute( 'ontouchstart', 'return;' );
if ( typeof el.ontouchstart == 'function' )
{
// yay a touch device!
}
@ahmednuaman
ahmednuaman / update-wordpress.sh
Created December 1, 2010 11:13
A simple bash script to update Wordpress
#!/bin/bash
# This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License.
# To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter
# to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA.
# So before you start, the script assumes the following:
# 1. you have some sort of SSH access
# 2. you are owner of your blog (in terms of computa permissions)
# 3. the blog folder is called 'blog' (if not, change all instances of the word 'blog' with whatever it's called)
@ahmednuaman
ahmednuaman / wordpress-multisite-lighttpd.conf
Created December 12, 2010 21:52
A nice little rewrite directive for WordPress Multi-site and Lighttpd
url.rewrite-once = (
"^/(.*/)?files/$" => "/index.php",
"^/(.*/)?files/(.*)" => "/wp-content/blogs.php?file=$2",
"^(/wp-admin/.*)" => "$1",
"^/([_0-9a-zA-Z-]+/)?(wp-.*)" => "/$2",
"^/([_0-9a-zA-Z-]+/)?(.*\.php)" => "/$2",
"^/(.*)/?$" => "/index.php"
)
@ahmednuaman
ahmednuaman / detect_if_dom_is_ready.js
Created March 8, 2011 16:52
Using document.readyState to see if the DOM is ready
var timer = setInterval( function()
{
if ( /loaded|complete/.test( document.readyState ) )
{
clearInterval( timer );
// go!
}
}, 10 );
@ahmednuaman
ahmednuaman / get_touch_coords.js
Created March 31, 2011 11:25
This converts touch events list to a single coors x,y object
function scrollGetCoords(e)
{
var coors;
if ( e.hasOwnProperty( 'originalEvent' ) )
{
e = e.originalEvent;
}
if ( e.touches && e.touches.length )
@ahmednuaman
ahmednuaman / serialise.py
Created April 28, 2011 15:14
Prepare a GAE model for serialisation
#!/usr/bin/env python
import logging
import urllib
def serialise_model(m, d):
# let's serialise this bad boy
ps = m.properties()
# check if we're dealing with a list or not
@ahmednuaman
ahmednuaman / title_case.php
Created October 19, 2011 09:57
Convert strings to title case
function title_case($string, $delimiters = array(" ", "-", "O'"), $exceptions = array("to", "a", "the", "of", "by", "and", "with", 'it', 'as', "for")) {
/*
* Exceptions in lower case are words you don't want converted
* Exceptions all in upper case are any words you don't want converted to title case
* but should be converted to upper case, e.g.:
* king henry viii or king henry Viii should be King Henry VIII
*/
foreach ($delimiters as $delimiter){
$words = explode($delimiter, $string);
$newwords = array();
@ahmednuaman
ahmednuaman / css_animation_util.py
Created November 30, 2011 19:12
A little utility to take the pain out of writing vendor prefixed CSS3 animations
a = [ 'webkit', 'moz', 'ms', 'o', '' ]
n = 'enter'
f = {
'from' : [
'opacity: 0',
'.transform( e(\'rotate(360deg)\')'
],
'to' : [
'opacity: 1',
@ahmednuaman
ahmednuaman / animateCSS.js
Created December 7, 2011 14:38
jQuery plugin to dynamically apply animate.css animations
(function ($) {
$.fn.animateCSS = function (effect, delay, callback) {
// Return this to maintain chainability
return this.each(function () {
// Cache $(this) for speed
var $this = $(this);