Skip to content

Instantly share code, notes, and snippets.

@cowboy
cowboy / understanding-javascript.md
Created November 18, 2011 16:26
Outline for a new Bocoup JavaScript class

Understanding JavaScript

This 3-day course will expand on the introductory knowledge that developers have regarding the use of JavaScript. Attendees will learn best practice approaches on general JavaScript topics such as inheritance, code organization, type checking, performance and testing, as well as implementation-specific topics such as the window object, the DOM and the debugging console. In addition, hands-on workshops and discussions will be utilized to enable attendees to experiment and learn first-hand.

In this workshop, your team will learn:

  • JavaScript Isn't Just in the Browser
  • Debugging with console
  • Variables and Identifiers
  • Statements
@cowboy
cowboy / jquery.ba-simple-ajax-mocking.js
Created November 16, 2011 20:24
Simple jQuery (1.5+) AJAX Mocking (requires JSON, tested in jQuery 1.7))
/*!
* Simple jQuery (1.5+) AJAX Mocking - v0.1.1 - 2012-08-17
* http://benalman.com/
*
* Copyright (c) 2012 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($) {
@cowboy
cowboy / battlelog-bf3-misc.js
Created October 29, 2011 01:09
EA Battlelog BF3 misc hacks
/* EA Battlelog BF3 misc hacks
* http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */
// What does it do?
//
// * Auto-retries server join so you don't have to spam the button.
// (close the Game Manager error popup to cancel the auto-join)
//
// What might it do in the future?
@cowboy
cowboy / annoy.js
Created October 27, 2011 19:36
Wow, I remember making this.. back in 2001? Like my Britney Spears reference on line 25?
var isIE = document.all?true:false;
var isNS4 = document.layers?true:false;
var isNS6 = (document.getElementById&&!document.all)?true:false;
if (isNS4) document.onkeydown = getKey;
document.onselectstart = falseReturn;
document.oncontextmenu = falseReturn;
@cowboy
cowboy / overloading.js
Created October 26, 2011 18:44
Method overloading for JavaScript
// Don't actually use this. Ever. Thx.
(function fn() {
var slice = fn.call.bind([].slice);
Function.overload = function(obj) {
return function() {
var key = slice(arguments).map(function(a) { return typeof a; }).join(', ');
if (obj[key]) {
@cowboy
cowboy / argtest.js
Created October 24, 2011 18:38
Testing to see if an argument has been omitted
function joinArray(arr, separator) {
// if (typeof separator === "undefined") {
// if (separator === undefined) {
// if (arguments.length === 1) {
if (separator == null) {
separator = " - ";
}
return arr.join(separator);
}
joinArray([1, 2, 3]) // "1 - 2 - 3"
@cowboy
cowboy / twitpic_flickr.php
Created October 18, 2011 14:31
Twitpic-Flickr bridge. Now I can upload photos to Flickr via my iPhone Twitter app, yay!
<?PHP
# Twitpic-Flickr bridge - v0.1pre - 10/18/2011
# http://benalman.com/
#
# Copyright (c) 2011 "Cowboy" Ben Alman
# Dual licensed under the MIT and GPL licenses.
# http://benalman.com/about/license/
# There's no way I'm writing all the Flickr stuff myself.
@cowboy
cowboy / bad-bad-bad.js
Created October 15, 2011 14:44
Shitty destructors for JavaScript!
function Thing(context, name) {
this.context = context;
this.name = name;
this.init();
this.startTheWorstGarbageCollectorEver();
}
Thing.prototype.startTheWorstGarbageCollectorEver = function() {
var id = setInterval(function() {
if (!this.context[this.name]) {
[
"",
"",
"",
"",
"",
"",
"",
"",
"",
@cowboy
cowboy / jquer.ba-wtf-animation.js
Created September 29, 2011 17:07
jQuery: a little WTF text animation :)
// Iterate over a bunch of elements.
$(":header, p, li").each(function() {
// The current element.
var elem = $(this);
// A copy of the current element that will take its place in the DOM during
// the animation.
var copy = elem.clone().replaceAll(elem);
// The element's text content. To be animated, character-by-character.
var text = copy.text();