Skip to content

Instantly share code, notes, and snippets.

j-manu / Tips
Created Nov 21, 2010
tips & tricks
View Tips
Delete large number of files:
ls|xargs -L 1000 rm
Maintenace page for Rails
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/../tmp/stop.txt -f
j-manu / Postgres
Created Jan 3, 2011
Postgres tips
View Postgres
When doing the post-install setup of postgresql default database using initdb, you may hit this error:
FATAL: could not create shared memory segment: Cannot allocate memory
DETAIL: Failed system call was shmget(key=1, size=1646592, 03600).
You can either change the postgresql configuration to use less shared memory, or increase the system setting.
I suggest the latter, because this problem seems to stem from other running apps using some of the shared memory allowance, and I'd be nervous about them running out anyway if postgresql was still using a decent amount. IMHO, the default OS X limit is way too low.
Easy to fix; run:
sudo sysctl -w kern.sysv.shmall=65536
View Bash
# extract only the filename without extension
for i in *.xhtml
filename=$(basename $i});
wkhtmltopdf -O landscape -s A3 $i $filename'.pdf';
View vim tips.vimrc
If Vim detects that a file has been changed outside Vim and not inside Vim, 'autoread' will make Vim reread it automatically. But that auto-read won't happen if you do nothing. Vim checks timestamps after invoking the shell, and when you issue the ":checktime" command. Even if you add
:au CursorHold,CursorHoldI * checktime
the check will be triggered *once* if you wait for 'updatetime' milliseconds without doing anything, then it won't be retriggered until you hit a key.
You could also use
:map <F7> :checktime<CR>
:map! <F7> <C-O>:checktime<CR>
View gist:1374728
class CreateList < ActiveRecord::Migration
def self.up
create_table :lists do |t|
t.column :name, :string
t.column :link, :text
t.column :position, :integer
def self.down
View gist:1374732
class List < ActiveRecord::Base
acts_as_list :order => :position
validates_presence_of :name, :link
validates_numericality_of :position, :only_integer => true , :allow_nil => false
def validate
if position < 1
errors.add(:position , " must be greater than 0")
View gist:1374738
def update
@list = List.find(params[:id])
if(@list.position > params[:list][:position].to_i)
List.find(:all, :conditions => ["position >= ? AND position < ?", params[:list][:position],@list.position]).each {|c| c.update_attribute(:position, c.position + 1)}
List.find(:all, :conditions => ["position <= ? AND position > ?", params[:list][:position],@list.position]).each {|c| c.update_attribute(:position, c.position - 1)}
redirect_to :action => 'list'
View gist:1374742
<%= javascript_include_tag 'prototype.js' %>
<%= javascript_include_tag 'effects.js' %>
<%= javascript_include_tag 'dragdrop.js' %>
#reorder.rhmtl (Drag and Drop reordering via AJAX)
<div id="lists">
<ul id="sortable_list">
<% @lists.each do |list| %>
View gist:1374743
#sortable_list {margin:0;margin-top:10px;padding:0;list-style-type: none;width:250px;}
#sortable_list li {margin:0;margin-bottom:4px;padding:5px;border:1px solid #888;cursor:move;}
View gist:1374753
require 'rubygems'
require 'cgi'
require 'mechanize'
def check_pnr(pnr1,pnr2)
agent =
page = agent.get ''
form = page.forms[0]
form.lccp_pnrno1 = pnr1