Skip to content

Instantly share code, notes, and snippets.

Lose It or Lose It's formula to success
Maximum Weekly Reward = week# * $/lb * lb/wk + $5
Actual Weekly Reward = min(MWR, ((start - goal) - (actual - goal))*$/lb) + $5
where
* goal = start - week number * lb/wk
* start = first weigh-in weight
* actual = week's actual weigh-in weight
So, for week 5 of 2-2:
def generate_slug
while slug.blank? || self.class.count(:conditions => ['slug = ?', slug]) > 0
self.slug = Digest::SHA1.hexdigest([Time.now.to_s, (1..10).map{ rand.to_s }].flatten.join('--'))[0, 10]
end
end
* Forward [email protected] -> [email protected]
* Incoming email is passed through a filter if the recipient matches
* Stored as a message, delayed job is queued
* Delayed job is processed which posts the params to the destination
* Params is only JSON with info about attachments including the URL
* Mitt parses JSON and lets the app inspect the important stuff
* Attachment data is lazy-loaded over the wire so it's only fetched if needed.
module MothershipHelper
def mothership(magazine, file)
render :file => File.join(RAILS_ROOT, 'public', 'system', 'mothership', magazine, file)
rescue => e
if e.class == ActionView::MissingTemplate
Exceptional.handle(e, controller, request, params)
else
raise(e)
end
end
@r38y
r38y / huh.rb
Created November 5, 2009 05:28
require 'spec_helper'
describe LoseItDispatcher do
describe ".deliver_phone_confirmation(user)" do
it "should call the same method on the SmsNotifier" do
user = mock_model(User, :phone_number => '12673346833', :null_object => true)
SmsNotifier.should_receive(:deliver_phone_confirmation).with(user) # wrong number of arguments (2 for 1)
LoseItDispatcher.deliver_phone_confirmation(user)
end
end
# http://github.com/pivotal/refraction
Refraction.configure do |req|
winit_hosts = {
'itw' => {
'production' => 'winit.intouchweekly.com',
'staging' => 'winit-stage.intouchweekly.com',
'development' => 'winit.intouchweekly.local',
'test' => 'winit.intouchweekly.test'
},
'las' => {
mysql> SELECT * INTO OUTFILE '/tmp/yeah.txt' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM winit_users;
Query OK, 343234 rows affected (7.48 sec)
* results in a 150 mb csv file -- pretty quick!
@r38y
r38y / user.rb
Created December 15, 2009 19:58
# any idea how I could protect find_then_update_or_create_from_has with
# protect_from_non_user_hash by getting it to return what protect_from_non_user_hash
# returns?
# Basically use protect_from_non_user_hash to stop find_then_update_or_create_from_hash
class User < ActiveRecord::Base
def self.protect_from_non_user_hash(hash)
return nil if !hash.is_a?(Hash) || hash['error']
end
require 'yaml'
class Hash
def filter(*keys)
self.inject({}){|h,v| h[v.first] = v.last if keys.include?(v.first); h}
end
end
test_hash = {'one' => 1, 'two' => 2, 'three' => 3}
puts test_hash.to_yaml
What do you think of this for the Daring Fireball feed sponsorship?
Title: Lose It or Lose It
URL: http://loseitorloseit.com/?utm_source=df
Ad: Lose It or Lose It helps all you chubby geeks put an end to your constant battle to lose weight by making you try hard for 10 weeks or be punished! Choose lb per week and dollars per lb and give us the money up front. Each week, if you skip a weigh-in or don’t make your goal weight, you lose part of your initial investment. We send you daily reminders as well as let you add accountability friends who are updated every week with the status of your weigh-in. After the 10 weeks, you get the remaining balance back as a reward!