Skip to content

Instantly share code, notes, and snippets.

@cowboy
cowboy / gist:379255
Created April 26, 2010 12:20 — forked from remy/gist:378764
Just another way of doing it...
// "Cheat" special event using this pattern:
// http://benalman.com/news/2010/03/jquery-special-events/#pattern
//
// Also see:
// http://benalman.com/news/2010/03/jquery-special-events/#add-and-remove-tripleclick-per-handler
(function($){
$.event.special.cheat = {
setup: function() {
/*!
* Prototype throttle / debounce - v1.1 - 4/27/2010
* http://benalman.com/projects/jquery-throttle-debounce-plugin/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function(window,proto,undefined){
@cowboy
cowboy / boilerplate.text
Created April 30, 2010 12:38
For when people offer to donate.. but only if I implement my plugin for them.
_____, to be completely honest, I'm just too busy maintaining these
plugins and writing articles about plugin development to be able to
help with specific implementations. The examples and documentation
I've already taken the time to create are usually sufficient for most
developers looking to implement _____ in their website.
If you are experiencing a very specific problem, feel free to stop
into the official jQuery IRC channel for help with that specific
issue. Also, if you choose to recognize the hard work I've put into
any of my projects with a donation, it would be greatly appreciated.
@cowboy
cowboy / jquery.ba-bindandtrigger.js
Created April 30, 2010 12:49 — forked from westonruter/jquery.bindAndCall.js
Bind an event handler and fire it immediately
/*!
* bindAndTrigger - v0.1 - 04/30/2010
* http://benalman.com/
*
* http://jsfiddle.net/cowboy/fJnA2/
*/
(function($,undefined){
$.fn.bindAndTrigger = function( all, type, data, callback ) {
@cowboy
cowboy / feature_detection.js
Created May 5, 2010 19:22
feature detection for jd
window.alert && alert( 'omg hi!' );
set minX to 0
set minY to 22
tell application "Finder" to set screen_resolution to items 3 thru 4 of (get bounds of desktop's window)
set maxX to item 1 of screen_resolution
set maxY to item 1 of screen_resolution
--set maxX to (do shell script "echo $(defaults read /Library/Preferences/com.apple.windowserver) | sed 's/.*Width = \\([0-9]*\\);.*/\\1/'") as number
--set maxY to ((do shell script "echo $(defaults read /Library/Preferences/com.apple.windowserver) | sed 's/.*Height = \\([0-9]*\\);.*/\\1/'") as number) - 4
@cowboy
cowboy / Restart App.applescript
Created May 19, 2010 15:53
Restart App AppleScript
(*
* Restart App - v1.0 - 5/19/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*)
-- Usage:
@cowboy
cowboy / disable-backspace.js
Created May 26, 2010 15:09
Disable backspace in non-form elements
// Disable backspace in non-form elements in Chrome
// TODO: add input type, disabled and element contenteditable checks
(function(window){
window.addEventListener( 'keydown', handler, true );
window.addEventListener( 'keypress', handler, true );
function handler(e) {
!/^(?:textarea|input)$/i.test( e.target.nodeName ) && e.keyCode == 8 && e.preventDefault();
@cowboy
cowboy / php-json-heredoc.php
Created June 8, 2010 15:32
PHP "JSON heredoc" for inline data.. good? bad? comments? I'm trying to keep it simple.
<?php
## Parse query string.
$sb_league = $_GET['league'] ? strtolower( $_GET['league'] ) : 'all';
## Nav data, as a JSON heredoc. Much less verbose than PHP arrays!
$navs = json_decode(<<<JSON
{
"mlb": {
"title_link": "http://stats.boston.com/mlb/scoreboard.asp",
@cowboy
cowboy / irc.sh
Created June 9, 2010 02:45
an irssi "helper" script
#!/bin/bash
function print_usage {
cat <<PRINT_USAGE
Usage: $(basename $0) [ -start | -restart | -check | -info ]
-start start ssh session (connect to remote server)
-restart force-restart ssh session