Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I'm hiring! https://firemind.io/careers

Ahmed Nuaman ahmednuaman

💭
I'm hiring! https://firemind.io/careers
View GitHub Profile
View Checking YouTube URL
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 Nov 16, 2010
A simple little script to check for a touch enabled device
View check_for_touch_device.js
var el = document.createElement( 'div' );
el.setAttribute( 'ontouchstart', 'return;' );
if ( typeof el.ontouchstart == 'function' )
{
// yay a touch device!
}
@ahmednuaman
ahmednuaman / update-wordpress.sh
Created Dec 1, 2010
A simple bash script to update Wordpress
View update-wordpress.sh
#!/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 Dec 12, 2010
A nice little rewrite directive for WordPress Multi-site and Lighttpd
View wordpress-multisite-lighttpd.conf
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 Mar 8, 2011
Using document.readyState to see if the DOM is ready
View detect_if_dom_is_ready.js
var timer = setInterval( function()
{
if ( /loaded|complete/.test( document.readyState ) )
{
clearInterval( timer );
// go!
}
}, 10 );
@ahmednuaman
ahmednuaman / get_touch_coords.js
Created Mar 31, 2011
This converts touch events list to a single coors x,y object
View get_touch_coords.js
function scrollGetCoords(e)
{
var coors;
if ( e.hasOwnProperty( 'originalEvent' ) )
{
e = e.originalEvent;
}
if ( e.touches && e.touches.length )
@ahmednuaman
ahmednuaman / serialise.py
Created Apr 28, 2011
Prepare a GAE model for serialisation
View serialise.py
#!/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 Oct 19, 2011
Convert strings to title case
View title_case.php
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 Nov 30, 2011
A little utility to take the pain out of writing vendor prefixed CSS3 animations
View css_animation_util.py
a = [ 'webkit', 'moz', 'ms', 'o', '' ]
n = 'enter'
f = {
'from' : [
'opacity: 0',
'.transform( e(\'rotate(360deg)\')'
],
'to' : [
'opacity: 1',
@ahmednuaman
ahmednuaman / animateCSS.js
Created Dec 7, 2011
jQuery plugin to dynamically apply animate.css animations
View animateCSS.js
(function ($) {
$.fn.animateCSS = function (effect, delay, callback) {
// Return this to maintain chainability
return this.each(function () {
// Cache $(this) for speed
var $this = $(this);