WAT

Presenter Notes

json loves dates

1 JSON.parse({"a" => Date.today}.to_json) # => {"a"=>"2012-06-18"}

:)

1 JSON.parse(JSON.stringify({"a": new Date()})).a // "2012-06-18T14:46:47.357Z"
2 new Date() // Mon Jun 18 2012 16:46:54 GMT+0200 (CEST)
  • http://weblogs.asp.net/bleroy/archive/2008/01/18/dates-and-json.aspx
  • http://en.wikipedia.org/wiki/JSON#Data_types.2C_syntax_and_example
  • "JavaScript syntax defines several native data types not included in the JSON standard: Date, Error, Math, Regular Expression, and Function. These JavaScript data types must be represented as some other data format, with the programs on both ends agreeing on how to convert between types. As of 2011, there are some de facto standards for e.g. converting between Date and String, but none universally recognized."

Presenter Notes

Burn all the CPU !

1 EM.add_periodic_timer(nil, &block)
2 EM.add_periodic_timer(0, &block)

Why not an exception ?

1 EM.every_tick(&block) # + warning in doc

Presenter Notes

deploy:cleanup w capistrano

commit 28733e5f6ecbb44e006c9780d1a894b15cdde54f
Author: Paweł Pacana <pawel.pacana@gmail.com>
Date:   Wed Apr 18 14:04:16 2012 +0200

    if you cleanup, dot it AFTER

diff --git a/config/deploy.rb b/config/deploy.rb
index 34af8f0..77b0a1c 100644
--- a/config/deploy.rb
+++ b/config/deploy.rb
@@ -166,8 +166,8 @@ namespace :deploy do
 end

 before "deploy:update", "deploy:pre_announce"
-before "deploy:update", "deploy:cleanup"
 after  "deploy:update", "deploy:middle_announce"
+after  "deploy:update", "deploy:cleanup"
 before "deploy:restart", "deploy:another_announce"
 after  "deploy:restart", "deploy:post_announce"
  • or this shit won't work

Presenter Notes

window.localStorage

The user agent may throw a SecurityError exception instead of returning a Storage object if the request violates a policy decision (e.g. if the user agent is configured to not allow the page to persist data).

1 typeof(window.localStorage)

Presenter Notes

EM.stop will eventually stop :)

 1 EM.run { 
 2   EM.stop
 3   puts EM.reactor_running?
 4   EM.next_tick{
 5     puts EM.reactor_running?
 6     EM.next_tick{
 7       puts EM.reactor_running?
 8     }
 9   } 
10 }

output:

1 true
2 true

Presenter Notes

Minitest api

"." vs "F" vs "E"

  • Symbol ?
  • Dedicated class ?
  • "E" + exception

    1 output = failures.present?? "F" : output
    2 failures.each {|failed| runner.puke(self.class, method_name, failed) }
    

Presenter Notes

Zmq context and fork

  • Forks to have fast running multi-program acceptance tests

    1 Assertion failed: ok (mailbox.cpp:84)
    2 Aborted (core dumped)
    
  • new ZMQ context after fork

  • don't try to close previous one

Presenter Notes

at_exit

1 at_exit{ at_exit { puts "here close things like browsers etc" } }

or

1 MiniTest::Unit.after_tests {}

otherwise:

1 at_exit{ run_minitest }        # second ,  usually from test_helper
2 at_exit{ close_browser }       # first

it allows:

1 ruby -Ilib:test test/unit/something_test.rb

and

1 require 'test_helper'
2 class TestX < MiniTest::Unit; end

we should (IMHO) use dedicated test runners like Turn: https://github.com/TwP/turn

1 turn -Ilib:test test/unit/something_test.rb

Presenter Notes

hoptoad notifier

 1 Capistrano::Configuration.instance(:must_exist).load do
 2   after "deploy",            "deploy:notify_hoptoad"
 3   after "deploy:migrations", "deploy:notify_hoptoad"
 4 
 5   namespace :deploy do
 6     desc "Notify Hoptoad of the deployment"
 7     task :notify_hoptoad, :except => { :no_release => true } do
 8       rails_env = fetch(:hoptoad_env, fetch(:rails_env, "production"))
 9       local_user = ENV['USER'] || ENV['USERNAME']
10       executable = RUBY_PLATFORM.downcase.include?('mswin') ? fetch(:rake, 'rake.bat') : fetch(:rake, 'rake')
11       notify_command = "#{executable} hoptoad:deploy TO=#{rails_env} REVISION=#{current_revision} REPO=#{repository} USER=#{local_user}"
12       notify_command << " DRY_RUN=true" if dry_run
13       notify_command << " API_KEY=#{ENV['API_KEY']}" if ENV['API_KEY']
14       puts "Notifying Hoptoad of Deploy (#{notify_command})"
15       `#{notify_command}`
16       puts "Hoptoad Notification Complete."
17     end
18   end
19 end
  • get data from capistrano about production env
  • execute locally
  • won't work if you gems not installed locally

Presenter Notes