Skip to content

Instantly share code, notes, and snippets.

@joeybaker
joeybaker / clickable.js
Created April 9, 2012 22:50
jQuery for a clickable element
/* Clickable elements
*/
// when any .clickable elem is clicked, we'll grab the first link in the elem and redirect to it.
$('body').on('click', '.clickable', function(e){
var link = $('a:first', this)
, href = link.attr('href')
// _blank, command key, ctrl key, middle click
if (link.attr('target') == '_blank' || e.metaKey || e.ctrlKey || e.which == 2)
window.open(href, '_blank')
alias tolf="find . -type f -not -iname '*.png' -not -iname '*.jpg' -not -iname '*.jpeg' -not -iname '*.gif' -not -iname '*.tif' -not -iname '*.tiff' -not -iname '.git' -exec perl -pi -e 's/\r\n?/\n/g' {} \;"
@joeybaker
joeybaker / strtotitle
Created May 2, 2012 20:10
strtotitle – php to title case a string
# converts a string to title case
# input: string
# output: string in title case
function strtotitle($title) {
$blacklist = array( 'of','a','the','and','an','or','nor','but','is','then','else', 'at','from','by','on','off','for','in','out','over','to','into','with' );
$words = explode(' ', $title);
foreach ($words as $key => $word) {
if ($key == 0 || !in_array($word, $blacklist))
$words[$key] = ucfirst($word);
}
@joeybaker
joeybaker / gitinstall.sh
Created May 10, 2012 18:32
Turn a dir into a git repo
# add this to your .bash_profile
# usage: gitinstall http://github.com/path/to/git.git
function gitinstall(){ git init; git remote add origin "$@"; git config branch.master.remote origin; git config branch.master.merge refs/heads/master; git pull;}
@joeybaker
joeybaker / newdjango.sh
Created May 10, 2012 18:33
setup a new django project using virtual environments
# To setup a new django project
virtualenv PROJECTNAME --no-site-packages
source PROJECTNAME/bin/activate
pip install django
django-admin.py startproject PROJECTNAME
python PROJECTNAME/manage.py runserver
@joeybaker
joeybaker / tolf.sh
Created May 10, 2012 18:34
Batch Convert CLRF to LF
find . -type f -not -iname '*.png' -not -iname '*.jpg' -not -iname '*.jpeg' -not -iname '*.gif' -not -iname '*.tif' -not -iname '*.tiff' -not -iname '.git' -exec perl -pi -e 's/\r\n?/\n/g' {} \;
@joeybaker
joeybaker / batchrename.sh
Created May 10, 2012 18:35
Batch rename in bash example
ls mx50_* | awk '{print("mv "$1" "$1)}' | sed s/mx50_*/buckminster_/2 | /bin/sh
@joeybaker
joeybaker / gist:2654948
Created May 10, 2012 18:36
Heatmap based on mouse movement
/*
Copyright (c) 2010, Patrick Wied. All rights reserved.
Code licensed under the BSD License:
http://patrick-wied.at/static/license.txt
*/
var heatmapApp = (function(){
// var definition
// canvas: the canvas element
// ctx: the canvas 2d context
// width: the heatmap width for border calculations
@joeybaker
joeybaker / gist:2654956
Created May 10, 2012 18:37
CSS spinner
<!doctype html>
<title>Image-free spinner</title>
<style>
@-webkit-keyframes fadeOut {
0% { opacity:1; }
100% { opacity:.1; }}
p {
position:absolute;
overflow:hidden;
top:50%;
@joeybaker
joeybaker / .htaccess
Created May 10, 2012 18:38
Security for WordPress
<files wp-config.php>
order allow,deny
deny from all
</files>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule ^(.*)$ index.php [F,L]