Skip to content

Instantly share code, notes, and snippets.

@pithyless
pithyless / gist:1208841
Created September 10, 2011 21:49
Install Python 2.7 (homebrew + pip + virtualenv) on Mac OS X Lion

Install Python

$ brew install readline sqlite gdbm
$ brew install python --universal --framework
$ python --version
Python 2.7

Symlinks...

@pithyless
pithyless / Model_and_Form_Validations.md
Created September 13, 2011 22:49
Django Field Notes

Model + Form validations

Some of Django's choices on how to handle data integrity are wrong, or at the very least, unexpected to the uninitiated developers. I'm not here to pass judgement; like many people, I'd just like to get back to doing real work. Some notes on how to stay safe in Django:

What should I know?

  • Django now has both Form validations and Model validations
  • Django used to only have Form validations
  • Form’s is_valid() performs model validation automatically
  • full_clean() is never actually called by Django (see ticket #13100)
@pithyless
pithyless / gist:1261919
Created October 4, 2011 15:18
Carrierwave custom store_path

Carrierwave recommends overriding store_dir in the uploader, but it only gives you a way to modify the directory name, not the whole path with the file name. Overriding store_path let's you modify the entire path.

def store_path(for_file = filename)
  self.model.class.name.underscore.pluralize + "/" + self.model.slug + "/" + (version_name || :original).to_s + ".jpg"
end

This is the original:

@pithyless
pithyless / template.html
Created January 1, 2012 13:14 — forked from steveklabnik/template.html
I always end up typing out the minimal (for me) html5 stuff. so here it is.
<!doctype html >
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<nav></nav>
</body>
</html>
@pithyless
pithyless / quality.rake
Created January 1, 2012 13:14 — forked from steveklabnik/quality.rake
My new favorite Rake task
require 'flog'
require 'flog_task'
require 'flay'
require 'flay_task'
require 'roodi'
require 'roodi_task'
FlogTask.new :flog, SOME_NUMBER_HERE, %w[app lib]
FlayTask.new :flay, OTHER_NUMBER_HERE, %w[app lib]
RoodiTask.new 'roodi', ['app/**/*.rb', 'lib/**/*.rb']
@pithyless
pithyless / after.rb
Created January 1, 2012 13:17 — forked from steveklabnik/after.rb
dont load rails!
require 'active_record'
require "#{Rails.root}/app/models/user"
describe User do
it "does something sweet"
it "does something cool"
end
@pithyless
pithyless / gist:1547408
Created January 1, 2012 14:02
jQuery set Headers for $.ajax
// jQuery Headers support for $.ajax
$.ajax({
beforeSend: function(xhrObj){
xhrObj.setRequestHeader("Content-Type","application/json");
xhrObj.setRequestHeader("Accept","application/json");
}
type: "POST",
url: "/article",
processData: false,
@pithyless
pithyless / gist:1547905
Created January 1, 2012 17:52
Git track upstream repo
One time:
git remote add upstream git@github.com:foo/bar.git
git fetch upstream
git checkout -b upstream upstream/master
Each time you want to update:
git checkout upstream
git pull
@pithyless
pithyless / mac-homebrew-pyexiv2.sh
Created January 22, 2012 17:19 — forked from jpwatts/mac-homebrew-pyexiv2.sh
In which I finally get pyexiv2 working on my Mac using Homebrew and a series of disgusting hacks
#!/bin/sh
brew install python scons boost exiv2
curl -O http://launchpadlibrarian.net/83595798/pyexiv2-0.3.2.tar.bz2
tar xjvf pyexiv2-0.3.2.tar.bz2
cd pyexiv2-0.3.2
# https://answers.launchpad.net/pyexiv2/+question/140742
echo "env['FRAMEWORKS'] += ['Python']" >> src/SConscript
@pithyless
pithyless / match_method.rb
Created February 8, 2012 08:37 — forked from avdi/match_method.rb
Defining method_missing and respond_to? in one fell swoop
# Do you ever define #method_missing and forget #respond_to? I sure
# do. It would be nice if we could do them both at the same time.
module MatchMethodMacros
def match_method(matcher, &method_body)
mod = Module.new do
define_method(:method_missing) do |method_name, *args|
if matcher === method_name.to_s
instance_exec(method_name, *args, &method_body)
else