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 |
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 tips.sh
# 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 |
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 | |
end | |
end | |
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 | |
protected | |
def validate | |
if position < 1 | |
errors.add(:position , " must be greater than 0") | |
end |
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)} | |
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 |
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
#!/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 |
OlderNewer