This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'pathname' | |
rel_path = Pathname.new( ARGV.shift || './') | |
working_abs_path = Pathname.new(ARGV.shift || './') | |
working_abs_path = working_abs_path.join(rel_path) | |
working_abs_path.mkpath | |
sleep_sec = (ARGV.shift || 2).to_i | |
puts "---------------", "Sleep delay: #{sleep_sec}" | |
puts "Files will be stored in: \t#{working_abs_path}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
update crimes set formatted_date = (STR_TO_DATE(`Date`, '%m/%d/%Y %h:%i:%S %p')) where `Date` IS NOT NULL | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# data-journalism-homework-grading-bot-w-anti-grade-inflation-measures | |
###### PROTOTYPE | |
Dir.glob("*").select{|d| File.directory?d }.each do |dir| | |
`cd #{dir} && git pull` | |
if $?.success? | |
if File.exist?('homework.txt') | |
hw = open('homework.txt').read | |
if hw.length < 10000 | |
puts 'F' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# corn.stanford.edu is stuck at Ruby 1.9.3 | |
# This script gets the newest Ruby and lets you install your own gems without sudo | |
# get rbenv | |
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv | |
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc | |
echo 'eval "$(rbenv init -)"' >> ~/.bashrc | |
# run the updated .bashrc | |
source ~/.bashrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nokogiri' | |
f = './CA counties.kml' | |
xml = open(f){|x| Nokogiri::XML(x.read) } | |
placemarks = xml.search('Placemark') | |
atts = placemarks.first.search('ExtendedData > SchemaData').children.map{|t| t.attr('name') }.compact | |
headers = atts + ['geometry'] | |
require 'csv' | |
CSV.open('./ca-counties.csv', 'w', headers: true) do |csv| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Say you, say me; say it for always | |
That's the way it should be | |
Say you, say me; say it together | |
Naturally | |
I had a dream I had an awesome dream | |
People in the park playing games in the dark | |
And what they played was a masquerade | |
And from behind of walls of doubt a voice was crying out |
Installing rbenv https://github.com/sstephenson/rbenv
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ruby version of http://machinelearningmastery.com/naive-bayes-classifier-scratch-python/ | |
FILENAME="/tmp/pima.csv" | |
require 'csv' | |
data = CSV.open(FILENAME){|csv| csv.readlines.map{|arr| arr.map(&:to_f) } } | |
def split_dataset(dataset, ratio) | |
i = (ratio * dataset.length).to_i | |
copy = dataset.shuffle |