Skip to content

Instantly share code, notes, and snippets.

@casecode
casecode / typedFunction.js
Last active October 7, 2015 13:18
Typed Functions
function getType(arg) {
return ({}).toString.call(arg).match(/\s([a-zA-Z]+)/)[1].toLowerCase();
}
function typeMatch(arg, type) {
if (typeof arg === 'number' && typeof type === 'number' && isNaN(arg) && isNaN(type)) return true;
if ((typeof arg === 'number' && isNaN(arg)) || (typeof type === 'number' && isNaN(type))) return false;
if (getType(arg) === getType(type)) return true;
if (type instanceof Function && arg.constructor === type) return true;
return false;
@casecode
casecode / 0_reuse_code.js
Last active August 29, 2015 14:25
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
var poll = function (sel, fn, t) {
t = t || 25; // 25ms default
var $el = $(sel), found = $el.length;
// Proper tail calls - return and pass all necessary variables
// i.e. minimize current frame's footprint (allow release / reuse in es6 env)
if (found) return fn.call($el);
else if (document.readyState === 'complete') return;
else return setTimeout(function() {
poll(sel, fn, t);
// JSBin: http://jsbin.com/yugeyeliti/edit?js,console
function assertEqual (test, a, b) {
if (!b) {
b = a;
a = test;
test = null;
}
test = test ? '(' + test + ')' : '';
/*
screening.js test forked from rmurphy via tomfuertes
Answers by casecode
*/
// 1: how could you rewrite the following to make it shorter?
if (foo) {
bar.doSomething(el);
} else {
bar.doSomethingElse(el);
@casecode
casecode / autoresponder.md
Last active September 21, 2015 21:23
Automated Message Responder - Code Snippet

Autoresponder

The SMS Responder below demonstrates how to declare hash properties as methods in Ruby. This can be convenient if you have long if/elsif/else or case statements in your Ruby code. For example:

if x == "a"
  do_something(args)
elsif x == "b"
  do_something_else(args)
# remainder of long if/elsif block
@casecode
casecode / secure-websockets
Last active April 19, 2023 17:50
Basic Config for SSL with Secure Websockets using Nginx 1.6.0 + Puma + Thin
=========================
# /etc/nginx/nginx.conf
=========================
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
@casecode
casecode / ubuntu-ruby-build
Created May 16, 2014 12:02
Install Ruby from Source on Ubuntu 14.04
>> sudo apt-get update
# Install node if you don't already have it
>> sudo apt-get install nodejs
# Install dependencies
>> sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties
# Find the version of ruby you want from the Ruby FTP: ftp://ftp.ruby-lang.org/pub/ruby
# Install ruby to /usr/local/bin (using v 2.1.2)
@casecode
casecode / apache2-passenger-config
Last active August 29, 2015 14:01
Basic Apache2 + Passenger Config
# SSL config file at /etc/apache2/sites-available/default-ssl.config
# After saving the config file, remember to enable the virtual host and restart apache
# sudo a2ensite default-ssl
# sudo service apache2 reload
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin email@your_domain.com
ServerName your_domain.com # localhost:3000, etc., if using SSL in development