Skip to content

Instantly share code, notes, and snippets.

View dhigginbotham's full-sized avatar
😸
happycat

David Higginbotham dhigginbotham

😸
happycat
View GitHub Profile
@dhigginbotham
dhigginbotham / xhr.js
Last active August 29, 2015 13:55
xhr.get('https://api.github.com/users/dhigginbotham', function(err, ctx) { console.log((err ? err : ctx)) });
/**
* async xhr, provides a modern browser
* ajax api with less suck
*
* author: dhigginbotham
* license: MIT
*/
(function (root) {
/**
@dhigginbotham
dhigginbotham / async.js
Last active August 29, 2015 13:55
load script then test with: async.require('//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.10/angular.min.js', function (err, rdy) { if (rdy) console.log(angular) });
/**
* async loader
* author: dhigginbotham
*/
(function(root) {
/**
* public api
*/
@dhigginbotham
dhigginbotham / preload-templates.js
Created January 18, 2014 03:41
Angular.js factory to load preload templates.
app.factory('$preload', ['$templateCache', '$http',
function ($templateCache, $http) {
// angular.js preload template factory, the purpose of this
// is to preload all of your applications templates, once.
// all callbacks should fire with (err, data) node.js style
// flow.
var internalHttpRequest = function (url, fn) {
$http.get(url).success(function (data) {
return fn(data);
});
$args = array(
'post_type' => 'my_custom_post_type',
'meta_key' => 'age',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'age',
'value' => array(3, 4),
'compare' => 'IN',
@dhigginbotham
dhigginbotham / test.js
Last active January 2, 2016 23:18
`npm i express underscore superagent && node test.js`
var express = require('express'),
_ = require('underscore'),
request = require('superagent'),
app = express(),
server = require('http').createServer(app);
app.set('port', 5555);
app.use(express.json());
app.use(express.urlencoded());
app.factory('schemaInitializer', [ '$rootScope', '$resource', function ($rootScope, $resource) {
// service for `schemaInitializer` this will give you a schema
// with access to it's children in a consistent manner, that is easy to use.
var schema = {
title: '',
slug: '',
panels: [],
chartColors: [],
@dhigginbotham
dhigginbotham / emit.js
Last active January 2, 2016 11:09
tiny emitter
(function (root) {
// small event emitter
var emit = function () {
this.events = [];
this.watchers = {};
this.add = function (event, ctx) {
if (typeof ctx == 'undefined') ctx = this;
this.events.push({event: event});
@dhigginbotham
dhigginbotham / xhr.resource.js
Last active January 1, 2016 08:29
tiny xhr wrapper for angular, because I wanted something easier to remember.
app.factory('xhr',
[ '$http', function ($http) {
var xhr = {};
var methods = ['get', 'head', 'post', 'put', 'delete', 'jsonp'];
var internalHttpRequest = function (opts, fn) {
var req = {method: 'get', url: null};
if (opts) angular.extend(req, opts);
$http(req).success(function (data, status, headers, config) {
return fn(null, data);
@dhigginbotham
dhigginbotham / unique.js
Created November 26, 2013 02:33
example of why !~ is a neat trick
var unique = function (arr, fn) {
// callback, so we can async or not (your choice!)
var callback = ((typeof fn != 'undefined') && (typeof fn == 'function')) ? fn : null;
var a = ((typeof arr != 'undefined')) ? arr : null;
var ln = 0;
var newArray = [];
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');