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.
@marcelaraujo
marcelaraujo / checkUrl.php
Last active December 14, 2015 05:49
Check if a URL exists testing its header.
<?php
function checkUrl($url) {
if( !extension_loaded('curl')) {
trigger_error('The curl extension was not loaded.', E_USER_ERROR);
}
$status = preg_match('/^https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/_\.\-?]*(\?\S+)?)?)?$/i', $url);
if( $status === false ) {
@marcelaraujo
marcelaraujo / gist:5287579
Last active December 15, 2015 16:09
Zend Session on Redis
<?php
/**
* @see Zend_Session
*/
require_once 'Zend/Session.php';
/**
* @see Zend_Config
*/
<?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
@marcelaraujo
marcelaraujo / gist:7042602
Created October 18, 2013 14:44
10 commands most used
history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
@marcelaraujo
marcelaraujo / gist:10610335
Created April 14, 2014 01:49
jQuery window resize
/* Get size of viewport */
layout.winWidth = $(window).width();
layout.winHeight = $(window).height();
/* Get available width by subtracting the size of the rest of the components */
var dwidth = layout.winWidth - 63;
var dheight = layout.winHeight - 111;
/* Check if scrollbars are needed (cheight and cwidth are canvas element's height and width)*/
var vScrollNeeded = dheight < app.cheight;
var person = {};
Object.defineProperty(person, 'firstName', {
get: function() { return firstName; },
set: function(newName) { firstName = newName; },
enumerable: true
});
Object.defineProperty(person, 'lastName', {
get: function() { return lastName; },
@marcelaraujo
marcelaraujo / gist:10610377
Created April 14, 2014 01:50
PHP Build compile
./configure \
--prefix=/usr/local \
--disable-debug \
--enable-pdo \
--enable-inline-optimization \
--enable-xml \
--enable-fpm \
--enable-ftp \
--enable-gd-jis-conv \
--enable-intl \