Skip to content

Instantly share code, notes, and snippets.

View binarycode's full-sized avatar

Igor Sidorov binarycode

  • Virtuozzo
  • Rishon LeZion
View GitHub Profile
@mrrooijen
mrrooijen / deploy.rb
Created May 16, 2011 18:12
Unicorn + Bluepill + Capistrano with RVM
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require "rvm/capistrano"
set :application, "my_app"
set :repository, "[email protected]:myuser/myapp.git"
set :branch, "production"
set :rvm_ruby_string, "1.9.2"
set :deploy_to, "/var/applications/"
set :user, "username"
# daemonized resque scheduler runner
require 'yaml'
env = ENV['RAILS_ENV'] || 'development'
scheduler_config = YAML.load_file(File.expand_path('../../config/resque_schedule.yml', __FILE__))[env]
puts scheduler_config.inspect
paths = []
paths << stdout_path = scheduler_config['stdout_path']
paths << stderr_path = scheduler_config['stderr_path']
paths << pidfile_path = scheduler_config['pidfile_path']
@mpapis
mpapis / gist:1789571
Created February 10, 2012 13:05
ruby not preserving order of array elements when sorting
1.9.3p0 :001 > Z=Struct.new(:n,:v)
=> Z
1.9.3p0 :002 > z=[ Z.new('b',1), Z.new('b',2), Z.new('a',1)]
=> [#<struct Z n="b", v=1>, #<struct Z n="b", v=2>, #<struct Z n="a", v=1>]
1.9.3p0 :003 > z.sort_by{ |z| z.n }
=> [#<struct Z n="a", v=1>, #<struct Z n="b", v=2>, #<struct Z n="b", v=1>]
1.9.3p0 :004 > z.each_with_index.sort_by{ |z, i| [z.n, i] }.map{|z,_| z}
@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 \
@giedriusr
giedriusr / chef_solo_bootstrap.sh
Created July 19, 2012 10:56
Installation of plain ruby (taken from Ryan Bates screencast) + some modifications (newer ruby patch)
#!/usr/bin/env bash
apt-get -y update
apt-get -y upgrade
apt-get -y install build-essential
apt-get -y install libyaml-dev
apt-get -y install zlib1g-dev libssl-dev
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz
tar -xvzf ruby-1.9.3-p194.tar.gz
cd ruby-1.9.3-p194/
@pirj
pirj / Gemfile
Created August 17, 2012 10:13
Sinatra streaming + Redis PubSub
source 'https://rubygems.org'
gem 'sinatra'
gem 'sinatra-contrib', require: 'sinatra/streaming'
group :development do
gem 'thin'
gem 'pry-rails'
end
@return1
return1 / trim_enabler.txt
Last active May 26, 2024 11:01
TRIM Enabler for OS X Yosemite 10.10.3
#
# UPDATE for 10.10.4+: please consider this patch obsolete, as apple provides a tool called "trimforce" to enable trim support for 3rd party SSDs
# just run "sudo trimforce enable" to activate the trim support from now on!
#
# Original version by Grant Parnell is offline (http://digitaldj.net/2011/07/21/trim-enabler-for-lion/)
# Update July 2014: no longer offline, see https://digitaldj.net/blog/2011/11/17/trim-enabler-for-os-x-lion-mountain-lion-mavericks/
#
# Looks for "Apple" string in HD kext, changes it to a wildcard match for anything
#
# Alternative to http://www.groths.org/trim-enabler-3-0-released/
@kizzx2
kizzx2 / post.rb
Last active June 26, 2021 12:14
A clean and elegant approach to partial object validation with Rails + Wicked wizards (using session to store the partial object)
class Post < ActiveRecord::Base
attr_accessible :body, :price, :title
validates_presence_of :title
validates_length_of :title, minimum: 10
validates_presence_of :body
validates_numericality_of :price, greater_than: 0
end
@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

@maccman
maccman / canvas.physics.coffee
Created April 11, 2013 02:52
A canvas physics engine in 160 lines of CoffeeScript.
class Point
constructor: (@x = 0, @y = 0) ->
if isNaN(@x) or isNaN(@y)
throw new Error('Invalid coords')
add: (point) ->
@x += point.x
@y += point.y
subtract: (point) ->