Skip to content

Instantly share code, notes, and snippets.

@joeybaker
joeybaker / clickable.js
Created Apr 9, 2012
jQuery for a clickable element
View clickable.js
/* 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')
View bash_tolf.sh
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
strtotitle – php to title case a string
View strtotitle
# 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
Turn a dir into a git repo
View gitinstall.sh
# 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
setup a new django project using virtual environments
View newdjango.sh
# 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
Batch Convert CLRF to LF
View tolf.sh
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
Batch rename in bash example
View batchrename.sh
ls mx50_* | awk '{print("mv "$1" "$1)}' | sed s/mx50_*/buckminster_/2 | /bin/sh
@joeybaker
joeybaker / gist:2654948
Created May 10, 2012
Heatmap based on mouse movement
View gist:2654948
/*
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
View gist:2654956
<!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
Security for WordPress
View .htaccess
<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]
You can’t perform that action at this time.