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
## Coding 1-2-3
# This tutorial assumes you're using Ruby 1.8+
#
# http://rubyonrails.org/download
#
# Pick up a free text-editor like SciTE for Windows or
# TextWrangler for Mac
# Windows: http://bit.ly/SciTE
# Mac: http://bit.ly/textwrangler
#
class String
def xml_tag_getter(some_tag_word)
self.scan(/<#{some_tag_word}\>(.+?)<\/#{some_tag_word}>/).map{|p| p[0] if p}
end
end
@dannguyen
dannguyen / 01-get-wjchat-from-api.rb
Created March 3, 2011 15:46
Getting wjchat Tweets with API #
## Scrape wjchat using Twitter API
# API Twitter [Docs here](http://dev.twitter.com/doc/get/search):
# by @dancow, News App Developer at ProPublica
# Updated Mar. 2, 2011
##
# This tutorial uses basic scripting commands but doesn't take the time
# to explain them. A more explanatory tutorial can be found here:
#
# http://code-dancow.s3.amazonaws.com/beginners.html
#
@dannguyen
dannguyen / gist:876820
Created March 18, 2011 20:55
Excerpt of homepage source code for AP.org
<style type="text/css">
#p7s1content1 {
position: absolute;
width: 1548px;
z-index: 99;
left: -182px;
top: 2064px;
visibility: visible;
height: 203px;
@dannguyen
dannguyen / Studio20-Lesson1.rb
Created March 27, 2011 15:40
01-Studio-20 - lesson
#####
## The following lines load the files we need, and also
## makes sure everything is in place
['../results', '../html'].each do |dir|
raise "#{dir} does not exist as expected" if !File.exists?(dir)
end
require 'rubygems'
require 'rest-client'
@dannguyen
dannguyen / use_iconv_to_convert_to_ascii.rb
Created May 10, 2011 19:24
Ruby 1.8.7 iconv, I always forget this
require 'iconv'
class String
def to_ascii
Iconv.iconv('ascii//ignore//translit', 'utf-8', self).to_s
end
end
@dannguyen
dannguyen / hstrip.rb
Created February 4, 2012 13:47
Just strip damn whitespace from html
class String
def hstrip
self.gsub(/(?:\s|&nbsp;|\u00A0)+/, ' ').strip
end
end
@dannguyen
dannguyen / temper.rb
Created February 13, 2012 22:16 — forked from ashaw/temper.rb
# server
require 'rubygems'
require 'sinatra'
get '/temp' do
content_type :json
temp = `./temper`
bits = temp.split(' ')
"{ \"time\" : #{bits[0]}, \"fahrenheit\" : #{bits[2].gsub(/F/,'')}, \"celsius\" : #{bits[3].gsub(/C/,'')} }"
jQuery.getJSON('http://graph.facebook.com/Facebook',
function(data){
console.log("Success!");
console.log(data['id']);
});
@dannguyen
dannguyen / lightbulbtoggle-for-brupm.rb
Created June 11, 2012 15:39
My off-the-top-of-my-head solution to Bruno Miranda's light bulb switching puzzle
# http://blog.brunomiranda.com/post/5660219139/100-light-bulbs-brain-teaser
arr = Array.new(100, true)
(2..100).each do |d|
arr.each_with_index{ |a, i| arr[i] = !a if (i + 1) % d == 0 }
end
puts arr.each_with_index.map{|a, i| i + 1 if a }.compact.join(", ")