Skip to content

Instantly share code, notes, and snippets.

View jmervine's full-sized avatar

Joshua Mervine jmervine

View GitHub Profile
/*
Author: Joshua P. Mervine <joshua@mervine.net> [github.com/jmervine]
See: http://jsfiddle.net/jmervine/dqA9r/5/
Use:
<script src="http://cdn.mervine.net/FormattedDate.js" />
<script src="http://cdn.mervine.net/FormattedDate.min.js" />
@jmervine
jmervine / 1results.md
Last active August 29, 2015 14:00
Pythagorean Triplet - run time of go vs. java vs. node vs. ruby vs. python vs. perl vs. php vs. c++

Pythagorean Triplet

Note: The method used below is very slow, with 1bb iterations when trying to find 1000. For a faster method see: https://gist.github.com/jmervine/b5d985398b3ca7ba16aa (~125k iterations)


A Pythagorean triplet is a set of three natural numbers, a b c, for which,

a2 + b2 = c2 For example, 32 + 42 = 9 + 16 = 25 = 52.

###
# Usage:
#
# Download this file and start by running 'make'. Then run
# each target listed, 'make lesson_one', 'make lesson_two',
# etc.
#
introduction:
# Introduction:
#############################################################
# Function -- Boot2Docker
#############################################################
if test "$(which boot2docker 2> /dev/null)"; then
function docker_shellinit {
local _shellinit="$(boot2docker shellinit)"
eval "$(echo ${_shellinit})"
echo "${_shellinit}" > ~/.boot2dockerrc
}
@jmervine
jmervine / gist:2052509
Created March 16, 2012 20:37
Ruby: dynamically generated object with accessors
class Item
def initialize item
raise "expected Hash param" unless item.kind_of? Hash
item.each do |key,value|
instance_variable_set(clean_key(key), value)
define_singleton_method(key.to_s) { instance_variable_get( clean_key(key) ) }
define_singleton_method("#{key.to_s}=") { |val| instance_variable_set( clean_key(key), val ) }
end
end
@jmervine
jmervine / gist:2052468
Created March 16, 2012 20:30
Rails: Dynamic Model from JSON sans DB
require 'net/http'
class Item
#replaced with dynamic initialization below
#attr_reader :id, :user, :state
#
#
# Sample JSON
#
# [{ "id":1, "user":"john", "state":"active" },
# { "id":2, "user":"jane", "state":"inactive" },
anonymous
anonymous / file1.txt
Created September 21, 2012 20:55
gistcli - Paste
#! /usr/bin/python
#########################################################################################
# gistcli - version 1.1 #
# written by : pranavk #
#########################################################################################
import urllib2
import sys
@mariusbutuc
mariusbutuc / branch-rename-remote.git
Created September 21, 2012 23:12
Rename remote Git branch
git push origin previous_name:new_name
git branch new_name origin/new_name
# http://stackoverflow.com/a/3790682/341929
" for use before a colorscheme definition
autocmd ColorScheme * highlight ExtraWhitespace ctermbg=red guibg=red
" for use when not using a colorscheme
" highlight ExtraWhitespace ctermbg=red guibg=red
" show unwanted whitespace
match ExtraWhitespace /\s\+\%#\@<!$/
" strip unwanted trailing whitespace on save
@jmervine
jmervine / test_helper.sh
Last active December 19, 2015 03:08
Simple Bash Test Framework
################################################################################
# Simple CLI Testing Psudo-Framework
# > http://mervine.net/simple-cli-testing-framework
#
# Assertions:
# - assert "CMD" "FAIL MESSAGE"
# - refute "CMD" "FAIL MESSAGE"
# - assert_equal "FIRST" "SECOND" "FAIL MESSAGE"
# - refute_equal "FIRST" "SECOND" "FAIL MESSAGE"
# - assert_numeq "FIRST" "SECOND" "FAIL MESSAGE"