Skip to content

Instantly share code, notes, and snippets.

class GistTest
def test(foo='bar')
end
end
require 'pusher-client'
socket = PusherClient::Socket.new('5df8ac576dcccf4fd076')
socket.subscribe('common')
handler = lambda do |event, data|
p [event, data]
end
events = ['job:created', 'job:started', 'job:finished', 'job:canceled',
<!doctype html>
<html>
<head>
<title>My Little Webapp: Coding Is Magic</title>
<meta charset="UTF-8" />
<link rel="stylesheet" href="https://rawgithub.com/krzysztofbialek/Rails-Girls-Warsaw-App/master/style.css" />
</head>
<body>
</body>
</html>
<table>
{{#for post in posts}}
<tr><td>First row</td></tr>
<tr><td>Second row</td></tr>
{{/for}}
</table>
@drogus
drogus / gist:10368834
Last active August 29, 2015 13:58 — forked from qoobaa/gist:10368474
this.resource("restaurants")
this.resource("restaurant", { path: "/restaurants/:restaurant_id" }, function () {
this.resource("bookings", function () {
this.route("new");
});
this.resource("booking", { path: "/bookings/:booking_id" });
});
@drogus
drogus / post_form.rb
Last active August 29, 2015 14:03
form objects
class PostForm
include Virtus.model
extend ActiveModel::Naming
include ActiveModel::Validations
attribute :id, Integer
attribute :title, String
attribute :body, String
validates :title, presence: true
Capybara.register_driver :selenium_with_long_timeout do |app|
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 120
Capybara::Selenium::Driver.new(app, :browser => :firefox, :http_client => client)
end
Capybara.javascript_driver = :selenium_with_long_timeout
#!/usr/bin/env python
import time
from pyo import *
s = Server(duplex=0).boot()
s.start()
left = [
Sine( phase = 0.25, freq = 400, mul = 0.5 ),
class ActiveRecord::Base
# Returns hash prepared to be converted to json
#
# Can take the same options as ActiveRecord::Base#to_json
def prepare_json(options = {})
if include_root_in_json
{ self.class.json_class_name => JsonSerializer.new(self, options).serializable_record }
else
JsonSerializer.new(self, options).serializable_record
end
Ruby 1.8.6
| AR 2.2.1 | DM 0.9.7 | DIFF |
----------------------------------------------------------------------------------------
Model.new (instantiation) x10000 | 0.541 | 0.049 | 11.02x |
Model.new (setting attributes) x10000 | 1.895 | 1.103 | 1.72x |
Model.get specific (not cached) x10000 | 9.964 | 19.736 | 0.50x |
Model.get specific (cached) x10000 | 12.432 | 1.227 | 10.14x |
Model.first x10000 | 10.063 | 11.966 | 0.84x |
Model.all limit(100) x1000 | 23.322 | 25.645 | 0.91x |
Model.all limit(100) with relationship x1000 | 48.873 | 67.983 | 0.72x |