Skip to content

Instantly share code, notes, and snippets.

select * from information_schema.tables where table_schema='public' and table_type='BASE TABLE';
# helper method to paginate a non ActiveRecord collection like a Array
def paginate_collection(collection, opts = {})
opts[:per_page] ||= 20
opts[:page] ||= 1
opts[:page] = opts[:page].to_i
opts[:per_page] = opts[:per_page].to_i
returning WillPaginate::Collection.new( opts[:page], opts[:per_page], collection.size ) do |pager|
start = (opts[:page]-1) * opts[:per_page]
finish = start + opts[:per_page]
pager.replace collection[ start...finish ]
def disable_geocoding
GeoKit::Geocoders::Geocoder.instance_eval do
def geocode(a)
res = GeoKit::GeoLoc.new
res.lat = 13.423007
res.lng = 52.534194
res.success = true
res
end
end
@electronicbites
electronicbites / gist:60738
Created February 9, 2009 10:35
get the duration of a youtube video
require 'rubygems'
require 'hpricot'
require 'net/http'
HOST = "gdata.youtube.com"
SITE = "/feeds/api"
def parse_duration(xml)
result = 0
(xml/'entry').each do |entry|
@electronicbites
electronicbites / gist:60747
Created February 9, 2009 11:13
gets the tags of a youtube video
require 'rubygems'
require 'hpricot'
require 'net/http'
HOST = "gdata.youtube.com"
SITE = "/feeds/api"
def tags(youtubeid)
request = Net::HTTP::Get.new("#{SITE}/videos?q=#{youtubeid}&safeSearch=none")
request.add_field 'GData-Version', '2'
require 'rubygems'
require 'hpricot'
require 'net/http'
HOST = "gdata.youtube.com"
SITE = "/feeds/api"
def upload_time(youtubeid)
request = Net::HTTP::Get.new("#{SITE}/videos?q=#{youtubeid}&safeSearch=none")
request.add_field 'GData-Version', '2'
@electronicbites
electronicbites / gist:77803
Created March 11, 2009 22:48
get similar artists from the last.fm api
#http://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&artist=cher&api_key=b25b959554ed76058ac220b7b2e0a026
require 'rubygems'
require 'hpricot'
require 'net/http'
HOST = "ws.audioscrobbler.com"
SITE = "/2.0"
def get_similar_artists(artist)
We couldn’t find that file to show.
@electronicbites
electronicbites / scan_unused_files.rb
Created September 15, 2010 15:29
scan unused images and globals in a xcode project
#!/usr/bin/env ruby
#TODO
# find all files not in project file
# => list these files
globalsfile = "Classes/Globals.h"
allfiles = `git ls-files`.split(/\n/)
#allfiles.each{|f| f.gsub!(/\"/, "")} #not needed when files have no unicode chars inf filenames
@electronicbites
electronicbites / change href dynamic
Created September 23, 2010 13:58
change href dynamic
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>test_change_link</title>
<script type="text/javascript" language="javascript">
// <![CDATA[