Skip to content

Instantly share code, notes, and snippets.

View davidh-raybeam's full-sized avatar

David Hollis davidh-raybeam

View GitHub Profile
<%= <<WAT
<%= whatever %>
WAT %>
@davidh-raybeam
davidh-raybeam / markup-problem.md
Created May 28, 2013 18:10
The problem with tabular data and markup languages

Part of the problem is that markup languages are inherently 1-dimensional (and the ones that aren't suck to actually write in), whereas tablular data is often 2+-dimensional. This problem is compounded if you want to represent anything that isn't strictly a plain m by n table (e.g., something with additional formatting or cells with non-1 column or row spans).

Frankly, I think the best way to make tables is to have a GUI that generates some machine-readable markup for the table (or even just an image of it). I'd like for there to be something like Grid that does this.

@davidh-raybeam
davidh-raybeam / avg_timespan.sql
Last active December 25, 2015 05:19
avg_timespan.sql is a Vertica SQL statement which will, given a table like the one in setup.sql, calculate the mean amount of time a user spends on our website before completing a purchase, plus its standard deviation. Note that very little effort has been made to optimize this operation.
SELECT
AVG(session_length) as mean_session_length,
STDDEV(session_length_seconds) as session_length_stddev
FROM (
SELECT
event_name,
MAX(action_timestamp) OVER(PARTITION BY user_hostname, pattern_id)
- MIN(action_timestamp) OVER(PARTITION BY user_hostname, pattern_id)
as session_length,
datediff('second',
@davidh-raybeam
davidh-raybeam / bar.rb
Created December 6, 2013 16:59
bar usage: bar foo
#! /usr/bin/env ruby
bar_char = '-'
lead_count = 5
cols = `tput cols`.strip.to_i
max_len = [cols - ((2 * lead_count) + 4), 0].max
bar_color = `tput setaf 3`
reset = `tput sgr0`
title = ARGV.join ' '
@davidh-raybeam
davidh-raybeam / tputcolors.sh
Created December 6, 2013 17:02
Shamelessly copied from somewhere on the Internet. Please comment if you know the actual source, and I'll update this.
#!/bin/bash
# tputcolors
echo
echo -e "$(tput bold) reg bld und tput-command-colors$(tput sgr0)"
for i in $(seq 1 7); do
echo " $(tput setaf $i)Text$(tput sgr0) $(tput bold)$(tput setaf $i)Text$(tput sgr0) $(tput sgr 0 1)$(tput setaf $i)Text$(tput sgr0) \$(tput setaf $i)"
done
@davidh-raybeam
davidh-raybeam / ohshit.rb
Created April 24, 2014 21:47
Makes something interruptible, but not otherwise killable.
begin
code_that_could_break
rescue SignalException => se
raise se
rescue Exception => e
puts e
end
"foo\uFFFF".each_char.to_a.collect(&:ord).reject { |x| x > 65000 }.collect(&:chr).join
# => "foo"
@davidh-raybeam
davidh-raybeam / gitsh
Created August 26, 2014 14:31
Shelly (https://github.com/davidh-raybeam/shelly) script for a git shell with a nice prompt and tab completion for remotes and branches.
#!/usr/bin/env ruby
require 'shelly'
require 'shellwords'
include Shelly
$YELLOW = `tput setaf 3`
$BLUE = `tput setaf 4`
$WHITE = `tput setaf 7`
$RESET = `tput sgr0`
@davidh-raybeam
davidh-raybeam / .bashrc
Created October 13, 2014 18:15
A shell function to quickly initialize empty python packages.
# Creates directories and empty __init__.py files for the given python package in the current directory.
# Usage:
# pypkg a.python.package.name
pypkg () {
local pkgpath="$(echo $1 | sed 's:\.: :g')"
local fspath="."
for el in $pkgpath; do
fspath="${fspath}/${el}"
(mkdir "$fspath" && touch "${fspath}/__init__.py") &>/dev/null
done
module Kernel
def it
(Class.new(BasicObject) {
def method_missing(name, *args)
@calls ||= []
@calls << { name: name, args: args }
self
end
def to_proc
Proc.new do |rcv|