Skip to content

Instantly share code, notes, and snippets.

View damian's full-sized avatar

Damian Nicholson damian

View GitHub Profile
javascript:window.location = document.location.protocol + '//' + document.location.host + '/admin_menu/flush-cache?destination=' + document.location.pathname.substring(1);
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
function Async(options){};
Async.each=function(list,callback){
var _count=0;
if(list.length==null){
_list=[];
@damian
damian / gist:738893
Created December 13, 2010 11:01
Gravatar with options
require 'digest/md5'
def gravatar(user, options = {})
email_address = user.email.downcase
hash = Digest::MD5.hexdigest(email_address)
image_src = "http://www.gravatar.com/avatar/#{hash}"
unless options.empty?
query_string = options.map {|key, value| "#{key}=#{value}"}
image_src << "?" << query_string.join("&")
end
Can't exec "ruby": No such file or directory at /usr/sbin/munin-node line 564, <STDIN> line 47.
2011/01/19-14:00:37 Plugin timeout: passenger_memory_stats : Interrupted system call
(pid 11057)
Can't exec "ruby": No such file or directory at /usr/sbin/munin-node line 564, <STDIN> line 58.
2011/01/19-14:00:50 Plugin timeout: passenger_status : Interrupted system call
(pid 11159)
@damian
damian / Prompt git branch
Created March 3, 2011 09:35
Prompt git branch
# Bash prompt
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
PS1="$RED\$(date +%H:%M) \w$YELLOW\$(parse_git_branch)$GREEN\$ "
# Required for meta_search to use a named scope
search_methods :for_location, :at_location, :name_contains
scope :for_location, lambda { |location| location = Location.find(location) unless location.is_a?(Location); joins('LEFT OUTER JOIN administrators_locations ON administrators.id = administrator_id').where('location_id IN(?)', location.path_ids) }
scope :at_location, lambda { |location| location = Location.find(location) unless location.is_a?(Location); joins('INNER JOIN administrators_locations ON administrators.id = administrator_id').where('location_id = ?', location.id) }
scope :name_contains, lambda { |name| where("CONCAT_WS(' ', forename, surname) LIKE ?", "%#{name}%") }
@damian
damian / gist:1212315
Created September 12, 2011 20:29
Colgroup
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
* { margin: 0; padding: 0; }
body { font: 14px Georgia, serif; }
table { border-collapse: collapse; width: 600px; }
@damian
damian / pre-commit
Created November 18, 2011 16:02
Git pre-commit hook
#!/bin/sh
# A JavaScript focussed git pre-commit hook
#
# It ensures that any files containing console.log() or alert() calls aren't able to be committed.
# It also ensures that all JavaScript passes JSHint(which is assumed to be installed). A static code analysis tool which detects errors and potential issues from smelly JS - see http://www.jshint.com/ for more details
#
# Written by Damian Nicholson - @damian
if git rev-parse --verify HEAD >/dev/null 2>&1
@damian
damian / gist:1386249
Created November 22, 2011 17:16
CSS border transitions
<style type="text/css">
a {
display:inline-block;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
width:100px;
height:100px;
-webkit-border-radius:50px;
-moz-border-radius:50px;
@damian
damian / gist:1388506
Created November 23, 2011 11:55
Cheap db backup rake task to be used with Rails
namespace :db do
desc 'Backup database'
task :backup => :environment do
# Loads in database config and finds the correct environment
config = YAML::load(File.open('config/database.yml'))[Rails.env]
# Creates a filename which is unique to the backup
filename = "backup_#{Time.now.to_i}"
# Run a mysqldump using our credentials from database config