Skip to content

Instantly share code, notes, and snippets.

View alsemyonov's full-sized avatar
🏠
Working from home

Alex Semyonov alsemyonov

🏠
Working from home
View GitHub Profile
@tonycoco
tonycoco / select2.rb
Created February 19, 2014 17:28
Select2 Capybara Support File
# Useage: select2("value to select", from: "label text")
module Capybara
module Select2
def select2(value, options={})
select_name = options[:from]
select2_container = first("label", text: select_name).find(:xpath, "..").find(".select2-container")
select2_container.find(".select2-choice").click
find(:xpath, "//body").find(".select2-drop li", text: value).click
end
Dash=(Dedent=-(Indent=1.0/0)).to_s[0...1]
def scan(file)
File.readlines(file).inject([[],[]]) do |(tokens,levels),line|
case (levels.last || 0) <=> (level = line[/^\s*(-\s*)?/].length)
when -1 then tokens << Indent; levels << level
when 1 then while (levels.last || 0) > level; levels.pop; tokens << Dedent; end
end
if matches = line.match(/^\s*(-\s*)?(\w+):\s*(.*)$/)
tokens << Dash if matches[1]
@dakatsuka
dakatsuka / amqp.rb
Created May 14, 2012 09:02
Rails3 + unicorn + RabbitMQ
# config/initializers/amqp.rb
require 'amqp/utilities/event_loop_helper'
require 'amqp/integration/rails'
module AMQPManager
def self.start
AMQP::Utilities::EventLoopHelper.run
AMQP::Integration::Rails.start do |connection|
connection.on_error do |ch, connection_close|
raise connection_close.reply_text
@mislav
mislav / initialize_spellcheck.rb
Created August 18, 2012 15:32
Raise error if "initialize" method name is misspelled
# Public: Implementation of "Strike a match" algorithm for calculating
# similarity between strings.
#
# http://www.catalysoft.com/articles/StrikeAMatch.html
#
# Examples
#
# checker = StringSimilarityChecker.new('Quick brown fox')
#
# checker =~ 'quick brown ox' #=> true
@rusllonrails
rusllonrails / HOW TO BECAME a ROR DEVELOPER
Created October 10, 2012 07:42
HOW TO BECAME a ROR DEVELOPER
WEB FUNDAMENTS (САМЫЙ ОСНОВЫ) - HTML & CSS
http://www.codecademy.com/tracks/web
HTML
http://htmlbook.ru/samhtml
CSS
@Aeon
Aeon / adapters-application.js
Last active March 21, 2016 18:50
faye adapter for ember-data
require('config/adapters/faye-adapter');
export default DS.FayeAdapter.extend();
@symposion
symposion / README
Created October 15, 2011 15:34 — forked from cyberfox/keychain.rb
Convert OS X Keychain exported entries into logins for 1Password import
These two files should help you to import passwords from mac OS X keychains to 1password.
Assumptions:
1) You have some experience with scripting/are a power-user. These scripts worked for me
but they haven't been extensively tested and if they don't work, you're on your own!
Please read this whole document before starting this process. If any of it seems
incomprehensible/frightening/over your head please do not use these scripts. You will
probably do something Very Bad and I wouldn't want that.
2) You have ruby 1.9.2 installed on your machine. This comes as standard with Lion, previous
versions of OS X may have earlier versions of ruby, which *may* work, but then again, they
@sishen
sishen / gist:1019347
Created June 10, 2011 17:49
Nokogiri Template Builder. (Rails 3.0)
require 'action_view'
module ActionView
module Template::Handlers
class NokogiriBuilder
class_attribute :default_format
self.default_format = Mime::XML
def call(template)
require 'nokogiri'
class Service
class TransactionWrapper
TransactionFailed = Class.new(StandardError)
attr_reader :sequence
delegate :append, :prepend, to: :sequence
def initialize(sequence, connection)
@sequence = sequence
@connection = connection
require "uri"
(URI::REGEXP.constants - ["PATTERN"]).each do |rc|
puts "#{rc}: #{URI::REGEXP.const_get(rc)}"
end
URI::REGEXP::PATTERN.constants.each do |pc|
puts "#{pc}: #{URI::REGEXP::PATTERN.const_get(pc)}"
end