Skip to content

Instantly share code, notes, and snippets.

View carlzulauf's full-sized avatar

Carl Zulauf carlzulauf

  • Unabridged Software
  • Denver, CO
View GitHub Profile
@carlzulauf
carlzulauf / haversine.sql
Created February 2, 2012 16:47
PostgreSQL function for haversine distance calculation, in miles
-- Haversine Formula based geodistance in miles (constant is diameter of Earth in miles)
-- Based on a similar PostgreSQL function found here: https://gist.github.com/831833
-- Updated to use distance formulas found here: http://www.codecodex.com/wiki/Calculate_distance_between_two_points_on_a_globe
CREATE OR REPLACE FUNCTION public.geodistance(alat double precision, alng double precision, blat double precision, blng double precision)
RETURNS double precision AS
$BODY$
SELECT asin(
sqrt(
sin(radians($3-$1)/2)^2 +
sin(radians($4-$2)/2)^2 *
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@carlzulauf
carlzulauf / git-clean-local
Last active May 11, 2022 21:43
git clean-local
#!/usr/bin/env ruby
# git clean-local
# ---------------
# Clean out your local branches. Defaults to branches you haven't touched in 30+ days.
#
# More info: git clean-local -h
#
# Asks for confirmation by default, so safe to run with no options.
@carlzulauf
carlzulauf / git-pushu
Created May 11, 2022 21:39
git pushu
#!/usr/bin/env ruby
# git pushu
# ---------
#
# Push upstream every time
#
# * If the current branch tracks a remote, push to it.
#
# * If there is no tracking branch, point to a branch of the same name,
@carlzulauf
carlzulauf / git-pullf
Created May 11, 2022 21:38
git pullf
#!/usr/bin/env ruby
# git pullf
# ---------
# Force pull without needing to be verbose
current = `git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)`
remote, remote_branch = current.strip.split("/", 2)
branch = `git branch | grep \\* | cut -d ' ' -f2`
@carlzulauf
carlzulauf / console_saver.rb
Created March 22, 2022 19:59
A pry session that remembers
#!/usr/bin/env ruby
# Console script with saved data serialized into script body at bottom
#
# `Console#db` is serialized via YAML whenever the `save` method is called
# * YAML is placed after special `__END__` keyword
# * Script can access data after `__END__` via `DATA` constant
# Useful as a skeleton for one-off console scripts needing limited data storage
@carlzulauf
carlzulauf / redis.conf
Created November 16, 2011 00:45
redis config file for development environment
# Redis configuration file example
# Note on units: when memory size is needed, it is possible to specifiy
# it in the usual form of 1k 5GB 4M and so forth:
#
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
@carlzulauf
carlzulauf / Rakefile
Created October 5, 2011 17:44
Rake task to install dot files into home directory as symlinks
require 'rake'
desc "Install dot files as symbolic links"
task :install do
dots = File.join(Dir.getwd, "home")
home = Dir.home
backup = File.join(home, ".backup-dotfiles")
Dir.mkdir(backup) unless File.directory?(backup)
files = Dir.entries(dots) - [".", ".."]
files.each do |file|
@carlzulauf
carlzulauf / watch.rb
Created November 14, 2013 08:29
Watch the price of Bitcoin on Coinbase, and alert me.
require 'logger'
require 'net/http'
require 'json'
require 'mail' # gem 'mail'
dir = File.dirname(__FILE__)
logger = Logger.new(STDOUT)
logger.level = Logger::INFO

Keybase proof

I hereby claim:

  • I am carlzulauf on github.
  • I am carlzulauf (https://keybase.io/carlzulauf) on keybase.
  • I have a public key ASBdd9PaBV4nzitPvyoXMfFKb4jFJ-5w8xzBV81Qc-LDywo

To claim this, I am signing this object: