Skip to content

Instantly share code, notes, and snippets.

View jeffchao's full-sized avatar
:shipit:

Jeff Chao jeffchao

:shipit:
View GitHub Profile
@jeffchao
jeffchao / mappable.rb
Last active February 2, 2020 04:05
Implementation of Enumerable.map() in Ruby
# Run using rspec.
# e.g.: rspec file_name.rb
require 'rubygems'
require 'rspec'
module Enumerable
def mymap (&block)
return nil if block.nil?
@jeffchao
jeffchao / mappable.spec.js
Created March 28, 2013 23:58
Implementation of Array.prototype.map() in Javascript
// Run using jasmine-node.
// e.g.: jasmine-node file_name.spec.js
Array.prototype.mymap = function (callback) {
var obj = Object(this);
if (obj.length === 0) return null;
if (typeof(callback) === 'undefined') return null;
for (var i = 0, o; o = obj[i]; i++) {
@jeffchao
jeffchao / injectable.rb
Created March 29, 2013 06:19
Basic implementation of Enumerable.inject() in Ruby
require 'rubygems'
require 'rspec'
module Enumerable
def myinject (base = nil, &block)
return nil if block.nil?
return nil if self.length.zero?
if base.nil?
case self.first
@jeffchao
jeffchao / injectable.spec.js
Created March 29, 2013 06:58
Basic implementation of Array.prototype.inject() in Ruby-like method in Javascript
Array.prototype.myinject = function () {
var obj = Object(this);
var base;
var callback;
if (arguments.length === 2) {
base = arguments[0];
callback = arguments[1];
} else if (arguments.length === 1) {
callback = arguments[0];
@jeffchao
jeffchao / fix-deploy
Created May 21, 2013 22:31
Deploying octopress to github pages but then it says "Everything up-to-date"
rm -rf _deploy
mkdir _deploy
cd _deploy
git init
git remote add origin git@github.com:username/username.github.io.git
git pull origin master
cd ..
bundle exec rake deploy
@jeffchao
jeffchao / git-branch-checkout
Created May 23, 2013 17:16
Checking out an existing git branch and not getting a "merge commit" when pulling.
# Get a list of existing remote branches
git fetch origin
# Checkout the branch from that branch
git checkout -b branch_name origin/branch_name
git pull origin branch_name
git push origin branch_name # yields 'Everything up-to-date'
@jeffchao
jeffchao / show-git-branch
Last active May 27, 2023 09:26
Show git branches ordered by latest commit. Also by name and date.
# By commit hash
git for-each-ref --sort=-committerdate refs/heads/
# By name, date.
git for-each-ref --sort=-committerdate refs/heads/ --format='%(committerdate:short) %(authorname) %(refname:short)'
@jeffchao
jeffchao / revert
Created October 11, 2013 08:06
Revert git head back to last known specific commit. Typically useful on bad merges.
// Reset the index to the desired tree.
git reset <specific sha>
// Move the branch pointer back to the previous HEAD.
git reset --soft HEAD@{1}
git commit
git push origin master
@jeffchao
jeffchao / nginx.conf
Last active August 29, 2015 13:57
nginx + node + ssl config
upstream foo_backend {
server 127.0.0.1:8080;
}
server {
listen 443 ssl;
ssl_certificate /etc/nginx/ssl/foo.com.bundle.crt;
ssl_certificate_key /etc/nginx/ssl/foo.com.key;
ssl_ciphers RC4:HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
@jeffchao
jeffchao / clustering_columns
Created April 8, 2014 01:02
Cassandra ordering cluster columns
CREATE TABLE employees (company varchar, name varchar, age int, role varchar, primary key (company, name, age)) with clustering order by (name desc, age asc);