Skip to content

Instantly share code, notes, and snippets.

View cpsubrian's full-sized avatar

Brian Link cpsubrian

  • Dropbox
  • Fremont, CA
View GitHub Profile
@cpsubrian
cpsubrian / tokens.js
Created October 23, 2012 23:32
Replace named tokens in a string.
var input = 'Hello, :name.first :name.last! :greeting';
function tokenReplace(str, values) {
return str.replace(/:([\w.]+)/g, function (token, name) {
return name.split('.').reduce(function (value, part) {
return value[part] || null;
}, values) || token;
});
}
@cpsubrian
cpsubrian / gist:4488592
Created January 8, 2013 22:27
SublimeLinter User Settings. Edit by going to menu `SublimeText2 -> Preferences -> Package Settings -> SublimeLinter -> Settings - User`
{
"sublimelinter": "load-save",
// jshint: options for linting JavaScript. See http://www.jshint.com/options/ for more info.
// By deault, eval is allowed.
"jshint_options":
{
// To fix column positions for JSHint errors you may want to add `"indent": 1` to your
// **User** "jshint_options". This issue affects users with tabs for indentation.
// This fix was reverted due to a conflict with using the `"white": true` option.
@cpsubrian
cpsubrian / .pash_profile
Created February 12, 2013 23:31
My Terminal Prompt
# GIT Prompt
parse_git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
WHITE="\[\033[1;37m\]"
GREEN="\[\033[0;32m\]"
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
B_YELLOW="\[\033[1;33m\]"
GREY="\[\033[0;39m\]"
@cpsubrian
cpsubrian / gist:4989424
Last active December 13, 2015 23:09
Function generators.
function addX (x) {
return function (a) {
return a + x;
}
}
var add5 = addX(5);
var add10 = addX(10);
// What is result?
@cpsubrian
cpsubrian / README.md
Last active December 15, 2015 06:19
This would be the title!

Article Content

Using markdown:

  • Use lists
  • etc.
(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\
@cpsubrian
cpsubrian / README.md
Last active December 17, 2015 03:19
Streams instead of ORM.

Streams instead of ORM

Pros:

  • Streams?
  • More manual query control.
  • Combine different transforms depending on use case.

Cons:

// Optional `options. Stuff like retry count, ramp-up, etc.
// should have sane defaults.
var wait = waitforit(options, function (cb) {
// This would be the 'test' function.
// cb(true) when 'it' is done.
});
wait.on('ready', function () {
// Do something because the test condition passed.
@cpsubrian
cpsubrian / user-data.sh
Created May 2, 2014 17:20
AWS User Data for a Node.js Server
#!/bin/bash
USER=ubuntu
HOME=/home/ubuntu
# install pubkeys
mkdir -p $HOME/.ssh
chmod 700 $HOME/.ssh
curl --silent --location [url to an authorized keys file] > $HOME/.ssh/authorized_keys
chmod 600 $HOME/.ssh/authorized_keys
@cpsubrian
cpsubrian / keybase.md
Created May 22, 2014 22:40
keybase.md

Keybase proof

I hereby claim:

  • I am cpsubrian on github.
  • I am cpsubrian (https://keybase.io/cpsubrian) on keybase.
  • I have a public key whose fingerprint is 98C5 3702 B9D9 0B60 46B0 0E8E 4B6E 728A 3FF3 9D1C

To claim this, I am signing this object: