Skip to content

Instantly share code, notes, and snippets.

@j-manu
j-manu / Tips
Created November 21, 2010 10:36
tips & tricks
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
j-manu / Postgres
Created January 3, 2011 10:35
Postgres tips
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
@j-manu
j-manu / Bash tips.sh
Created January 7, 2011 10:58
Bash Tips
# extract only the filename without extension
for i in *.xhtml
do
filename=$(basename $i});
extension=${filename##*.};
filename=${filename%.*};
wkhtmltopdf -O landscape -s A3 $i $filename'.pdf';
done
@j-manu
j-manu / vim tips.vimrc
Created February 23, 2011 08:25
Vim tips
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>
class CreateList < ActiveRecord::Migration
def self.up
create_table :lists do |t|
t.column :name, :string
t.column :link, :text
t.column :position, :integer
end
end
def self.down
class List < ActiveRecord::Base
acts_as_list :order => :position
validates_presence_of :name, :link
validates_numericality_of :position, :only_integer => true , :allow_nil => false
protected
def validate
if position < 1
errors.add(:position , " must be greater than 0")
end
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)}
else
List.find(:all, :conditions => ["position <= ? AND position > ?", params[:list][:position],@list.position]).each {|c| c.update_attribute(:position, c.position - 1)}
endif
@list.update_attributes(params[:list])
redirect_to :action => 'list'
else
<%= 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| %>
#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;}
#!/usr/local/bin/ruby
require 'rubygems'
require 'cgi'
require 'mechanize'
def check_pnr(pnr1,pnr2)
agent = WWW::Mechanize.new
page = agent.get 'http://www.indianrail.gov.in/pnr_stat.html'
form = page.forms[0]
form.lccp_pnrno1 = pnr1