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
@ahmednuaman
ahmednuaman / parse.py
Created October 3, 2014 14:50
A simple example of how to parse a page with python
import urllib2
from bs4 import BeautifulSoup
page = urllib2.urlopen('http://www.bbc.co.uk/sport/football/tables')
soup = BeautifulSoup(page)
rows = soup.find_all('tr')
for row in rows:
team = row.find('td', class_='team-name')
@ahmednuaman
ahmednuaman / grunt-githash.js
Created December 12, 2014 15:22
Grunt githash grabber
// use like <%= commitsha1 %>
grunt.registerTask('githash', function () {
var done = this.async(),
config;
config = {
cmd: 'git',
args: ['rev-parse', '--verify', 'HEAD']
};
@ahmednuaman
ahmednuaman / default.js
Created January 6, 2015 16:00
Getting BrowserSync and gulp-watch to play nicely
var browserSync = require('browser-sync'),
common = require('./__common__'),
gulp = require('gulp'),
watch = require('gulp-watch');
gulp.task('default', [
'less'
], function () {
browserSync({
server: {
@ahmednuaman
ahmednuaman / gist:6156cad582db96a9099e
Created April 11, 2015 13:39
Cannot resolve module 'istanbul-instrumenter-loader'
var cwd = process.cwd(),
path = require('path');
module.exports = function (config) {
config.set({
basePath: cwd,
browsers: [
'Chrome'
],
files: [
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
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 / 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