Skip to content

Instantly share code, notes, and snippets.

View dannguyen's full-sized avatar
💭
havin a normal one

Dan Nguyen dannguyen

💭
havin a normal one
View GitHub Profile
@dannguyen
dannguyen / screengrabber-fun.rb
Last active August 29, 2015 14:06
A little script that runs OS X screengrab and autosaves the file and provides a markdown path
#!/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}"
@dannguyen
dannguyen / fix-non-military-dates.sql
Created September 28, 2014 21:27
Little date fixing for SQL
update crimes set formatted_date = (STR_TO_DATE(`Date`, '%m/%d/%Y %h:%i:%S %p')) where `Date` IS NOT NULL

Hello this is an image

some image

Hello this is an image

caption text

@dannguyen
dannguyen / homework-grader-bot.rb
Created October 2, 2014 18:18
Prototype homework-grading bot for data-related homework, with grade-inflation countermeasures
# 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'
@dannguyen
dannguyen / corn-stanford-ruby-opencv.sh
Last active August 29, 2015 14:09
How to install rbenv, Ruby 2.1, and the OpenCV gem onto Stanford FarmShare (corn.stanford.edu) without using sudo
# 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
@dannguyen
dannguyen / convert-census-kml-to-csv.rb
Created December 1, 2014 03:10
Convert a KML file from the census and convert it to a CSV using the SimpleData fields
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|
@dannguyen
dannguyen / sayyousayme.txt
Created January 5, 2015 18:14
Lionel Richie lyrics, Say You Say Me
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
@dannguyen
dannguyen / ruby2.0-corn.stanford.md
Created January 10, 2015 02:09
Building Ruby 2.0 on corn.stanford.edu

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
@dannguyen
dannguyen / naive-bayes.rb
Created February 25, 2015 03:42
The Ruby version of "How To Implement Naive Bayes From Scratch in Python" : http://machinelearningmastery.com/naive-bayes-classifier-scratch-python/
# 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