Skip to content

Instantly share code, notes, and snippets.

View avsej's full-sized avatar
🛋️
On the couch

Sergey Avseyev avsej

🛋️
On the couch
View GitHub Profile
@rtomayko
rtomayko / Tests Is Wrong
Created January 28, 2009 20:50
Why "require 'rubygems'" In Your Library/App/Tests Is Wrong
In response to all the responses to:
http://twitter.com/rtomayko/status/1155906157
You should never do this in a source file included with your library,
app, or tests:
require 'rubygems'
The system I use to manage my $LOAD_PATH is not your library/app/tests
@avsej
avsej / vim-alternatives.sh
Created April 11, 2010 09:46
install alternatives for vim
#!/bin/sh
set -e
pkg=vim
mandir=/usr/share/man
bindir=/usr/local/bin
priority=30
update-alternatives --install /usr/bin/vim vim $bindir/vim $priority
update-alternatives --install /usr/bin/vimdiff vimdiff $bindir/vim $priority
class ActiveRecord::Base
before_validation :strip_whitespace_from_attributes!, :stringify_content_attributes!
private
# Will strip trailing and leading whitespace from all attributes and convert
# empty strings to nil.
def strip_whitespace_from_attributes!
for col in self.class.content_columns.collect{|c| c.name.to_sym}
if !self[col].nil? && self[col].respond_to?(:strip)
@vvalgis
vvalgis / Capistrano tasks for starting unicorn.rb
Created May 7, 2010 08:13
Capistrano tasks for starting unicorn
set :rails_env, :production
set :unicorn_binary, "/usr/bin/unicorn"
set :unicorn_config, "#{current_path}/config/unicorn.rb"
set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid"
namespace :deploy do
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && #{try_sudo} #{unicorn_binary} -c #{unicorn_config} -E #{rails_env} -D"
end
task :stop, :roles => :app, :except => { :no_release => true } do
=begin
Author: Jabari Zakiya, Original: 2009-12-25
Revision-2: 2009-12-31
Revision-3: 2010-6-2
Revision-4: 2010-12-15
Revision-5: 2011-5-11
Revision-6: 2011-5-15
Module 'Roots' provides two methods 'root' and 'roots'
which will find all the nth roots of real and complex
@doitian
doitian / wlist.rb
Created August 26, 2010 14:03
List windows for gpicker.
#!/usr/bin/env ruby
workspaces = {}
`wmctrl -d`.each_line do |line|
columns = line.split
if columns[7] == "N/A"
workspace_name = columns[8..-1].join(" ")
else
workspace_name = columns[9..-1].join(" ")
end
diff --git a/postgresql/9.0/main/pg_hba.conf b/postgresql/9.0/main/pg_hba.conf
index 18831d3..f0d0e1d 100644
--- a/postgresql/9.0/main/pg_hba.conf
+++ b/postgresql/9.0/main/pg_hba.conf
@@ -80,13 +80,13 @@
# (custom daily cronjobs, replication, and similar tasks).
#
# Database administrative login by UNIX sockets
-local all postgres ident
+# local all postgres trust
@igrigorik
igrigorik / webapp.rb
Created November 13, 2010 21:28
Inspired by @JEG2's talk at Rubyconf... Any ruby object, as a webapp! 'Cause we can. :-)
require 'rubygems'
require 'rack'
class Object
def webapp
class << self
define_method :call do |env|
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?)
[200, {}, send(func, *attrs)]
end
@mikhailov
mikhailov / installation.sh
Created November 23, 2010 15:18
nginx+passenger (real production config)
# NOTICE: to get Nginx+Unicorn best-practices configuration see the gist https://gist.github.com/3052776
$ cd /usr/src
$ wget http://nginx.org/download/nginx-1.2.1.tar.gz
$ tar xzvf ./nginx-1.2.1.tar.gz && rm -f ./nginx-1.2.1.tar.gz
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz
$ tar xzvf pcre-8.30.tar.gz && rm -f ./pcre-8.30.tar.gz
$ wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
@erlyvideo
erlyvideo / gist:881251
Created March 22, 2011 14:07
lib/sc_middleware.rb
# config/environment/development.rb:
# require 'lib/sc_middleware'
# config.middleware.use ScMiddleware
class ScMiddleware
def initialize(app)
@app = app
SC::Rack::Service.filesystem = true
@project = SC::Project.load(File.dirname(__FILE__)+"/../public/self_video", :parent => SC.builtin_project)
@sproutcore = SC::Rack::Service.new([@project])