Skip to content

Instantly share code, notes, and snippets.

bling = {"blah"=>0.0038, "bloo"=>0.01}
bling.each_pair do |name, value|
val = sprintf( "%.02f" , value).to_s.to_f
bling[name] = val if val!=0
end
puts bling.inspect
=> {"blah"=>0.0038, "bloo"=>0.01} #does this? WTF?
<script type="text/javascript" language="javascript">
$(function () {
var chart_selector = "#57";
$.plot($(chart_selector), [
{
data: [[1296431999000, 0.404836307023734], [1296518399000, 0.407615597839891], [1296604799000, 0.383347139459691], [1296691199000, 0.366511148398092], [1296777599000, 0.399677487432291], [1296863999000, 0.373120121835142], [1296950399000, 0.376370103920855], [1297036799000, 0.388712657769108], [1297123199000, 0.392372440535301], [1297209599000, 0.338887153957786], [1297295999000, 0.215102006264285], [1297382399000, 0.243113630361647], [1297468799000, 0.276328075801116], [1297555199000, 0.386734482742028], [1297641599000, 0.441959801544221], [1297727999000, 0.427229618821813], [1297814399000, 0.420886374585893], [1297900799000, 0.422994439646389], [1297987199000, 0.443993244836197], [1298073599000, 0.570164450279094], [1298159999000, 0.786386138613861], [1298246399000, 0.729117360235872], [1298332799000, 0.627713955917111], [1298505599000, 0.541585160781084], [12985
app = ActionController::Integration::Session.new
app.get url
app.response.body #this will be the responses body.
require 'rubygems'
require 'dm-migrations'
require 'dm-core'
require 'dm-migrations/migration_runner'
env = ARGV.first || "development"
db = YAML.load(File.read(ENV['PWD']+'/config/database.yml'))
if !db.has_key?(env)
puts "No such environment #{env}."
env = "development"
#this is all called in a rakefile, which basically just loads the .rb migration file then runs migrate_up! or migrate_down! depending on direction
?> migrate_up!
== Performing Up Migration #1: core_db_20110304235959
CREATE TABLE `analysis_metadatas` (`id` SERIAL PRIMARY KEY, `function` String(50), `finished` TrueClass, `rest` TrueClass, `curation_id` Integer, `save_path` String(50)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
DataObjects::SQLError: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'String(50), `finished` TrueClass, `rest` TrueClass, `curation_id` Integer, `save' at line 1 (code: 1064, sql state: 42000, query: CREATE TABLE `analysis_metadatas` (`id` SERIAL PRIMARY KEY, `function` String(50), `finished` TrueClass, `rest` TrueClass, `curation_id` Integer, `save_path` String(50)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci, uri: mysql://root:@localhost/140kit)
require 'rubyge
1)
ArgumentError in 'Campaign full-serve campaigns global campaign allocations Campaign.allocations'
Anonymous modules have no name to be referenced by
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.11/lib/active_support/dependencies.rb:611:in `to_constant_name'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.11/lib/active_support/dependencies.rb:417:in `qualified_name_for'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.11/lib/active_support/dependencies.rb:130:in `const_missing'
/Users/dgaffney/Work/api.140proof.com/app/models/campaign.rb:630:in `_unmemoized_total_impressions_expected_today'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.11/lib/active_support/memoizable.rb:72:in `total_impressions_expected_today'
/Users/dgaffney/Work/api.140proof.com/app/models/campaign.rb:514:in `current_percent_allocation'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.11/lib/active_record/associations/association_proxy.rb:215:in `send'
where gmt is aliased as gmtime
>> DateTime.now.to_time.gmt
=> Fri Mar 11 04:28:38 UTC 2011 #alright, this looks good
>> Time.now.gmt
=> Fri Mar 11 04:28:45 UTC 2011 #alright, this looks good
>> d = Dataset.last
=> #<Dataset @id=1 @scrape_type="track" @start_time=#<DateTime: 212166602837/86400,-7/24,2299161> @length=3400 @created_at=nil @updated_at=nil @scrape_finished=false @instance_id=nil @params="lol" @tweets_count=0 @users_count=0>
>> d.start_time = Time.now.gmt #so this should be about "Fri Mar 11 04:29..."
def self.spooled_result(query)
puts query
connection = Environment.db
connection.query_with_result = false
sync = connection.real_query(query)
return sync.use_result
end
def self.spooled_result(query)
puts query
connection = Environment.db
connection.query_with_result = false
sync = connection.real_query(query)
return sync.use_result
end
named_scope :from_date, lambda {|date| {:conditions => {:created_date => date}}}
named_scope :today, :from_date Date.today