Skip to content

Instantly share code, notes, and snippets.

View marcelaraujo's full-sized avatar

Marcel Araujo marcelaraujo

View GitHub Profile
Index: ext/spl/spl_classloader.c
===================================================================
--- ext/spl/spl_classloader.c (revision 0)
+++ ext/spl/spl_classloader.c (revision 0)
@@ -0,0 +1,464 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2009 The PHP Group |
<?php
/**
* SplClassLoader implementation that implements the technical interoperability
* standards for PHP 5.3 namespaces and class names.
*
* http://groups.google.com/group/php-standards/web/final-proposal
*
* // Example which loads classes for the Doctrine Common package in the
* // Doctrine\Common namespace.
<?php
// Access a property with no restrictions
function stole($object,$property){
$dict = (array)$object;
$class = get_class($object);
return isset($dict[$property])?
$dict[$property]:(isset($dict["\0*\0$property"])?
$dict["\0*\0$property"]:(isset($dict["\0$class\0$property"])?
$dict["\0$class\0$property"]:null));
''' listing 6: pi_mp.py
Multiprocessing based code to estimate the value of PI
using monte carlo sampling
Ref: http://math.fullerton.edu/mathews/n2003/montecarlopimod.html
Uses workers:
http://docs.python.org/library/multiprocessing.html#module-multiprocessing.pool
'''
import random
/*! Copyright (c) 2011 Piotr Rochala (http://rocha.la)
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
*
* See working example at http://rocha.la/fun-with-pixels-html5-video-canvas
*
*/
var canvasVideo = function()
{
var $ = jQuery,
function updateSVG() {
var el = document.querySelector('.icon-user');
var style = window.getComputedStyle(el);
var uri = style.backgroundImage;
var svg64 = uri.replace(/^.+base64,/, "").replace(/\"?\)$/, "")
var xml = window.atob(svg64);
var hex = '#' + Math.floor(Math.random()*16777215).toString(16);
var color = xml.replace(/fill="#[A-Za-z0-9]+"/, 'fill="' + hex + '"');
var color64 = window.btoa(color);
var colorUri = "url('data:image/svg+xml;base64," + color64 + "')";
#!/usr/bin/env python
# Clone or update all a user's gists
# curl -ks https://gist.githubusercontent.com/fedir/5466075/raw/gist-backup.py | USER=fedir python
# USER=fedir python gist-backup.py
import json
import urllib
from subprocess import call
from urllib import urlopen
import os

Moving from jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
<?php
// root path
$path = realpath('.');
// finds everything in $path including root directory
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
$success = 0;
$error = 0;
$skipped = 0;
<?php
// A closure can be bound ($this will be a specific object), unbound ($this not set) or static ($this cannot be set)
// A closure may be scoped (it can see the private properties of a specific class), or unscoped (no class)
// At present, a closure must be bound or static if it is scoped, and unscoped if it is unbound
// I propose changing this to also allow scoped, unbound closures
// I want to add Closure::call, which lets you call and bind a closure (to avoid creating a new closure for each object you want to bind to)
$foo = function () {
return $this->x;