Skip to content

Instantly share code, notes, and snippets.

source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'
# gem 'authority'
gem 'whenever', require: false
gem 'bitwise'
gem "aws-ses", "~> 0.5.0", :require => 'aws/ses'
gem 'closure_tree'
gem 'kaminari'
@johnrees
johnrees / hack.sh
Last active December 28, 2015 23:48 — forked from linssen/hack.sh
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://gist.github.com/johnrees/7581236/raw/hack.sh | sh
#
@johnrees
johnrees / convert.coffee
Last active January 2, 2016 02:49
Ridiculously simple live currency conversion. I will make it into a jquery plugin soon but for now, if you put the convert.js snippet inside a jquery document ready tag it should just work™.
if $('span[data-currency]').length > 0
$.get '//query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22EURUSD%22%2C%20%22EURGBP%22%2C%20%22EURJPY%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=', (result) ->
$('span[data-currency]').each ->
matches = $(this).data('currency').match(/(\d+) (.+)/)
amount = parseInt(matches[1])
conversion = matches[2]
for conversions in result.query.results.rate
if conversion == conversions.Name
rate = conversions.Rate
return $(this).text Math.floor(amount * rate)
require 'json'
require 'open-uri'
raw_json = open('http://api.smartcitizen.me/v0.0.1/ba997ab4b0e21eda08b3da4a7b60a628/646/posts.json?from_date=2014-02-06&to_date=2014-02-08').read
json = JSON.parse(raw_json)
File.open('posts.csv', 'w') do |file|
# write first line
file.puts json["device"]["posts"][0].keys.join(',')
@johnrees
johnrees / 88.rb
Last active August 29, 2015 14:05
problem 88
min = 2
max = 100
min.upto(max) do |count|
puts "k=#{count}"
a = (1..count).to_a
options = a.repeated_combination(count).to_a
for option in options.reverse
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
rbenv install 2.1.5
rbenv global 2.1.5
ruby -v
/coverage
*.todo
#!/bin/bash
set -e
need_rails=1
if [ $# -gt 0 ]; then # we have args
filename=$1
# remove trailing line number from filename e.g. spec/my_spec.rb:33
grep_filename=`echo $1 | sed 's/:.*$//g'`
@johnrees
johnrees / Installing Cassandra
Last active August 29, 2015 14:14
Installing Cassandra
sudo apt-get update
mkdir -p /usr/local/java
cd /usr/local/java
wget http://www.reucon.com/cdn/java/jdk-7u76-linux-x64.tar.gz
tar xvzf jdk-7u76-linux-x64.tar.gz
vim /etc/profile
JAVA_HOME=/usr/local/java/jdk-7u76-linux-x64
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
JRE_HOME=/usr/local/java/jdk-7u76-linux-x64
PATH=$PATH:$HOME/bin:$JRE_HOME/bin
@johnrees
johnrees / .hgignore
Last active August 29, 2015 14:15
proposed fabacademy global .hgignore
syntax: regexp
# files with special characters
[^\w.\-\/ ]+
# banned extensions, still relatively flexible
(?i)^(.+)\.(db|php|php4|php5|swp|log|tmp|\d+)$