Skip to content

Instantly share code, notes, and snippets.

View iamwilhelm's full-sized avatar

Wil Chung iamwilhelm

  • Mountain View, CA
View GitHub Profile
@iamwilhelm
iamwilhelm / tableView Crash
Created October 20, 2010 20:48
The crash log for tableView when prepending Row, then trying to append rows
Process: mindless [95490]
Path: /Users/iamwil/Library/Application Support/iPhone Simulator/4.0.2/Applications/53071FAE-7C99-484E-ACB8-90CFE853CDC7/mindless.app/mindless
Identifier: mindless
Version: ??? (???)
Code Type: X86 (Native)
Parent Process: launchd [151]
Date/Time: 2010-10-20 13:57:21.310 -0700
OS Version: Mac OS X 10.6.4 (10F569)
Report Version: 6
#!/usr/bin/ruby
require 'rubygems'
require 'net/http'
require 'hpricot'
require 'json'
require 'pp'
require 'yaml'
puts "Counting number of users using hashtags"
Incident Identifier: 6D354706-2A9F-46C2-9A98-64D56FC5CADC
CrashReporter Key: ad7a4853d59b8fe78498e170b5d656f9b69a7d12
Process: mindless [711]
Path: /var/mobile/Applications/5C922AE1-DC41-44CC-A6B7-C993AF122E7F/mindless.app/mindless
Identifier: mindless
Version: ??? (???)
Code Type: ARM (Native)
Parent Process: launchd [1]
Date/Time: 2010-08-30 12:50:09.988 -0700
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
require "config/environment"
# HTTP Auth For Resque Console
AUTH_PASSWORD = "password" || ENV['AUTH']
if AUTH_PASSWORD
Resque::Server.use Rack::Auth::Basic do |username, password|
password == AUTH_PASSWORD
end
end
items = [{ :weight => 6, :value => 30 },
{ :weight => 3, :value => 14 },
{ :weight => 4, :value => 16 },
{ :weight => 2, :value => 9 }]
def repeatable_knapsack(items, capacity)
knapsack = []
while true
values = items.reject { |item|
knapsack_overflow(knapsack + [item], capacity)
def make_dag(sequence)
edges = {}
sequence.each_with_index do |num, i|
edges[i] = [] unless edges.has_key?(i)
for j in ((i + 1)...sequence.length)
edges[i] << j if sequence[i] < sequence[j]
end
end
return edges
end
class ChangeTableAttributes < ActiveRecord::Migration
class << self
include AlterColumn
end
def self.up
alter_column :sometables, :is_numeric, :boolean, { "1" => true, "else" => false }, true
alter_column :sometables, :multiplier, :integer, "USING CAST(multiplier AS integer)", 1
end
# used to alter columns in postgresql
module AlterColumn
def alter_column(table_name, column_name, new_type, mapping, default = nil)
drop_default = %Q{ALTER TABLE #{table_name} ALTER COLUMN #{column_name} DROP DEFAULT;}
execute(drop_default)
# puts drop_default
base = %Q{ALTER TABLE #{table_name} ALTER COLUMN #{column_name} TYPE #{new_type} }
if mapping.kind_of?(Hash)
contains_else = mapping.has_key?("else")
-- change a column named "is_numeric" from integer to boolean
ALTER TABLE sometable ALTER COLUMN is_numeric DROP DEFAULT;
ALTER TABLE sometable ALTER COLUMN is_numeric TYPE boolean
USING CASE is_numeric
WHEN '1' THEN true
ELSE 0 END;
ALTER TABLE sometable ALTER COLUMN is_numeric SET DEFAULT true;
-- change a column named "multiplier" from string to integer
ALTER TABLE sometable ALTER COLUMN multiplier DROP DEFAULT;