Skip to content

Instantly share code, notes, and snippets.

@theconektd
theconektd / gist:12991
Created September 25, 2008 23:55
Generates a per_page select for will_paginate
def per_page_select(collection, name=nil, value=nil, options={})
unless collection.empty?
per_page = collection.first.class.per_page
name = name || 'per_page'
value = value || params[:per_page] || per_page.to_s
before = options[:before_default] || ["#{per_page/2}"]
after = options[:after_default] || ["#{per_page*2}"]
choices = options_for_select(before + ["#{per_page}"] + after, value)
select_tag name, choices, options
end
@jarib
jarib / tryselenium.rb
Created April 5, 2011 20:44
Nested LoadableComponents in Ruby
require 'selenium-webdriver'
#
# Read more about LoadableComponent here:
#
# http://code.google.com/p/selenium/wiki/LoadableComponent
#
class LoadableComponent
attr_reader :driver
@jarib
jarib / file.rb
Created June 14, 2011 13:02
selenium-webdriver bug report template
require 'rubygems'
require 'selenium-webdriver'
path = File.expand_path("test.html")
File.open(path, "w") { |io| io << DATA.read }
browser = Selenium::WebDriver.for :firefox # replace :firefox with the browser you're having trouble with
begin
browser.get "file://#{path}"
@hisea
hisea / nginx
Created January 1, 2012 23:37
ubuntu passenger nginx init.d script
sudo cp nginx /etc/init.d/
sudo update-rc.d nginx defaults
sudo chmod +x /etc/init.d/nginx
/etc/init.d/nginx start
@andresgutgon
andresgutgon / user.rb
Created January 8, 2012 13:28
Migrate Autholugic SHA512 Passwords to BCryt Devise Passwords
# Because we have some old legacy users in the database, we need to override Devises method for checking if a password is valid.
# We first ask Devise if the password is valid, and if it throws an InvalidHash exception, we know that we're dealing with a
# legacy user, so we check the password against the SHA1 algorithm that was used to hash the password in the old database.
#SOURCES OF SOLUTION:
# http://stackoverflow.com/questions/6113375/converting-existing-password-hash-to-devise
# https://github.com/binarylogic/authlogic/blob/master/lib/authlogic/crypto_providers/sha512.rb
# https://github.com/plataformatec/devise/blob/master/lib/devise/encryptors/authlogic_sha512.rb
alias :devise_valid_password? :valid_password?
def valid_password?(password)
@nesquena
nesquena / jbuilder.rb
Created February 14, 2012 01:15
JBuilder and RABL Syntax Comparison
Jbuilder.encode do |json|
json.content format_content(@message.content)
json.(@message, :created_at, :updated_at)
json.author do |json|
json.name @message.creator.name.familiar
json.email_address @message.creator.email_address_with_name
json.url url_for(@message.creator, format: :json)
end
@Fonsan
Fonsan / blocks.rb
Created May 9, 2012 18:24
First class citizen methods in ruby
def do_something
yield 'something'
end
do_something do |thing|
puts thing
end
def do_complex(first, second)
thing = 'nothing'
@xdite
xdite / gist:3072362
Created July 8, 2012 19:10
deploy/asset.rb
# -*- encoding : utf-8 -*-
set :assets_dependencies, %w(app/assets lib/assets vendor/assets Gemfile.lock config/routes.rb)
namespace :deploy do
namespace :assets do
desc <<-DESC
Run the asset precompilation rake task. You can specify the full path \
to the rake executable by setting the rake variable. You can also \
@somebody32
somebody32 / gist:5232120
Last active October 4, 2022 08:19
Список литературы для ознакомления с concurrent programming и реализацией этих принципов и подходов на ruby. Огромное спасибо @brainopia за составление.

Введение

Начать стоит отсюда. Не пугайтесь то, что это книга по незнакомой OS, эти термины практически везде одинаковые и здесь они изложены в понятной для начинающих форме.

http://www.qnx.com/developers/docs/6.4.1/neutrino/getting_started/s1_procs.html

Прочесть нужно треть главы до подраздела "Starting a process", если С не пугает, читайте полностью. После прочтения вы будете понимать, что такое process, thread, mutex, priorites, semaphores, scheduler, contex-switch, kernel states.

Ruby

nav class="nav navbar navbar-inverse" role="navigation"
div class="container"
div class="navbar-header"
button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".navbar-gnav-collapse"
span class="sr-only" Toggle navigation
span class="icon-bar"
span class="icon-bar"
span class="icon-bar"
div class="collapse navbar-collapse navbar-gnav-collapse"
ul class="nav navbar-nav"