Skip to content

Instantly share code, notes, and snippets.

View mahadazad's full-sized avatar

Muhammad Mahad Azad mahadazad

View GitHub Profile
@mahadazad
mahadazad / gist:5992341
Created July 13, 2013 21:45
Extract MySQL queries to PHP arrays.
preg_match_all('/^(?:UPDATE|SELECT|INSERT INTO|CREATE).*;$/smU', file_get_contents('dump.sql'), $matches);
<?php
function slugify($text) {
// replace non letter or digits by -
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
// trim
$text = trim($text, '-');
// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// lowercase
$text = strtolower($text);
<?php
/**
* @link http://stackoverflow.com/q/10212752/367456
* @link http://msdn.microsoft.com/en-us/magazine/ee335713.aspx
*/
$file = 'billion-laughs-2.xml';
$file = 'quadratic-blowup-2.xml';
printf("Mem: %s (Peak: %s)\n", number_format(memory_get_usage(), 0, '', ' '), number_format(memory_get_peak_usage(), 0, '', ' '));
<?php
/**
* Create a web friendly URL slug from a string.
*
* Although supported, transliteration is discouraged because
* 1) most web browsers support UTF-8 characters in URLs
* 2) transliteration causes a loss of information
*
* @author Sean Murphy <sean@iamseanmurphy.com>
* @copyright Copyright 2012 Sean Murphy. All rights reserved.
<?php
/**
* Compares two strings.
*
* This method implements a constant-time algorithm to compare strings.
* Regardless of the used implementation, it will leak length information.
*
* @param string $knownString The string of known length to compare against
* @param string $userInput The string that the user can control
*
<link rel="import" href="../polymer/polymer.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
height: 100%;
@mahadazad
mahadazad / main.js
Last active August 29, 2015 14:17 — forked from jpoehls/main.js
var Benchmark = require('benchmark');
var request = require('request');
var suite = new Benchmark.Suite;
// add tests
suite.add('Calling cow api', {
defer: true,
fn: function(deferred) {
request({
@mahadazad
mahadazad / README.md
Last active August 29, 2015 14:20 — forked from xarem/README.md
  • Step 1, create Service in Automator:

Step 1

  • Step 2, set Service for files:

Step 2

  • Step 3: insert bash script (see below)
  • Step 4, save:
function is32Bit(c) {
return c.codePointAt(0) > 0xFFFF;
}
console.log(is32Bit("𠮷")); // true
console.log(is32Bit("a")); // false
@mahadazad
mahadazad / app.js
Last active August 29, 2015 14:26 — forked from jmdobry/app.js
js-data + js-data-firebase + js-data-localstorage
var fb = new DSFirebaseAdapter({
basePath: 'https://my-app.firebase.io'
});
var ls = new DSLocalStorageAdapter();
var store = new JSData.DS({
// After creating an item, sync it to localStorage
afterCreate: function (resource, data) {
return ls.create(resource, data);