Skip to content

Instantly share code, notes, and snippets.

View kristjan's full-sized avatar

Kristján Pétursson kristjan

View GitHub Profile
$ ruby proctest.rb
1
proctest.rb:2:in `block in <main>': wrong number of arguments (2 for 1) (ArgumentError)
from proctest.rb:5:in `call'
from proctest.rb:5:in `<main>'
# Data looks like:
# {
# #"old": new,
# "7583": 201343,
# "7614": 280397,
# "8381": 285146,
# "9197": 285727,
# "9356": 220591,
# }
79271
104677
107019
174413
201911
198794
209420
208774
62819
181205
#!/usr/bin/env ruby
# $ ./reverse_vowels.rb 'lalelilolul'
# lulolilelal
# $ ./reverse_vowels.rb 'lalelilolu'
# lulolilela
VOWELS = 'aeiouy'
string = ARGV[0]
@kristjan
kristjan / .ssh_config
Created May 30, 2013 01:25
A clever way to copy from a remote vim session to your local system clipboard
Host my.remote.host
RemoteForward 12888 localhost:12888
vnoremap <Leader>y :yank:call system('nsend ', @0)<CR>
@a = true
@b = false
def one_way
@a and @b ? 'surprise!' : 'expected'
end
def the_other_way
@b and @a ? 'surprise!' : 'expected'
end
@kristjan
kristjan / https
Created January 7, 2013 18:43
Simple wrapper to use HTTPS more natively with https://github.com/jkbr/httpie
#!/usr/bin/env ruby
PROTOCOL = %r{[\w-]+://?}
URL = %r{^((#{PROTOCOL}|\w+[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))$}
args = ARGV.to_a
args.each_with_index do |arg, i|
args[i] = "https://#{arg}" if arg =~ URL && arg !~ PROTOCOL
end
@kristjan
kristjan / loadenv.sh
Created October 15, 2012 22:38
Load a .env file into your current shell. Handy when you need to skirt Foreman.
function loadenv() {
env=${1:-.env}
echo Loading $env
file=`mktemp -t tmp`
if [ -f $env ]; then
cat $env | while read line; do
echo export $line >> $file
done
source $file
else
@kristjan
kristjan / singly_photo_upload.rb
Created September 19, 2012 22:42
Uploading a Photo to Singly
require 'rubygems'
require 'rest_client'
TOKEN = ENV['TOKEN']
PHOTO_ENDPOINT = 'https://api.singly.com/types/photos'
PHOTO_PATH = ARGV[0]
puts "Uploading #{PHOTO_PATH}"
puts RestClient.post(PHOTO_ENDPOINT, {