Skip to content

Instantly share code, notes, and snippets.

View rafi's full-sized avatar

Rafael Bodill rafi

View GitHub Profile
@rafi
rafi / form_builder_controller.js
Created March 27, 2014 13:41
Rough draft for dynamic regions and views loading into layout (Backbone.js, Marionette.js, RequireJS)
var _this = this,
pendingViewPaths = [];
options = options || {};
this.layout = this.getFormLayout(options);
this.elements = options.collection;
this.show(this.layout);
javascript:(function() {
var bookmarklet = {
init: function() {
this.parse();
},
parse: function() {
page = "";
$(".PlaylistPage:visible")
.find(".Track")
.children(".info")
@rafi
rafi / .psqlrc
Created June 10, 2014 08:03
psql startup file
-- vim: se ft=psql :
------------------------------------------------------------------------------
-- sources and inspiration: --
-- http://opensourcedbms.com/dbms/psqlrc-psql-startup-file-for-postgres/ --
-- http://www.craigkerstiens.com/2013/02/21/more-out-of-psql/ --
-- https://github.com/dlamotte/dotfiles/blob/master/psqlrc --
------------------------------------------------------------------------------
\set QUIET ON
@rafi
rafi / Auth.php
Created July 8, 2014 09:33
Minimal Auth helper for Kohana
<?php
/**
* Auth helper
*
* @package Kohana/Auth
* @author Kohana Team
* @copyright (c) 2007-2012 Kohana Team
* @license http://kohanaframework.org/license
*/
@rafi
rafi / git-hook.sh
Last active August 29, 2015 14:06
Git hooks maintenance
# Iterate and delete all hook files from git projects and submodules (only if there's ".git" in path)
find . -name 'post-*' | grep 'hooks/' | grep '.git' | sed 's/hooks\/.*$/hooks/g' | while IFS= read -r dir; do rm $dir/*; done;
# Copy your git template's hooks into all projects and submodules (only if there's ".git" in path)
find . -name 'hooks' -type d | grep '.git' | while IFS= read -r dir; do cp ~/.config/git/template/hooks/* $dir/; done;
# Copy your git template's hooks into a single project
cp ~/.config/git/template/hooks/* .git/hooks/
@rafi
rafi / syntastic.vim
Last active August 29, 2015 14:07
syntastic/syntax_checkers/html/tidy.vim (Strip mustache tags out of HTML content to ease HTMLTidy's errors)
let g:syntastic_html_tidy_ignore_errors = [
\ '<html> attribute "lang" lacks value',
\ '<a> attribute "href" lacks value',
\ 'trimming empty <span>',
\ 'trimming empty <h1>'
\ ]
@rafi
rafi / convert.vim
Created October 6, 2014 12:23
Atlassian JIRA markup to Markdown. Oh the horror! Inspiration: https://github.com/FokkeZB/J2M
function! s:convert_to_markdown(txt)
let txt = a:txt
let txt = substitute(txt, 'h\(\d\+\)\. ', '\=repeat("#", submatch(1))." "', 'g')
let txt = substitute(txt, '{code\(:\([a-z]\+\)\)\?}', '```\2', 'g')
let txt = substitute(txt, '{{\([^}\n]\+\)}}', '`\1`', 'g')
let txt = substitute(txt, '\*\([^\*\n]\{-}\)\*', '\*\*\1\*\*', 'g')
let txt = substitute(txt, '_\([^_\n]\{-}\)_', '\*\1\*', 'g')
let txt = substitute(txt, '\s\zs-\([^-\n]\{-}\)-', '~~~\1~~~', 'g')
let txt = substitute(txt, '+\([^+\n]\+\)+', '<ins>\1</ins>', 'g')
let txt = substitute(txt, '\^\([^\^\n]\+\)\^', '<sup>\1</sup>', 'g')
@rafi
rafi / migrate_branches.sh
Last active August 29, 2015 14:17
Git subtree push --rejoin for all branches that changed a directory, using git merge-base.
#!/usr/bin/env bash
set -e
set -u
# Exit program with error message.
die() {
echo -e "ERROR: $1"
exit $2
}
@rafi
rafi / agg-queues.sh
Last active August 29, 2015 14:22
Converting Circus celery worker ini files into Ansible yaml
#!/usr/bin/env bash
echo "workers:"
find roles/ -iname 'celery*' | xargs grep -h 'watcher\|cmd' \
| gsed "s/'/\"/g" \
| gsed "s/\s*{{ ansible_nodename }}//g" \
| gsed 's/--time-limit=//' \
| gsed 's/\-[OQlnc]\s\+//g' \
| awk -F'"' '{for(i=2;i<=NF;i++)if(i%2==0)gsub(" ","_",$i);}1' OFS="\"" \
| gsed "s/{{\s/{{_/g" \
@rafi
rafi / gmail_spam_filter.md
Created December 4, 2009 10:37
Gmail spam filter

I'm sick of all those spam emails sent to my Gmail, although they are trapped in the Spam folder, sometimes I do receive legitimate emails which are mistakenly trapped in the spam folder, so this filter will delete annoying pharmaceuticals shit and crap watches spam emails so looking at the spam will be a little easier.

Subject: Pfizer OR RxMed OR RxMeds OR Ritalin OR Phentermin OR AnxietyMedications OR Weightl0ss OR Vicodin OR Oxycodone OR noprescription OR hydrocodone OR "Herbal Pills" OR ("risk free" AND pills) OR "longer and stronger in bed" OR "help falling in sleep" OR "unique web offer" OR (without AND prescription) OR (fda AND drugs) OR "refill notice" OR (long AND stronger AND bed) OR ((favorite OR pain OR cheaper OR online OR refill OR order) AND (medication OR medications OR med OR meds)) OR Xanax OR Viagra OR Phentermine OR RxMedications OR (Refill AND PreScript) OR (Replica AND Watches) OR (Percocet AND (Shipped OR Available)) OR (larger AND penis) OR Phentrmine OR Cialis

Has the words: