Skip to content

Instantly share code, notes, and snippets.

@ryangreenberg
ryangreenberg / gist:2990246
Created June 25, 2012 18:03
Emails about finding bike on Criagslist
@ryangreenberg
ryangreenberg / git-sts
Created August 17, 2012 17:24
git sts
#!/usr/bin/env ruby -KU
space_shuttle = <<EOS
_
,' '.
/ \\
^ | _ | ^
| || / \\ || |
| |||.-.||| |
| ||| ||| |
@ryangreenberg
ryangreenberg / gist:3692694
Created September 10, 2012 18:19
Order git branch by last commit to branch
alias branches='for k in `git branch|sed s/^..//`;do echo -e `git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" "$k"`\\t"$k";done|sort'
@ryangreenberg
ryangreenberg / scrape.js
Created September 11, 2012 18:43
Scraper Helper
(function($){
if (typeof $ === 'undefined') {
alert('jQuery is required');
return;
}
var highlightClass = 'scraper-helper-highlight';
$('#scraper-helper-rule').remove();
var style = '<style id="scraper-helper-rule">.' + highlightClass + ' { background-color: #fcc; }</script>';
$(style).appendTo('head');
@ryangreenberg
ryangreenberg / ruby_checkstyle.md
Created December 12, 2012 17:09
Things I would want from a Ruby checkstyle program

If had a Ruby linter or Ruby checkstyle program, I would want to configure it to detect the following things:

  • Duplicate methods in the same class, module (this produces a warning at runtime if warnings are enabled)
  • Parens in methods with no arguments
  • Missing parens in methods with arguments (or check that there aren't parens, if you're into that)
  • Method indentation is consistent
  • Consistent block spacing (.map{|ea| ea} vs. .map {|ea| ea} vs. .map { |ea| ea }, etc.)
  • private, protected are consistently indented (or outdented)
  • do...end blocks must be used beyond a certain line length
  • No semi-colons (possible exceptions for one-line exception classes)
class Rut(id: String, checksumDigit: String) {
def checksum: String = {
val digits = id.map(_.toString.toInt)
val digitsWithMultipliers = digits.zip(
Rut.ChecksumMultipliers.drop(Rut.ChecksumMultipliers.size - digits.size)
)
val productSum = digitsWithMultipliers.foldLeft(0)(
(acc, multipliers) => acc + multipliers._1 * multipliers._2
)
#!/usr/bin/env ruby -KU -rubygems
require 'sinatra'
get '/:time' do
sleep params[:time].to_i
"Just slept for #{sleep_time} seconds"
end
@ryangreenberg
ryangreenberg / 1_README.md
Created April 21, 2013 17:56
Potentiometer video control

This is code used to control the playback speed of a video playing in Quicktime Player. Upload arduino_read_potentiometer.cpp on your Arduino and run processing_control_video.pde in Processing. See video demo at http://www.youtube.com/watch?v=UfDRINiV4Kg

@ryangreenberg
ryangreenberg / 1_percent_z_parse_examples.rb
Last active December 26, 2015 04:19
Ruby's strptime %z parses things that I didn't expect it to. Equivalent examples from other languages welcome.
#!/usr/bin/env ruby -wKU
require 'date'
# strptime %z parses all of the following in Ruby
iso_8601_timezones = %[
Z
UTC
PST
@ryangreenberg
ryangreenberg / jank_repl
Last active January 3, 2016 04:49
Jank REPL
#!/bin/bash
INPUT_FILE=input
OUTPUT_FILE=output
LAST_RUN=$(date "+%s")
LAST_MODIFIED=$LAST_RUN
touch $INPUT_FILE
touch $OUTPUT_FILE