Skip to content

Instantly share code, notes, and snippets.

require 'nokogiri'
require 'open-uri'
URL = "http://www.wunderground.com/US/TX/173.html" #change this if you're not in cedar park
TIMESTAMP = /^\d\d\/\d\d\/\d\d\d\d/
$seen = {}
#tunables!
VERBOSE = false
MAX_DEBT = 15_000
MIN_DEBT = 500
MAX_APR = 30
DEBT_MONEY = 1500
SIMULATION_ATTEMPTS = 1000
class Debt
function setCurrentUserFilter() {
Ext.Ajax.request({
url: "/convs/current_user_to_json",
success: function(transport) {
var response = Ext.decode(transport.responseText);
alert("received response!");
alert("setting response to: " + response);
user_combo.setValue(response);
}
});
def current_user_to_json
render :json => {:user => current_user.display_name,
:user_id => current_user.id,
:job_title => current_user.job_title,
:avatar => nil}
end
def problem37
#The number 3797 has an interesting property. Being prime itself, it is possible to
#continuously remove digits from left to right, and remain prime at each stage:
#3797, 797, 97, and 7.
#Similarly we can work from right to left: #3797, 379, 37, and 3.
#primes = [37, 797, 3797]
primes = []
lefts = [2,3,5,7]
rights = [3,7]
Math.module_eval do
def self.variance(population)
n = 0
mean = 0.0
s = 0.0
population.each do |x|
n += 1
delta = x - mean
mean = mean + (delta / n)
s = s + delta * (x - mean)
class Module
def alias_method_chain(target, feature)
# Strip out punctuation on predicates or bang methods since
# e.g. target?_without_feature is not a valid method name.
aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
yield(aliased_target, punctuation) if block_given?
with_method, without_method = "#{aliased_target}_with_#{feature}#{punctuation}", "#{aliased_target}_without_#{feature}#{punctuation}"
alias_method without_method, target
# Settings specified here will take precedence over those in config/environment.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
def people_complexity(people, land)
(floor(people.urban * land.urban))! + (floor(people.rural + land.rural))!
end
women_multiplier = 25
people * people_complexity(women, usa - alaska) * women_multipier * people_complexity(men, usa - alaska)
#here's what the scrape method looks like
def scrape!(&block)
next_link = nil
self.logged_in do
loop do
break if next_link == "none"
response = next_link ?
self.http_get(next_link) :