Skip to content

Instantly share code, notes, and snippets.

View stevenschobert's full-sized avatar

Steven Schobert stevenschobert

View GitHub Profile
@stevenschobert
stevenschobert / templar.coffee
Created December 3, 2012 22:33
Quick 'n Easy template parser in CoffeeScript
# ------------------------------------------------------
# Really simple template parser in CoffeeScript.
# Matches {{keyword}} syntax.
# Input: string, object
# Output: string
#
# Ex: templar("Hello {{planet}}!", {planet: "World"});
# -> outputs "Hello World!"
# ------------------------------------------------------
templar = (input, data) ->
@stevenschobert
stevenschobert / onAir.js
Last active December 13, 2015 19:28
Run a podcast? Here's a little JavaScript function to test if your show is currently "On the Air".
/**
* onAir.js
*
* @param {string} day [the day your show airs (eg. "Tuesday")]
* @param {string} start [start time of the show in 24hr format (eg. "13:00")]
* @param {string} end [stop time of the show in 24hr format (eg. "14:30")]
* @param {string} timezone [the UTC time zone of your show (eg. "-6" for Central Time)]
* @return {bool}
*/
var onAir = function (day, start, end, timezone) {
@stevenschobert
stevenschobert / plainModule.js
Last active December 25, 2015 19:09
Pattern for exporting a plain JS module (when not using AMD/CommonJS). Pulled from O'Reilly's "Programming JavaScript Applications".
// Optional object namespace
var app = {};
(function (exports) {
(function (exports) {
// module exports
exports.moduleName = {
@stevenschobert
stevenschobert / package.sampe.json
Created November 6, 2013 16:23
My starter package.json
{
"name": "http-server",
"version": "0.0.0",
"author": "Steven Schobert <spschobert@gmail.com>",
"description": "let there be javascripts",
"scripts": {
"start": "node ./bin/http-server",
"test": "vows --spec --isolate",
"predeploy": "echo This will be run before deploying the app",
"postdeploy": "echo This will be run after deploying the app"
@stevenschobert
stevenschobert / search_and_kill_node.sh
Last active December 28, 2015 03:09
How to find and kill a node process hogging a port.
# grep for process
ps -ax | grep node
# find the process id and kill it
kill -9 PROCESS_ID
@stevenschobert
stevenschobert / runtest.sh
Created November 22, 2013 21:34
run specific ruby test
bundle exec turn -I "lib:test" test/unit/user_test.rb -n "sort by current streak"
@stevenschobert
stevenschobert / eventEmitterJquery.js
Created December 16, 2013 22:38
If you ever need to whip up a quick event emitter, and you already have jQuery, you can piggyback off jQuery's events:
// event emitter factory built off jQuery events
eventEmitter = function eventEmitter () {
var pipe = $({}),
api = {
trigger: function trigger (event, data) {
pipe.trigger({
type: event,
customData: data
});
},
function isPortrait() {
return Math.abs(window.orientation) / 90 !== 1);
}
// note: if you don't need IE8 support, you can just do
// return image.tags.indexOf('TAGNAME') !== -1;
filter: function(image) {
var foundTag = false, tags = image.tags;
for(var i=0,len=tags.length; i<len && !foundTag; i++) {
if (tags[i] === 'THE_TAG_NAME') foundTag = true;
};
return foundTag;
@stevenschobert
stevenschobert / fix_vim_ruby.sh
Created February 17, 2014 16:42
thing to run when vim isn't using the right ruby (rbenv + zsh)
sudo chmod ugo-x /usr/libexec/path_helper