Skip to content

Instantly share code, notes, and snippets.

@durango
durango / functions.php
Created May 6, 2012 14:58
Just showing someone how to convert 1k10 to 1,010.
function money_commands($dep) {
$total = 0;
$dep = str_replace(',', '', $dep);
preg_match_all('#[0-9]{1,}(m|M)#', $dep, $matches);
foreach($matches AS $v) {
foreach($v AS $val) {
$x = str_ireplace('m', '', $val);
$dep = str_replace($val, '', $dep);
$total += $x*1000000;
@durango
durango / proxyServer
Created July 2, 2012 03:36 — forked from randylubin/proxyServer
Node.js Multi-App Proxy Server with Forwarding
var http = require('http'),
httpProxy = require('http-proxy');
//
// Setup proxy server with forwarding
//
var options = {
router: {
'proxytest.randylubin.com': '127.0.0.1:7200',
'randylubin.com': '127.0.0.1:7200',
@durango
durango / advice.js
Created September 15, 2012 04:07 — forked from angus-c/advice.js
an advice functional mixin
//usage
withAdvice.call(targetObject);
//mixin augments target object with around, before and after methods
//method is the base method, advice is the augmenting function
withAdvice: function() {
['before', 'after', 'around'].forEach(function(m) {
this[m] = function(method, advice) {
if (typeof this[method] == 'function') {
return this[method] = fn[m](this[method], advice);
@durango
durango / advice.js
Created September 15, 2012 05:19 — forked from angus-c/advice.js
an advice functional mixin
//usage
withAdvice.call(targetObject);
//mixin augments target object with around, before and after methods
//method is the base method, advice is the augmenting function
withAdvice: function() {
['before', 'after', 'around'].forEach(function(m) {
this[m] = function(method, advice) {
if (typeof this[method] == 'function') {
return this[method] = fn[m](this[method], advice);
var chainer = new Sequelize.Utils.QueryChainer()
Artist.find({ where: {name: name} }).success(function(artist) {
if (artist) {
// get all tracks
artist.getTracks().success(function (tracks) {
if (tracks.length > 0) {
tracks.forEach(function(track) {
chainer.add(track.getArtists())
})
@durango
durango / gist:3752407
Created September 19, 2012 21:31
QueryChainer - adding custom classMethods with complex queries [example]
// This is in classMethods:
a_method: function(id, order_id) {
var query1 = s.Utils.format(['query goes here...']);
var query2 = s.Utils.format(['query goes here....']);
return new s.Utils.CustomEventEmitter(function(emitter) {
db.query(query1, null, {raw:true}).success(function(row1){
db.query(query2, null, {raw:true}).success(function(row2){
emitter.emit('success', {results1: row1, results2: row2});
});
@durango
durango / standards.md
Created November 12, 2012 18:58
Coding Standards for various languages

CODING STANDARDS

This is a list of the various code style guides I've printed out and (try to) abide by. There are endless style guides on the internet, these are just the ones I use wherever possible.


Frontend

@durango
durango / object-watch.js
Created November 22, 2012 18:21 — forked from eligrey/object-watch.js
object.watch polyfill
/*
* object.watch polyfill
*
* 2012-04-03
*
* By Eli Grey, http://eligrey.com
* Public Domain.
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/
@durango
durango / index.html
Created November 27, 2012 04:47 — forked from anotherjavadude/index.html
Most simple d3.js stack bar chart from matrix
<!DOCTYPE html>
<html>
<head>
<title>Simple Stack</title>
<script src="http://d3js.org/d3.v2.js"></script>
<style>
svg {
border: solid 1px #ccc;
font: 10px sans-serif;
shape-rendering: crispEdges;
@durango
durango / snap_lines_to_indent_level_command.py
Created November 27, 2012 10:59 — forked from vitaLee/snap_lines_to_indent_level_command.py
SublimeText command for snapping displaced text to indentation
# sample shortcuts
{ "keys": ["ctrl+super+]"], "command": "snap_lines_to_indent_level", "args": { "snap_direction": 1 } },
{ "keys": ["ctrl+super+["], "command": "snap_lines_to_indent_level", "args": { "snap_direction": -1 } }