This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# taken from http://railsbros.de/2010/11/29/a-custom-irbrc-for-rails-3.html | |
# config/application.rb that is | |
module MyApp | |
class Application < Rails::Application | |
# config stuff comes here | |
def load_console(sandbox=false) | |
super | |
if File.exists?(project_specific_irbrc = File.join(Rails.root, ".irbrc")) | |
puts "Loading project specific .irbrc ..." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Shamelessly taken from http://blog.iharder.net/2009/09/28/itunes-stream-itunes-over-ssh/ | |
# Your remote library will appear in your local iTunes as a shared library | |
# You need an ssh server running on the remote library's computer | |
#!/bin/sh | |
dns-sd -P "Home iTunes" _daap._tcp local 3689 localhost.local. \ | |
127.0.0.1 "Arbitrary text record" & | |
PID=$! | |
ssh -C -N -L 3689:localhost:3689 yourhost.dyndns.org | |
kill $PID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# yes, sometimes you need to do this. you get pilloried in a forum if you | |
# ask about it, though! | |
# this code taken from | |
# http://wholemeal.co.nz/blog/2011/04/05/rendering-from-a-model-in-rails-3/ | |
class MyModel < ActiveRecord::Base | |
# Use the my_models/_my_model.txt.erb view to render this object as a string | |
def to_s | |
ActionView::Base.new(Rails.configuration.paths.app.views.first).render( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/devise_http_rememberable.rb | |
# Monkeypatch Devise so HTTP authentication sets remember_user_token cookie | |
# ABR: Always Be Remembering | |
module Devise | |
module Strategies | |
class Authenticatable < Base | |
def remember_me? | |
# Devise's implementation of this is: | |
# valid_params? && Devise::TRUE_VALUES.include?(params_auth_hash[:remember_me]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_complete_ssh_hosts () | |
{ | |
COMPREPLY=() | |
cur="${COMP_WORDS[COMP_CWORD]}" | |
comp_ssh_hosts=`cat ~/.ssh/known_hosts | \ | |
cut -f 1 -d ' ' | \ | |
sed -e s/,.*//g | \ | |
grep -v ^# | \ | |
uniq | \ | |
grep -v "\[" ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="zh-CN"> | |
<head> | |
<title>Triangle</title> | |
<meta charset="utf-8" /> | |
<style type="text/css"> | |
.a{width:0;height:0;border-top:100px solid #0099ff;border-left:100px solid #ff9900;border-right:100px solid #F6402D;border-bottom:100px solid #8CC63E; float:left;} | |
.b{ | |
width:0;height:0;border-top:100px solid #0099ff;border-left:100px solid transparent;border-right:100px solid transparent;border-bottom:0; margin-left:60px; float:left;} | |
.c{width:0;height:0;border-top:100px solid transparent;border-left:0;border-right:100px solid transparent;border-bottom:100px solid #0099ff; margin-left:60px; float:left;} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# via http://jablan.radioni.ca/post/4982485974/parsing-search-query-in-ruby | |
def parse_query s | |
s.scan(/((\S+)\:\s?)?([+-])?(("(.+?)")|(\S+))/).map{|match| | |
Hash[ | |
[nil, :prefix, :plusminus, nil, nil, :phrase, :word].zip(match).select(&:all?) | |
] | |
} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Stolen from http://paste.pocoo.org/show/224441/ | |
from pymongo.cursor import Cursor | |
from pymongo.connection import Connection | |
from pymongo.errors import AutoReconnect | |
from time import sleep | |
def reconnect(f): | |
def f_retry(*args, **kwargs): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_files(directory, pattern): | |
for root, dirs, files in os.walk(directory): | |
for basename in files: | |
if fnmatch.fnmatch(basename, pattern): | |
filename = os.path.join(root, basename) | |
yield filename | |
for f in find_files(".", "*.txt"): | |
print f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# determines filename and extension, then delegates compiling the LESS files to lessc via a shell command | |
import sys, os.path | |
from subprocess import call | |
src = sys.argv[1] | |
base,ext = os.path.splitext(src) |