Skip to content

Instantly share code, notes, and snippets.

@lushone
lushone / disable-cache.html
Created April 19, 2013 09:49
Disable caching on iOS browsers.
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="pragma" content="no-cache">
@lushone
lushone / gist:5546946
Created May 9, 2013 11:30
Fix pg gem to work with PostgreSQL 9.2
cd /Library/Ruby/Gems/1.8/gems/pg-0.13.2/lib/
otool -L pg_ext.bundle
> libpq.5.dylib (compatibility version 5.0.0, current version 5.4.0)
# Notice that libpq.5.dylib doesn't use an absolute path like the other libs in pg_ext.bundle. The system can't find it. You need to change where it looks for libpq.5.dylib.
install_name_tool -change libpq.5.dylib /Library/PostgreSQL/9.2/lib/libpq.5.dylib pg_ext.bundle
# Note: Use the absolute path that applies to your system. I used what it was for my system.
# Now run:
@lushone
lushone / gist:5550239
Created May 9, 2013 20:17
get an image's dimensions using pure js
/**
* get an image's dimensions using pure js
*/
var img = new Image();
img.onload = function() {
document.write('<strong>image:</strong> ' + this.src + '<br><strong>width:</strong> '+ this.width + '<br><strong>Height:</strong> ' + this.height);
}
img.src = 'http://domain.com/image.jpg';
#!/bin/bash
OPENSSL_VERSION="1.0.0e"
curl -O http://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz
tar -xvzf openssl-$OPENSSL_VERSION.tar.gz
mv openssl-$OPENSSL_VERSION openssl_i386
tar -xvzf openssl-$OPENSSL_VERSION.tar.gz
mv openssl-$OPENSSL_VERSION openssl_x86_64
cd openssl_i386
./Configure darwin-i386-cc -shared
@lushone
lushone / gist:6257616
Created August 17, 2013 16:07
Create iPhone ringtones with ffmpeg
ffmpeg -i ringtone.mp3 -ac 1 -ab 128000 -f mp4 -acodec libfaac -y ringtone.m4r

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.

@lushone
lushone / Rakefile
Created March 6, 2014 11:29 — forked from stammy/Rakefile
# ignore the "bit" stuff.. only relevant to my custom jekyll fork
desc 'create new post or bit. args: type (post, bit), title, future (# of days)'
# rake new type=(bit|post) future=0 title="New post title goes here" slug="slug-override-title"
task :new do
require 'rubygems'
require 'chronic'
type = ENV["type"] || "bit"
title = ENV["title"] || "New Title"
# shortform git commands
alias g='git'
# generate file list modified since last commit and export to tar file
git diff-tree -z -r --no-commit-id --name-only --diff-filter=ACMRT COMMID_HASH | xargs -0 tar -rf list.tar
# export unpushed files list
git log -z origin/master..master --name-only --pretty="format:" | sort -zu | xargs -0 tar -rf list.tar
# Count the lines of each file extenion in a list of files