Skip to content

Instantly share code, notes, and snippets.

commit_time ()
{
local repo=`git rev-parse --git-dir 2>/dev/null`
if [ -n "$repo" ]; then
local last=`git log --pretty=format:'%at' -1`
local now=`date +%s`
local m_since=0
((m_since=($now - $last) / 60))
@nwjsmith
nwjsmith / middleware.rb
Created September 8, 2011 13:55 — forked from skippy/middleware.rb
delete vagrant vm's chef client and node from chef server on destroy
class OnDestroyMiddleware
def initialize(app, env)
@app = app
end
def call(env)
env["config"].vm.provisioners.each do |provisioner|
env.ui.info "Attempting to remove client #{provisioner.config.node_name}"
`knife client show #{provisioner.config.node_name}`
if $?.to_i == 0
@nwjsmith
nwjsmith / daves_solution.rb
Created September 1, 2011 14:54
Dave's solution
[1,1,1,1,2,2,2,1,1,1,3,3,3].inject([]) {|on_boundary_array,x|
if on_boundary_array == [] || on_boundary_array[-1][0] != x
on_boundary_array = on_boundary_array + [[x]]
else
on_boundary_array[-1] << x
end
on_boundary_array
}
describe '#chunk' do
def chunk(arr)
arr.inject([]) do |chunks, elem|
current_sequence = chunks.last || []
if elem == current_sequence.last
current_sequence << elem
else
chunks << [elem]
end
chunks
#!/bin/sh
set -e
last_commit_time="$(git log --pretty=format:'%at' -1)"
current_time="$(date +%s)"
((minutes_since_last_commit=($current_time - $last_commit_time) / 60))
# Color Green/Yellow/Red depending on the amount of time since the last commit
pyths :: Int -> [(Int, Int, Int)]
pyths n = [(x, y, z) | x <- [1..n], y <- [1..n], z <- [1..n], arePyths x y z]
where arePyths x y z = x ^ 2 + y ^ 2 == z ^ 2
require 'nokogiri'
require 'yaml'
kml_path = File.join(File.dirname(__FILE__), 'FloodLine_x5.kml')
File.open(kml_path) do |f|
kml = Nokogiri::XML(f)
kml.xpath('//ns:MultiGeometry', {'ns' => "http://www.opengis.net/kml/2.2"}).each do |polygon|
escaped_geometry = con.escape_string(polygon.to_s)
con.exec "INSERT INTO flood_zones VALUES( ST_GEOMFROMKML('#{escaped_geometry}') )"
vim_plugin_task "gundo", "git://github.com/sjl/gundo.vim.git"
require 'spec_helper'
require 'stringio'
describe BloomFilter, '#collision?' do
subject { object.collision?(word) }
let(:dictionary) { Dictionary.new }
let(:object) { described_class.new(dictionary) }
context 'checked with a filtered word' do
- form_for interviewer do |f|
= f.error_messages
= f.label :name, "What is their name?"
= f.text_field :name
#languages
= f.label :languages, "What languages do they speak?"
- f.fields_for :speaks_language do |language_fields|