Skip to content

Instantly share code, notes, and snippets.

@mattpat
mattpat / common.js
Created February 13, 2012 03:10
Just the Basics, for people who hate JavaScript libraries (like me!)
/*
I've never been a fan of JavaScript frameworks.
These three functions are all I ever really need!
*/
/* convenient DOM element lookup */
function $(el){
return document.getElementById(el);
}
@mattpat
mattpat / BTOverlayView.m
Created October 30, 2011 03:04
How Bowtie accomplishes a movable window with a WebView.
// BTOverlayView.h
@interface BTOverlayView : NSView {
NSWindow *mainWindow;
NSPoint initialLocation;
NSTrackingArea *tArea;
BOOL frameChanged;
}
@mattpat
mattpat / example.js
Created October 2, 2011 21:40
Original
for (var i = 0; i < 10; i++){
elements[i].addEventListener('click', function(){
alert(i);
});
}
@mattpat
mattpat / example.js
Created October 2, 2011 21:36
How to avoid accidental closures in loops.
function makeAlerter(x){
return function(e){
alert(x);
};
}
for (var i = 0; i < 10; i++)
elements[i].addEventListener('click', makeAlerter(i));
@mattpat
mattpat / gist:956593
Created May 5, 2011 05:42
Closure black magic
for x in entrySelectors:
datetext = x.select('.//pubDate/text()').extract()
datetext = u'0000-00-00 00:00:00+00:00' if len(datetext)<1 else dateutil.parser.parse(datetext[0])
templist = x.select('.//link["nytimes.com/"]/text()').extract()
if len(templist)>0 :
def cb(tx):
return lambda r: self.check_call(r, tx)
links.append(templist[0])
#tx = str(copy.deepcopy(datetext))
slides = [
function(){
spinner(spinnerContainer);
},
function(){
setOpacity("bootScreen", 1);
},
function(){
setOpacity("blah", 0);
setOpacity("blahblah", 0.5);
slide(function(){
spinner(spinnerContainer);
});
slide(function(){
setOpacity("bootScreen", 1);
});
slide(function(){
setOpacity("blah", 0);
setOpacity("blahblah", 0.5);
doSomethingElse("yaddayadda", 42);
#!/bin/bash
# Written on 04/20/10 by Carter Allen
# Copyright Opt-6 Products, LLC, 2010
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#pragma mark Actions
- (IBAction)callMyMom:(id)sender
{
// Update the text view, disable the button
[textView insertText:@"Time to call Mom!\n"];
[self disableButton:sender];
// We're going to make an NSDictionary containing
// the button, so we can pass it to our timer
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:sender forKey:@"button"];
# Put this in your .profile
# Now, the `ts` command will give you the UNIX timestamp
alias ts="date +%s"