Skip to content

Instantly share code, notes, and snippets.

View htchaan's full-sized avatar

htc htchaan

  • Hong Kong
View GitHub Profile
@olleolleolle
olleolleolle / es5array.js
Created February 23, 2010 14:17
adds ECMA-262 methods to Array prototype
/**
* Adds ECMA-262 rev. 5 methods to Array prototype, if they are missing
* Please note that the global prototypes are updated, so only use this file
* if that is acceptable, or if you're running in an iframe
*
* Please not that this file WILL NOT BE COPYRIGHTED, as it merely wraps mozilla implementation
* of JavaScript 1.6 / ECMA-262 rev. 5 methods
*
* @author Morgan Roderick - morgan@roderick.dk
*/
@cowboy
cowboy / callbackify.js
Created April 14, 2012 15:25
JavaScript callbackify
/*
* callbackify
*
* Copyright (c) 2012 "Cowboy" Ben Alman
* Licensed under the MIT license.
* http://benalman.com/about/license/
*/
function callbackify(fn, args, done) {
// If the function arity exceeds args length, it's accepts a "done" callback.
@RichardStyles
RichardStyles / JsonResponse.php
Last active May 26, 2016 18:31
Middleware for PHP Slim framework 3.x to output JSON responses with the correct header. Probably a better way to do this then just simply interrogating the response body, but for a initial test sufficient for my needs.
<?php
/**
* Middleware to set correct header for JSON output.
* Very basic initial version, simply checks the body of the response to see if it is valid JSON.
* If response is not JSON then continues with default settings.
* If response is JSON then header is updated.
*
* @author Richard Styles
*/
namespace App\Middleware;
# script insstalls qemu and vagrant, then uses vagrant to build a qemu-
# supported rpi kernel for dev.
# - tested with 2015-02-16-raspbian-wheezy.zip on OSX El Capitan
# Variables
IMAGE=http://downloads.raspberrypi.org/raspbian_latest
IMG_PATH="/vagrant/raspbian_latest.img"
PI_LINUX=https://github.com/raspberrypi/linux
PI_LINUX_BRANCH="rpi-4.2.y"
PI_TOOLS=https://github.com/raspberrypi/tools
@mikejolley
mikejolley / gist:1565309
Created January 5, 2012 13:42
WooCommerce - Filters to add custom currencies and symbols
add_filter( 'woocommerce_currencies', 'add_my_currency' );
function add_my_currency( $currencies ) {
$currencies['ABC'] = __( 'Currency name', 'woocommerce' );
return $currencies;
}
add_filter('woocommerce_currency_symbol', 'add_my_currency_symbol', 10, 2);
function add_my_currency_symbol( $currency_symbol, $currency ) {
@Ocramius
Ocramius / nested-transactions.php
Created January 20, 2015 12:59
Multiple nested Doctrine2 EntityManager transactions pseudo-code
<?php
use doctrine\ORM\EntityManagerInterface;
$entityManager->transactional(function (EntityManagerInterface $entityManager) {
// first transaction
$entityManager->transactional(function () {
// nested transaction #1
});
@phatblat
phatblat / heroku-node-init.sh
Created January 31, 2012 22:28
Bash script to initialize an OS X box for local development of node app on heroku
#!/bin/bash
NODE_VERSION=0.4.7
NPM_VERSION=1.0.94
# Save script's current directory
DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
#cd "${DIR}"
#
@leodutra
leodutra / get-absolute-path.sh
Created February 3, 2016 13:31
Getting absolute path of a shell / bash script file in execution time
#!/bin/bash
# REFERENCE: http://stackoverflow.com/a/1638397/1260526
# Absolute path to this script, e.g. /home/user/bin/foo.sh
SCRIPT=$(readlink -f "$0")
# Absolute path this script is in, thus /home/user/bin
SCRIPTPATH=$(dirname "$SCRIPT")
echo $SCRIPTPATH
@NV
NV / clone_object_with_circular_references.js
Created November 26, 2011 18:22
Clone an Object with all its circular references. Take that jQuery.extend!
function cloneObject(object) {
return extendObject({}, object);
}
function extendObject(base, object) {
var visited = [object];
// http://en.wikipedia.org/wiki/Adjacency_list_model
var set = [{value: base}];
brew install libvirt
sudo ln -s /opt/vagrant/embedded/include/ruby-2.0.0/{universal-darwin12.6.0,x86_64-darwin12.6.0}
ARCHFLAGS='-arch x86_64' \
CONFIGURE_ARGS="with-libvirt-include=/usr/local/include/libvirt:/opt/vagrant/embedded//include/ruby-2.0.0/universal-darwin12.6.0/ with-libvirt-lib=/usr/local/lib" \
vagrant plugin install vagrant-libvirt