Skip to content

Instantly share code, notes, and snippets.

@danielrw7
danielrw7 / jquery.ajax-load.js
Last active June 14, 2016 19:51
ajax-load html attribute
$(function() {
$('[ajax-load]').each(function() {
var $this = $(this);
$this.load($this.attr('ajax-load'), function() {
if ($this.attr('ajax-onloaded')) {
eval($this.attr('ajax-onloaded'));
}
});
});
});
function Timer() {
var _this = {};
return extend.bind(this, _this, {
timestamp: new Date().getTime(),
timeout: -1,
delay: 1000,
tick: function(timestamp) {
var timestamp = timestamp || this.now();
this.timeout = setTimeout(function() {
var timestamp = _this.now();
function extend() {
var result = arguments[0];
for(var i = 1; i < arguments.length; i++) {
for(var key in arguments[i]) {
result[key] = arguments[i][key];
}
}
return result;
}
<?php
function ordinal_suffix($n) {
$j = $n % 10;
$k = $n % 100;
if (!($k >= 11 && $k <= 19)) {
switch($j) {
case 1:
return "st";
case 2:
function once(fns, callback, args) {
var c = 0;
var len = fns.length;
var results = [];
fns.forEach(function(fn, i) {
fn.apply(fn, [function(value) {
results[i] = value;
c++;
if (c == len) {
callback.apply(callback, results);
function sort(rows, key, dir) {
if (!key || !rows || typeof rows.sort !== "function" || !rows.length) {
return rows;
}
var dir = dir ? String(dir).toLowerCase() : "up";
if (typeof key === "function") {
return rows.sort(key);
} else {
return rows.sort(function(rowA, rowB) {
if (dir === "u" || dir === "up" || dir === "asc") {
<?php
$profiles = array();
function profile_start($key) {
global $profiles;
$profiles[$key] = array();
$profiles[$key]["start"] = microtime(true);
}
function profile_end($key) {
global $profiles;
@danielrw7
danielrw7 / make-address.php
Last active February 26, 2016 15:53
PHP Address HTML
<?php
function make_address($info = array(), $line_seperator = "<br>\r\n") {
extract($info);
$address = "";
if (isset($address_line_1) && $address_line_1) {
$address .= $address_line_1;
}
if (isset($address_line_2) && $address_line_2) {
if ($address) {
@danielrw7
danielrw7 / php-json.php
Last active November 25, 2016 17:01
PHP array manipulation
<?php
/**
* Author: Daniel Wilson <danielrw7@gmail.com> (https://github.com/danielrw7)
* Gist: https://gist.github.com/danielrw7/63ee3faffb86613f379a
*/
function props($key) {
$props = preg_split("/[\\.\\[\\]\\\"]/", trim($key));
$result = array();

Keybase proof

I hereby claim:

  • I am danielrw7 on github.
  • I am danielrw (https://keybase.io/danielrw) on keybase.
  • I have a public key ASAk-oo3HcNTfezT-rsWc1XfYNJPJb1Q4TU5e4OidsIr4wo

To claim this, I am signing this object: