Skip to content

Instantly share code, notes, and snippets.

@tvladeck
tvladeck / Git color log
Created June 19, 2012 16:21
Better log for git
It's simple. Just type in:
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --
I guess that's a bit too long, eh? Let's just make an alias. Copy and paste the line below on your terminal:
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"
And every time you need to see your log, just type in
git lg
@tvladeck
tvladeck / fish_prompt
Created June 24, 2012 21:49
My fish_prompt function
function fish_prompt -d "Write out the prompt"
printf '%s' (vcprompt) (set_color $fish_color_cwd) (prompt_pwd) (set_color normal) ' > '
end
@tvladeck
tvladeck / yelp_api.rb
Created July 17, 2012 14:51
Touching the Yelp API
require 'oauth'
require 'json'
consumer_key = 'etdTVJFmBsqOjZITP_MqJQ'
consumer_secret = 'S1DUC0OqdRWrbvuhjVuF5QI3cEY'
token = 'm_fA4dzJ78ppRTrd2otSPFOTEx2Q_J4c'
token_secret = 'hL8scdaQ0gRMLPOj5ZCF7Wg3XvA'
api_host = 'api.yelp.com'
@tvladeck
tvladeck / Presidential Simulation.R
Created October 1, 2012 22:20
Really really informal simulation of the election
library("hash")
# States treated as going democratic with probability 1
DemStates <- hash()
.set(DemStates, "WA"=12, "OR"=7, "CA"=55, "NM"=5,
"MN"=10, "WI"=10, "MI"=16, "IL"=20,
"PA"=20, "MD"=10, "DC"=3, "DE"=3,
"NJ"=14, "CT"=7, "RI"=4, "MA"=11,
"VT"=3,"ME"=4,"HI"=4, "NY"=29)
@tvladeck
tvladeck / theme.html
Created October 1, 2012 22:28 — forked from soemarko/theme.html
embed github gist to tumblr
<!-- Add the following lines to theme's html code right before </head> -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="http://static.tumblr.com/fpifyru/VCxlv9xwi/writecapture.js"></script>
<script src="http://static.tumblr.com/fpifyru/AKFlv9zdu/embedgist.js"></script>
<!--
Usage: just add <div class="gist">[gist URL]</div>
Example: <div class="gist">https://gist.github.com/1395926</div>
-->
@tvladeck
tvladeck / 538Analysis.R
Created November 9, 2012 16:14
Evaluation of 538's performance
library('hash')
states = hash()
.set(states,
"CO" = 0.8, "FL" = 0.5, "IA" = 0.84, "NBC2" = 0.87,
"NH" = 0.85, "NC" = 0.74, "VA" = 0.79, "AZ" = 0.98,
"MNC2" = 0.95, "MI" = 0.99, "MT" = 0.98, "NV" = 0.93,
"NM" = 0.99, "OH" = 0.91, "PA" = 0.99, "WI" = 0.97)
run.simulation <- function()
@tvladeck
tvladeck / viewport.R
Created November 13, 2012 22:00
Viewports in R
library('grid')
pushViewport(viewport(layout = grid.layout(4, 1)))
print(a, vp = viewport(layout.pos.row = 1, layout.pos.col = 1))
print(b, vp = viewport(layout.pos.row = 2, layout.pos.col = 1))
@tvladeck
tvladeck / convert_to_annual.rb
Created November 15, 2012 05:36
converting to annual
irb(main):002:0> def convert_to_annual(ary)
irb(main):003:1> len = ary.length
irb(main):004:1> rem = len % 12
irb(main):005:1> idx = len / 12
irb(main):006:1> ret = idx.times.map { |i| ary[i..(i+11)].reduce(:+) }
irb(main):007:1> ret << ary[(len - rem)..(len)].reduce(:+)
irb(main):008:1> ret
irb(main):009:1> end
filepath = "#{Rails.root.join('tmp')}/new"
File.open(filepath, "wb") do |f|
f.write open(@account.logo.url).read
end
Showing /Users/thomasvladeck/Git/bh_pro/app/views/proposals/_cover_sheet.xlsx.axlsx where line #6 raised:
No such file or directory - /uploads/account/logo/1/me_climbing_mountains.jpg
Extracted source (around line #6):
3
4
5
6
7
8