Skip to content

Instantly share code, notes, and snippets.

View mason-stewart's full-sized avatar
🎃
無敵

Mason Stewart mason-stewart

🎃
無敵
  • Bookshop.org
  • NeW eNgLaNd
View GitHub Profile
@mason-stewart
mason-stewart / Excercise 2
Created March 3, 2011 20:18
just testing out some closures
countdown = (function(){
var index;
function log(){
console.log(index);
}
function iterate(){
log();
if(index>1) setTimeout(iterate, 1000);
@mason-stewart
mason-stewart / OO v. !00
Created March 3, 2011 21:09
more testing
<script>
// Exercise 1 - OO || !OO
// Define a data structure for cars (make and color), and a function
// that logs a string like "I'm a red Mercedes" to the console.
// Make two versions: a functional version, and a object-oriented version.
// Example call for functional version:
logCar({ color: 'blue', make: 'BMW' });
// Example call for OO version:
document.getElementById('the_div').addEventListener(
'click', function(){ log('the_div!') }, true);
document.getElementById('the_list').addEventListener(
'click', function(){ log('the_list!') }, false);
document.getElementById('the_item').addEventListener(
'click', function(){ log('the_item!') }, true);
document.getElementById('the_div').addEventListener(
'click', function(){ log('the_div!') }, false);
document.getElementById('the_list').addEventListener(
'click', function(){ log('the_list!') }, false);
document.getElementById('the_item').addEventListener(
'click', function(){ log('the_item!') }, false);
document.getElementById('the_div').addEventListener(
'click', function(){ log('the_div!') }, false);
document.getElementById('the_list').addEventListener(
'click', function(){ log('the_list!') }, false);
document.getElementById('the_item').addEventListener(
'click', function(){ log('the_item!'); event.stopPropagation(); }, false);
<body id="body">
<div id="the_div">
<ul id="the_list">
<li id="the_item">Click me!</li>
</ul>
</div>
<p id="log"></p>
<script type="text/javascript" charset="utf-8">
@mason-stewart
mason-stewart / prototypes-in-js.js
Created April 1, 2011 18:50
It doesn't get anymore exciting that this.
function AwesomeBand(name) {
this.name = name;
}
AwesomeBand.prototype.name = 'Iron Maiden';
var band = new AwesomeBand('Ke$ha');
band.name; //prints 'Ke$ha'
@mason-stewart
mason-stewart / gist:960916
Created May 7, 2011 22:33
How many of them there Micro libraries are there?!
//Run this in the console at http://microjs.com to see how much it would weigh if you used 'em all! ;D
var theSizes = document.getElementsByTagName("div");
var total = 0;
var incorrectClass = 0;
var i = theSizes.length;
var current;
while (i--) {
if ( theSizes[i].className == "size" ) {
@mason-stewart
mason-stewart / gist:998038
Created May 29, 2011 18:52
Automatically show new tweets on Twitter.com
// Sometimes, when I'm in my office but not sitting at my computer, I want to glance over at new tweets
// in my feed at http://twitter.com. I find myself annoyed with having to click "Show X new tweets"
// button that pops up. Running this in the console solves my problem.
setInterval(function(){$("#new-tweets-bar").click()}, 5000);
@mason-stewart
mason-stewart / gist:1012550
Created June 7, 2011 16:02
Colors and shiz for .bash_profile
# slightly different version of the awesome stuff found at http://digitalformula.net/articles/pimp-my-prompt-like-paul-irish
# enable the git bash completion commands
source ~/git-completion.sh
# enable git unstaged indicators - set to a non-empty value
GIT_PS1_SHOWDIRTYSTATE="."
# enable showing of untracked files - set to a non-empty value
GIT_PS1_SHOWUNTRACKEDFILES="."