Skip to content

Instantly share code, notes, and snippets.

Aleksey Gureiev alg

Block or report user

Report or block alg

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View rspec-syntax-cheat-sheet.rb
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
View rails-3-mongo-devise.rb
# This Rails template will generate a Rails 3 (MASTER) application, with MongoDB as ORM and Devise for authentication.
# You will require ruby 1.9.2-HEAD to run generated app.
file 'Gemfile', <<-GEMS
source 'http://gemcutter.org'
gem "rails", :git => "git://github.com/rails/rails.git"
gem "mongoid", "2.0.0.beta4"
gem "bson_ext", "0.20.1"
gem "inherited_resources"
gem "devise", :git => "git://github.com/plataformatec/devise.git"
@alg
alg / mongoid.rb
Created Dec 21, 2010
No underscore/dash escaping in Mongoid
View mongoid.rb
# Instead of the standard composition, convert everything
# non-alpha and non-digit to dash and squeeze
class String
def identify
if Mongoid.parameterize_keys
gsub(/[^a-z0-9]+/, ' ').strip.gsub(' ', '-')
else
self
end
end
@alg
alg / 0_instructions.txt
Created May 31, 2011 — forked from eric1234/0_instructions.txt
Using Sprockets 2 in Rails 3.0.x with CoffeeScript & SASS
View 0_instructions.txt
Some brief instructions on how to use Sprocket 2 in Rails to get CoffeeScript
powered JS and SASS powered CSS with YUI compression all via the magic of rack.
This stuff will be native in Rails 3.1 and the layout of the files on the
filesystem will be different but this guide will get you working with it
while we wait for all that to finalize.
Ignore the number prefixes on each file. This is just to ensure proper order in the Gist.
@alg
alg / session
Created Aug 25, 2011
MongoDB id/array queries
View session
> db.m.insert({ body: '1', phone_id: 1 })
> db.m.insert({ body: '2', phone_id: [ 1, 2 ]})
> db.m.find({ phone_id: 1 })
{ "_id" : ObjectId("4e56089fbdfcdc0f68c894ae"), "body" : "1", "phone_id" : 1 }
{ "_id" : ObjectId("4e5608afbdfcdc0f68c894af"), "body" : "2", "phone_id" : [ 1, 2 ] }
> db.m.find({ phone_id: 2 })
{ "_id" : ObjectId("4e5608afbdfcdc0f68c894af"), "body" : "2", "phone_id" : [ 1, 2 ] }
@alg
alg / t1.erl
Created Dec 29, 2011
Primes from 1 to N
View t1.erl
-module(t1).
-export([primes/1]).
primes(N) -> primeA(1, N, []).
primeA(X, N, L) ->
if
X =:= 1 -> primeA(2, N, [1|L]);
X > N -> lists:reverse(L);
true ->
NL = case length([I || I <- L, X rem I =:= 0]) of
@alg
alg / gist:2964374
Created Jun 21, 2012
Exposing an interface between windows in Titanium
View gist:2964374
//error when the a table row is clicked in nearme_window.js
[WARN] Exception in event callback. {
line = 59;
message = "'undefined' is not a function (evaluating 'pub_win.update_pub_details('blah')')";
name = TypeError;
sourceId = 233027648;
}
//nearme_window.js
module.exports = (function() {
View gist:3952537
describe SomeController do
context "if user is not logged in" do
[ :show, :edit, :update ].each do |action|
specify do
get action
should redirect_to login_path
end
end
end
end
View communal.rb
# encoding: utf-8
def gas(name = "", acct = "")
url = "http://sevgaz.com.ua/index.php?option=com_content&view=article&id=52"
data = `curl -F "afam=#{name}" -F "peracc=#{acct}" "#{url}" 2>/dev/null`
data.scan(%r{Адрес.*?<tr><td>(.*?)</td>\s*<td>\s*<strong>(.*?)</strong>}).flatten
end
def water(name = "", acct = "")
View fill_in_date.rb
# Fills the standard Rails 3-field date picker with the date.
# #name# is supposed to lead to one of these fields, either through a label or a CSS selector.
# Usage:
# fill_in_date "Date of birth", with: 30.years.ago
def fill_in_date(name, options)
date = options[:with]
within find_field(name).parent do
find('select[name*="2i"]').select(date.strftime('%B'))
find('select[name*="3i"]').select(date.day.to_s)
find('select[name*="1i"]').select(date.year.to_s)
You can’t perform that action at this time.