Skip to content

Instantly share code, notes, and snippets.

View hoandang's full-sized avatar
👟
Roaming

Hoàn Đặng hoandang

👟
Roaming
  • Sydney, Australia
View GitHub Profile
#!/bin/bash
#
# Build and iPhone Simulator Helper Script
# Shazron Abdullah 2011
#
# WARN: - if your .xcodeproj name is not the same as your .app name,
# this won't work without modifications
# - you must run this script in where your .xcodeproj file is
PROJECTNAME=$1
@hoandang
hoandang / get_paramater.js
Created September 23, 2013 13:58
Get parameter query from URL
function getParameterByName(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
<?php
function response_json_error($app, $http_code, $msg)
{
$app->response()->status($http_code);
$app->response()->header('X-Status-Reason', $msg);
echo json_encode(array('error' => $msg));
}
function array_to_json($array)
{
return json_decode(json_encode($array));

#Migrating from homebrew-php to phpbrew

After installing phpbrew it's time to install a set of chosen PHP versions. My picks at the time of this writing were:

sudo phpbrew install php-5.5.0 +default+dbs+mb+apxs2=/usr/sbin/apxs
sudo phpbrew install php-5.3.27 +default+dbs+mb+apxs2=/usr/sbin/apxs
sudo phpbrew install php-5.5.0 +default+dbs+mb+apxs2=/usr/sbin/apxs

When not sure where apxs is located on your system, whereis apxs is quite chatty.

@hoandang
hoandang / z-installation
Last active December 21, 2015 04:18
Install z command on Linux
Clone z from rupa github
Put . /path/to/z.sh this in your $HOME/.bashrc or $HOME/.zshrc:
createjs.Bitmap.prototype.setWidth = function(w)
{
if (this.image.width == 0) return;
this.scaleX = w / this.image.width;
}
createjs.Bitmap.prototype.setHeight = function(h)
{
if (this.image.height == 0) return;
function clear_input_file(input)
{
input.replaceWith(input = input.clone(true));
}
@hoandang
hoandang / outHtml.js
Last active December 19, 2015 12:39
Javascript: Get outer html of a element
jQuery.fn.outerHTML = function() {
return jQuery('<div />').append(this.eq(0).clone()).html();
};
@hoandang
hoandang / crop.php
Created July 7, 2013 13:03
PHP: Crop Image
<?php
$x = $_POST['x'];
$y = $_POST['y'];
$w = $_POST['w'];
$h = $_POST['h'];
$targ_w = 800;
$targ_h = 620;
$jpeg_quality = 90;
@hoandang
hoandang / serialise.js
Created July 7, 2013 12:02
Javascript: Serialise Form into Object
$.fn.serializeObject = function() {
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {