Skip to content

Instantly share code, notes, and snippets.

RegExp.escape = function(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
}
function searchScore(query, data) {
var query = query.toString().replace(/\s+/g, " ");
var queryRegEx = new RegExp(RegExp.escape(query), "g");
function uniqueArray(array) {
var result = [];
for(var i in array) {
if (result.indexOf(array[i]) === -1) {

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:

@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();
@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) {
<?php
$profiles = array();
function profile_start($key) {
global $profiles;
$profiles[$key] = array();
$profiles[$key]["start"] = microtime(true);
}
function profile_end($key) {
global $profiles;
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") {
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);
<?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 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;
}
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();