Skip to content

Instantly share code, notes, and snippets.

def user_agent(pattern)
condition {
if request.user_agent =~ pattern
@params[:agent] = $~[1..-1]
true
else
false
end
}
end
Slim2:pgsql _postgres$ /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data start
server starting
Slim2:pgsql _postgres$ FATAL: could not create shared memory segment: Invalid argument
DETAIL: Failed system call was shmget(key=5432001, size=18366464, 03600).
HINT: This error usually means that PostgreSQL's request for a shared memory segment exceeded your kernel's SHMMAX parameter. You can either reduce the request size or reconfigure the kernel with larger SHMMAX. To reduce the request size (currently 18366464 bytes), reduce PostgreSQL's shared_buffers parameter (currently 2048) and/or its max_connections parameter (currently 13).
If the request size is already small, it's possible that it is less than your kernel's SHMMIN parameter, in which case raising the request size or reconfiguring SHMMIN is called for.
The PostgreSQL documentation contains more information about shared memory configuration.
Slim2:pgsql _postgres$ cat data/postgresql.conf | grep max_conn
max_connections = 10 # (change requir
kern.sysv.shmmax=1610612736
kern.sysv.shmall=393216
kern.sysv.shmmin=1
kern.sysv.shmmni=32
kern.sysv.shmseg=8
kern.maxprocperuid=512
kern.maxproc=2048
Slim2:pgsql _postgres$ sysctl -a | grep shm
kern.sysv.shmmax: 2147483648
kern.sysv.shmmin: 1
kern.sysv.shmmni: 32
kern.sysv.shmseg: 8
kern.sysv.shmall: 2147483648
machdep.pmap.hashmax: 12
security.mac.posixshm_enforce: 1
security.mac.sysvshm_enforce: 1
require 'sinatra'
get '/' do
haml :upload
end
post '/show' do
@sinatra_params = params
@rack_request = request
haml :results
gkistner@gitbox:/var/www/bugbot3$ git rev-parse HEAD
1facc81f72428d83a4bc3e0eecd60dec9d403534
gkistner@gitbox:/var/www/bugbot3$ git pull origin planning
remote: Counting objects: 9, done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 5 (delta 4), reused 5 (delta 4)
Unpacking objects: 100% (5/5), done.
From /pub/scm/bugbot3
* branch planning -> FETCH_HEAD
# gem install remix
require 'remix'
class Class
@tweaks = Hash.new{ |h,k| h[k]=Hash.new{ |h,k| h[k] = Module.new } }
class << self; attr_reader :tweaks; end
def when_tweaked_as(name,&block)
Class.tweaks[name][self].class_eval(&block)
end
@Phrogz
Phrogz / phrogz_tweak.rb
Created November 9, 2010 19:52
Temporarily tweak classes to use new methods; idea (and necessary 'remix' functionality) stolen from banister(fiend)
# gem install remix; needed to uninclude modules
require 'remix'
class Class
@tweaks = Hash.new{ |h,k| h[k]=Hash.new{ |h,k| h[k] = Module.new } }
class << self; attr_reader :tweaks; end
def when_tweaked_as(name,&block)
Class.tweaks[name][self].class_eval(&block)
end
def apply_tweak(name,mod=nil)
file = ARGV[0]
2.times do
lines, bytes = 0,0
start = Time.now
File.foreach(file) do |line|
lines += 1
bytes += line.size
end
elapsed = Time.now-start
file = ARGV[0]
2.times do
lines, bytes = 0,0
start = Time.now
contents = File.open(file){ |f| f.read }
contents.scan(/.+/) do |line|
lines += 1
bytes += line.size
end
elapsed = Time.now-start