Skip to content

Instantly share code, notes, and snippets.

@flakyfilibuster
flakyfilibuster / switcharoo_test.rb
Created October 25, 2012 03:12
switcharoo_test
# run with: ruby switcharoo_test.rb
require 'minitest/autorun'
def switcharoo(string, switch_point, delimiter=false)
if switch_point < 0
raise "switch_point too small"
elsif switch_point > string.size
raise "switch_point too big"
end
class Hospital
attr_reader :name, :location, :employees, :patients, :admins
def initialize(name, location)
@name, @location, @employees, @patients, @admins = name, location, [], [], []
end
end
@flakyfilibuster
flakyfilibuster / image_converter.rb
Created October 26, 2012 07:05
image_converter & caption!
require 'RMagick'
include Magick
def image_reformatting(input_image)
img = Magick::Image.read(input_image)[0]
img.format = "png"
img.write("format.png")
text = Draw.new
@flakyfilibuster
flakyfilibuster / Add_support_for_multiple_users.xml
Created October 29, 2012 06:41
Solution for One To Many Schema Design
<?xml version="1.0" encoding="utf-8" ?>
<!-- SQL XML created by WWW SQL Designer, http://code.google.com/p/wwwsqldesigner/ -->
<!-- Active URL: http://socrates.devbootcamp.com/sql.html -->
<sql>
<datatypes db="mysql">
<group label="Numeric" color="rgb(238,238,170)">
<type label="Integer" length="0" sql="INTEGER" re="INT" quote=""/>
<type label="Decimal" length="1" sql="DECIMAL" re="DEC" quote=""/>
<type label="Single precision" length="0" sql="FLOAT" quote=""/>
<type label="Double precision" length="0" sql="DOUBLE" re="DOUBLE" quote=""/>
@flakyfilibuster
flakyfilibuster / todos.xml
Created October 29, 2012 06:47
Solution for Todo Schema Design
<?xml version="1.0" encoding="utf-8" ?>
<!-- SQL XML created by WWW SQL Designer, http://code.google.com/p/wwwsqldesigner/ -->
<!-- Active URL: http://socrates.devbootcamp.com/sql.html -->
<sql>
<datatypes db="mysql">
<group label="Numeric" color="rgb(238,238,170)">
<type label="Integer" length="0" sql="INTEGER" re="INT" quote=""/>
<type label="Decimal" length="1" sql="DECIMAL" re="DEC" quote=""/>
<type label="Single precision" length="0" sql="FLOAT" quote=""/>
<type label="Double precision" length="0" sql="DOUBLE" re="DOUBLE" quote=""/>
@flakyfilibuster
flakyfilibuster / one_to_one_schema_design.xml
Created November 1, 2012 03:56
Solution for One to One Schema Design
<?xml version="1.0" encoding="utf-8" ?>
<!-- SQL XML created by WWW SQL Designer, http://code.google.com/p/wwwsqldesigner/ -->
<!-- Active URL: http://socrates.devbootcamp.com/sql.html -->
<sql>
<datatypes db="mysql">
<group label="Numeric" color="rgb(238,238,170)">
<type label="Integer" length="0" sql="INTEGER" re="INT" quote=""/>
<type label="Decimal" length="1" sql="DECIMAL" re="DEC" quote=""/>
<type label="Single precision" length="0" sql="FLOAT" quote=""/>
<type label="Double precision" length="0" sql="DOUBLE" re="DOUBLE" quote=""/>
@flakyfilibuster
flakyfilibuster / Coup d'etat
Created November 5, 2012 00:49
Congress Database 1: From CSV to SQLite with Ruby
update politicians set name='Sen. Shereef Bishay' where id=422;
require 'sqlite3'
class Database
$db ||= SQLite3::Database.new('/Users/apprentice/Desktop/FTW/lib/connect4_dev.db', :results_as_hash => true)
def self.instance
$db
end
def self.load_schema
@flakyfilibuster
flakyfilibuster / database.rb
Created November 5, 2012 05:02
Dummy Database
require 'sqlite3'
require 'faker'
$db =SQLite3::Database.new( "test.db" )
$db.execute <<-SQL
create table dummy (
id INTEGER PRIMARY KEY,
first_name varchar(30),
last_name varchar(30),
@flakyfilibuster
flakyfilibuster / nokogiri_grouphug.rb
Created November 7, 2012 18:34
grouphug_nokogiri
require 'rubygems'
require 'nokogiri'
require 'open-uri'
class Grouphug_scraper
attr_accessor :confessions, :ids, :title
def initialize(url)