Skip to content

Instantly share code, notes, and snippets.

View gist:475
class GistTest
def test(foo='bar')
end
end
View pusher-travis-client.rb
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',
View 01_sketelon.html
<!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>
View 2-elements-per-iteration.hbs
<table>
{{#for post in posts}}
<tr><td>First row</td></tr>
<tr><td>Second row</td></tr>
{{/for}}
</table>
View gist:10368834
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 Aug 29, 2015
form objects
View post_form.rb
class PostForm
include Virtus.model
extend ActiveModel::Naming
include ActiveModel::Validations
attribute :id, Integer
attribute :title, String
attribute :body, String
validates :title, presence: true
View Setting longer HTTP timeout in capybara
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
View sound.py
#!/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 ),
View config.initializers.active_record_extensions.rb
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
View performance.rb
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 |