#!/usr/bin/env ruby
SUPPORT = ENV['TM_SUPPORT_PATH']
DIALOG = SUPPORT + '/bin/CocoaDialog.exe'
selected_word = ENV['TM_CURRENT_WORD']
x = "--xpos #{ENV['TM_CARET_XPOS']} "
y = "--ypos #{ENV['TM_CARET_YPOS']} "
if selected_word != nil
menu = []
all_words = STDIN.read.split(/\b/)
all_words.each do |word|
if word != selected_word
if word.index(selected_word) == 0
menu << word + " "
end
end
end
menu.uniq!
if menu.length < 1
abort
elsif menu.length == 1
print menu[0].sub(selected_word, '').strip
else
selected = %x`"#{DIALOG}" menu --items #{menu} #{x} #{y}`.to_i - 1
print menu[selected].sub(selected_word, '').strip
end
end
countries = Country.find(:all)
for country in countries
begin
tzc = TZInfo::Country.get(country.code.upcase)
rescue
puts "can't find TZInfo for #{country.code.upcase}"
next
end
puts tzc.name
for zone in tzc.zone_names
puts country.code.upcase
puts zone
CountryTimeZone.create(:parent_id => country.id, :name => zone)
end
end
#A. Create an array
names = %w[chris sandy josie billy suzie]
#B. Find the length of the array and iterate through it
names.length.times do |i|
puts i.to_s + " " + names[i]
end
module SnipplrAPI
require 'xmlrpc/client'
API_URL = "http://snipplr.com/xml-rpc.php"
class Snipplr
attr_accessor :api_key
def initialize(key)
@api_key = key
@server = XMLRPC::Client::new2(SnipplrAPI::API_URL)
end
def list(tags="", sort="", limit="")
cmd = "snippet.list"
result = @server.call(cmd, @api_key, tags, sort, limit)
end
def get(snippet_id)
cmd = "snippet.get"
result = @server.call(cmd, snippet_id)
end
def post(title,code,tags="",language="")
cmd = "snippet.post"
result = @server.call(cmd, @api_key, title, code, tags, language)
end
def delete(snippet_id)
cmd = "snippet.delete"
result = @server.call(cmd, @api_key, snippet_id)
end
def checkkey(api_key)
cmd = "user.checkkey"
result = @server.call(cmd, api_key)
end
def languages()
cmd = "languages.list"
result = @server.call(cmd)
end
end
end
# =========================================
# Testing: Do not include in class file
# =========================================
require 'pp' #used to Pretty Print results not required to use above module
# Replace YOUR_API_KEY below with your assigned API key
# can be found at snipplr.com at http://snipplr.com/settings/
# at the bottom of the page.
key = "YOUR_API_KEY"
snipplr = SnipplrAPI::Snipplr.new(key)
# list your snippets
pp snippets.list
# list only snippets tagged with php or xml
#pp snipplr.list("PHP")
require 'net/http'
require 'uri'
require "rexml/document"
# Retrieves US Location data based on a passed in Zipcode. Uses
# Google Maps geocoding service to retrieve a Hash of city, state, and zip
# For more info on the service see: http://code.google.com/apis/maps/documentation/geocoding/
#
# example:
# puts get_location_data(97030).inspect
# outputs:
# {:state=>"OR", :zip=>"97030", :city=>"Gresham"}
def get_location_data(zip)
url = "http://maps.google.com/maps/geo"
uri = URI.parse(url)
req = Net::HTTP::Get.new(uri.path + "?output=xml&q=#{zip}")
res = Net::HTTP.start(uri.host, uri.port) do |http|
http.request(req)
end
data = res.body
result = {}
address = ""
doc = REXML::Document.new data
doc.elements.each('//Placemark[1]/address') do |element|
address = element.text
end
if address
parts = address.split(/[,\s*]/)
result[:city] = parts[0]
result[:state] = parts[2]
result[:zip] = parts[3]
end
result
end