Skip to content

Instantly share code, notes, and snippets.

View gist:fd9bd940eae5978e1f8d
# This hack is designed to prevent a thread from implicitly checking out an AR connection by
# just accessing ActiveRecord::Base.connection. The point of doing this is to ensure that threads
# don't tie up connections that they are not using, by making sure we're explicit about where we
# need to use an AR connection.
#
# See also http://tenderlovemaking.com/2011/10/20/connection-management-in-activerecord.html
ActiveSupport.on_load(:active_record) do
ActiveRecord::ConnectionAdapters::ConnectionPool # ensure loaded
View dot.powrc.sh
if [ -f "${rvm_path}/scripts/rvm" ]; then
source "${rvm_path}/scripts/rvm"
if [ -f ".rvmrc" ]; then
source ".rvmrc"
elif [ -f ".ruby-version" ] && [ -f ".ruby-gemset" ]; then
rvm use `cat .ruby-version`@`cat .ruby-gemset`
elif [ -f ".ruby-version" ]; then
rvm use `cat .ruby-version`
View ansible.cfg
[defaults]
remote_user = vagrant
hostfile = .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
private_key_file = ~/.vagrant.d/insecure_private_key
@j-manu
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
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 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: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: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