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
# 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
# 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
# app/common/templatetags/expr.py | |
from django import template | |
from django.utils.translation import gettext_lazy as _ | |
from django.conf import settings | |
import re | |
register = template.Library() | |
class ExprNode(template.Node): |
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
class MandrillSignatureVerifier | |
def initialize(key, url, params, signature) | |
@key = key | |
@url = url | |
@params = params | |
@signature = signature | |
end | |
# Return true if the signature matches | |
def verified? |
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
# Rails datetime_select and similar use multiparameter attributes which are | |
# these dawful things from the bowels of activerecord and actionpack. This | |
# module extends virtus models to coerce multiparameter attributes back together | |
# before assigning attributes. | |
# | |
# Here's the implementation for ActiveRecord: | |
# | |
# https://github.com/rails/rails/blob/11fd052aa815ae0255ea5b2463e88138fb3fec61/activerecord/lib/active_record/attribute_assignment.rb#L113-L218 | |
# | |
# and DataMapper: |
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
# this was surprisingly difficult to find, the documentation and API is poor | |
require "net/http" | |
require "uri" | |
url = URI.parse("http://www.whatismyip.com/automation/n09230945.asp") | |
req = Net::HTTP::Get.new(url.path) | |
req.add_field("X-Forwarded-For", "0.0.0.0") | |
# For content type, you could also use content_type=(type, params={}) |
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 |
NewerOlder