Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Roberto Salas robsalasco

🏠
Working from home
View GitHub Profile
View hashes.rb
require 'csv'
require 'pry'
file = 'lackp_starting_rosters.csv'
# Create an empty teams hash
teams = {}
# Open up the CSV and save it to the variable csv
csv = CSV.open(file, headers: true)
View server.rb
require "sinatra"
require "csv"
require "shotgun"
before do
@players = []
CSV.foreach('lackp_starting_rosters.csv', headers: true, header_converters: :symbol) do |row|
@players << {
name: row[0] + ' ' + row[1], position: row[2], team_name: row[3]
}
View file_organizer.rb
#!/usr/bin/env ruby
#
# file_organizer.rb
# (http://gist.github.com/16180)
#
# By M@ McCray -- www.mattmccray.com (matt at elucidata dot net)
#
# Usage:
#
# organize_files_within( target_folder )
View foia.rb
# convert PDF to jpg
# use sips if available, ImageMagick(`convert`) with ghostscript otherwise
# convert -quality 90 /Users/trek/Desktop/postcard.pdf /Users/trek/Desktop/postcard.png
#
# postful image should be
#
# 6.25"x4.5" (450x324)
# 0.125" trim
# 300dpi
# 1875x1350
We couldn’t find that file to show.
View example_feed.rb
require 'rubygems'
require 'feedzirra'
# gem install feedzirra
url = "http://sunlightlabs.com/blog/feeds/tag/datacatalog/"
feed = Feedzirra::Feed.fetch_and_parse(url)
puts feed.title
puts feed.url
puts feed.feed_url
@winston
winston / example_controller.rb
Created Apr 4, 2010
GoogleVisualr::PieChart Creation Example
View example_controller.rb
# http://code.google.com/apis/visualization/documentation/gallery/piechart.html#Example
def pie_chart
@chart = GoogleVisualr::PieChart.new
@chart.add_column('string', 'Task')
@chart.add_column('number', 'Hours per Day')
@chart.add_rows(5)
@chart.set_value(0, 0, 'Work' )
@chart.set_value(0, 1, 11 )
@chart.set_value(1, 0, 'Eat' )
@robhurring
robhurring / plugin_loader.rb
Created May 18, 2010
Simple way to load Rails plugins in Sinatra
View plugin_loader.rb
# Simple bootloader for Rails plugins in Sinatra
# This checkes the +plugin_folder+ for plugin-like bundles. For each folder it finds it will do:
# If the +lib+ folder exists: add it to our load path
# If a +init.rb+ file exists: require it
# Not very robust but it is lightweight for loading simple rails plugins
class PluginLoader
attr_reader :plugin_folder
def initialize(plugin_folder)
@plugin_folder = plugin_folder
View Custom Feedzirra Flickr parser
module Feedzirra
module Parser
class FlickrEntry
include SAXMachine
include FeedEntryUtilities
element :guid, :as => :id
element :link, :as => :url
View google_face_search.rb
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
$KCODE = 'UTF8'
require 'rubygems'
require 'google-search'
query = ARGV[0] || "paris hilton"
HTML = File.dirname(__FILE__) + '/face.html'
open(HTML, 'w') do |file|