Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
It's Complicated

Dmitry Sabanin dsabanin

💭
It's Complicated
View GitHub Profile
View gist:4503086
def benchmark(name, &blk)
t1 = Time.now
ret = blk.call
time = Time.now - t1
$STATSD.timing(name, time)
[ret, time]
end
retvalue, time = benchmark("svn-commit-time") do
`svn command blah`
@dsabanin
dsabanin / gist:4118737
Created Nov 20, 2012
Idea for ruby test framework
View gist:4118737
class User < ActiveRecord::Base
test_context(:inherit => [:account_context]) do
@password = "123456"
@user = User.create(:login => "dima",
:first_name => "Dima",
:last_name => "Pupkin",
:password => @password,
:password_confirmation => @password,
:account => @account)
View gist:2146349
(fact "configuration"
server-port => number?
server-url => string?
server-static-path => string?)
(fact "on-connect handler"
(on-connect --connection--) => anything)
(fact "on-disconnect handler"
(on-disconnect --connection--) => anything)
View array_permutation_ext.rb
# Taken here http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/247669. Reformatted.
# based on the C++ standard library's implementation by Ken Bloom
class Array
def next_permutation!
return self if length<2
i = length-1
while true
ii = i
i -= 1
@dsabanin
dsabanin / install-magma-1.1.st
Created Apr 26, 2011
Install Magma 1.1r in Pharo 1.2
View install-magma-1.1.st
Deprecation raiseWarning: false.
Gofer new
squeaksource: 'MetacelloRepository';
package: 'ConfigurationOfMagma';
load.
((Smalltalk at: #ConfigurationOfMagma) project version: #stable) load: 'Tester'.
View rails_mock_openid_request.rb
# Mocks a request to OpenID server with given response status.
# If you give it a hash of args as a third argument, it will act
# like information about user transmitted from OpenID server.
class ActiveSupport::TestCase
# Example:
# mock_openid_response("http://identity.url", OpenID::Consumer::SUCCESS,
# 'fullname' => 'Joe Black',
# 'email' => 'joe.black@gmail.com',
# 'nickname' => 'joeeeey')
View string_tidy_example.rb
"<p>blah".tidy # => "<p>blah</p>"
"blah".tidy # => "blah"
"blah<p>".tidy # => "blah"
"blah".tidy(:show_body_only => false) # =>
# Renders:
# "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
# \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
@dsabanin
dsabanin / pre-commit.sh
Created Sep 8, 2008
Save this file as .git/hooks/pre-commit. No broken tests in repo
View pre-commit.sh
#!/bin/sh
# Save this file as .git/hooks/pre-commit
rake spec
View config.yml
root: "/Users/railsmonk/xfiles"
server_ip: "*"
apache2_configs_directory: "/sw/etc/apache2/alpha.d"
hooks_path: "#{root}/application/script/x"
storage_path: "#{root}/storage"
server_restart_marker: "/tmp/restart-server-please.flag.%d"
## Send emails about exceptions to
exception_recipients:
- sdmitry@gmail.com