Skip to content

Instantly share code, notes, and snippets.

View jsontocsv.rb
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 Aug 29, 2015
problem 88
View 88.rb
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
View ruby 2.1.5 install
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
View test
#!/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 Aug 29, 2015
Installing Cassandra
View 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 Aug 29, 2015
proposed fabacademy global .hgignore
View .hgignore
syntax: regexp
# files with special characters
[^\w.\-\/ ]+
# banned extensions, still relatively flexible
(?i)^(.+)\.(db|php|php4|php5|swp|log|tmp|\d+)$
@johnrees
johnrees / d2c.js
Created Apr 27, 2015
smartcitizen debug table to curl
View d2c.js
$('table#log_table tr').each(function(index, tr) {
var a = $('td', tr).map(function(index, td) {
return $(td).text();
});
console.log("curl -v -X POST -H 'Host: sc.dev' -H 'User-Agent: SmartCitizen' -H 'X-SmartCitizenMacADDR: " + a[1] + "' -H 'X-SmartCitizenVersion: "+ a[2]+"' -H 'X-SmartCitizenData: [{\"temp\":\""+a[4]+"\",\"hum\":\""+a[5]+"\",\"light\":\""+a[6]+"\",\"bat\":\""+a[7]+"\",\"panel\":\""+a[8]+"\",\"co\":\""+a[9]+"\",\"no2\":\""+a[10]+"\",\"noise\":\""+a[11]+"\",\"nets\":\""+a[12]+"\",\"debug_push\": 1,\"timestamp\":\""+a[13]+"\"}]' sc.dev/add")
});
View gist:3fb05609301e42e0eaa5
## All MPs
https://twitter.com/tweetminster/lists/ukmps
## Parties
https://twitter.com/conservatives
https://twitter.com/cchqpress
https://twitter.com/david_cameron
https://twitter.com/uklabour
https://twitter.com/labourpress
@johnrees
johnrees / wanhaoduplicatori3.json
Created Jul 4, 2015
save in cura/resources/settings
View wanhaoduplicatori3.json
{
"id": "wanhaoduplicatori3",
"name": "Wanhao Duplicator i3",
"platform_texture": "WanhaoDuplicatori3Backplate.png",
"inherits": "ultimaker2.json",
"machine_settings": {
"machine_width": {
"default": 200
},
"machine_depth": {