Skip to content

Instantly share code, notes, and snippets.

Ben Alman cowboy

Block or report user

Report or block cowboy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:188817
// API
// all deparam methods return an object
$.deparam( params, coerce ) // deserialize params string, optionally coercing true, false, undefined, numbers
$.deparam.qs( coerce ); // get document query string as object
$.deparam.hash( coerce ); // get document hash as object
$.deparam.qs( params_or_url, coerce ); // get params from url or params string as object
View gist:189027
// API
// history, window.onhashchange
$.history.add( params, merge_mode ); // set new 'state' (into location.hash, triggers hashchange event)
$.history.retrieve( key, coerce ); // get current 'state' (from location.hash, wrapper for $.deparam.hash)
$(window).bind( 'hashchange', function(e){
e.hash; // the current 'state' as normalized hash string
e.retrieve(); // like $.history.retrieve but for this specific state
View gist:189255
function get_hash() {
var loc = document.location;
return loc.hash ? loc.href.replace( /^.*\#/, '' ) : '';
}
if ( 0 ) {
var esh = $.event.special.hashchange = {
setup: function(){
console.log( 'setup' );
$(this).bind( 'hashchange', esh.handler );
View gist:190474
// API for jQuery BBQ: Back Button & Query Library
// ==== HISTORY, window.onhashchange ====
// set new 'state' to location.hash (triggers hashchange event)
$.history.add( params, merge_mode );
// get current 'state' from location.hash (wrapper for $.deparam.fragment)
$.history.retrieve( key, coerce );
View gist:194959
// proposed 'until' extension to jQuery.dir to support 'nextUntil' and 'prevUntil'
// suggested by LaC_OS_X
jQuery.dir = function( elem, dir, until ){
var matched = [], cur = elem[dir];
while ( cur && cur != document ) {
if ( cur.nodeType == 1 )
matched.push( cur );
if ( until && jQuery( cur ).is( until ) )
return matched;
View bash_prompt.sh
#!/bin/bash
# My bash prompt - Ben Alman
# Source: http://gist.github.com/194971
# Screenshot: http://www.flickr.com/photos/rj3/3959554047/sizes/o/
#
# In my home folder, [user@host:directory] on the 1st line, [HH:MM] on the 2nd line:
#
# [cowboy@benalman:~]
# [19:55:20] $
View jQuery.fn.nextUntil.js
// This has moved! Get it here:
// http://github.com/cowboy/jquery-misc/blob/master/jquery.ba-nextUntil.js
jQuery.fn.nextUntil = function( expr ) {
var elems = [];
this.nextAll().each(function(){
return jQuery(this).is( expr )
? false
: elems.push( this );
@cowboy
cowboy / gyazo.php
Created Oct 6, 2009
PHP upload for Gyazo
View gyazo.php
<?PHP
/*
* PHP upload for Gyazo - v1.2.1 - 3/13/2011
* http://benalman.com/news/2009/10/gyazo-on-your-own-server/
*
* Copyright (c) 2011 "Cowboy" Ben Alman
* Licensed under the MIT license
* http://benalman.com/about/license/
*/
View gist:204177
// Potentially part of the jQuery urlInternal plugin
(function($){
// Method: jQuery.isUrlFragment
//
// Test whether or not a URL is a fragment. The URL can either begin with #
// or be a partial URL or full URI, that when navigated to, only changes the
// document.location.hash.
//
@cowboy
cowboy / jquery-param.js
Created Oct 9, 2009
jQuery.param, pulled out of 1.4.2, for use with 1.3.2 or earlier.
View jquery-param.js
// jQuery.param, pulled out of 1.4.2
(function($){
var r20 = /%20/g;
// Serialize an array of form elements or a set of
// key/values into a query string
$.param = function( a, traditional ) {
var s = [];
You can’t perform that action at this time.