Skip to content

Instantly share code, notes, and snippets.

View kulte's full-sized avatar

Zachary Friedman kulte

View GitHub Profile
@kulte
kulte / spotifyapigist.js
Created March 7, 2012 16:03
Spotify API
// Loading a Track
var track = Track.fromURI(uri, function(track) {
console.log(track.name + " loaded!");
if (track.playable)
// handle case in which some tracks are not playable
[...]
});
// Loading an Album
@kulte
kulte / gitgoggles.js
Created May 30, 2012 16:33
gitgoggles.js
var GitGoggles = {
getRepos: function(callback) {
this._get('repositories', callback);
},
getRepo: function(repo, callback) {
this._get('repository/' + repo, callback);
},
@kulte
kulte / iOSRecipes15-1.m
Created December 7, 2012 23:56
iOS Recipes 15-1
static NSString *CellID = @"CustomCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
UIImage *rainbow = [UIImage imageNamed:@"rainbow"];
UIImageView *mainImageView = [[UIImageView alloc] initWithImage:rainbow];
UIImageView *otherImageView = [[UIImageView alloc] initWithImage:rainbow];
CGRect iconFrame = (CGRect) { { 12.0, 4.0 }, rainbow.size };
@kulte
kulte / KTEManagedTableViewCell.h
Created December 8, 2012 20:48
Smart UITableViewCell subclass to abstract away scattered cell boilerplate.
@interface KTEManagedTableViewCell : UITableViewCell { }
+ (id)cellForTableView:(UITableView *)tableView;
+ (id)cellForTableView:(UITableView *)tableView fromNib:(UINib *)nib;
+ (NSString *)cellIdentifier;
- (id)initWithCellIdentifer:(NSString *)cellID;
@end
@kulte
kulte / KTEExampleTableViewController.m
Created December 8, 2012 21:40
Example table view controller code for implementing KTEManagedTableViewCell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
KTEDoubleRainbowCell *cell = [KTEDoubleRainbowCell cellForTableView:tableView];
cell.mainLabel.text = [self.quotes objectAtIndex:indexPath.row];
return cell;
}
// A module that can be mixed in to *any object* in order to provide it with
// custom events. You may bind with `on` or remove with `off` callback
// functions to an event; `trigger`-ing an event fires all callbacks in
// succession.
//
// var object = {};
// _.extend(object, Backbone.Events);
// object.on('expand', function(){ alert('expanded'); });
// object.trigger('expand');
//
$(document).ready(function() {
module("Backbone.Events");
test("on and trigger", 2, function() {
var obj = { counter: 0 };
_.extend(obj,Backbone.Events);
obj.on('event', function() { obj.counter += 1; });
obj.trigger('event');
equal(obj.counter,1,'counter should be incremented.');
Board.prototype.isWinner = function () {
if ((this.state[0] == this.state[1] == this.state[2] == 1)
|| (this.state[3] == this.state[4] == this.state[5] == 1)
|| (this.state[6] == this.state[7] == this.state[8] == 1)
|| (this.state[0] == this.state[3] == this.state[6] == 1)
|| (this.state[1] == this.state[4] == this.state[7] == 1)
|| (this.state[2] == this.state[5] == this.state[8] == 1)
|| (this.state[0] == this.state[4] == this.state[8] == 1)
|| (this.state[1] == this.state[4] == this.state[6] == 1)) {
return 1;
describe('minimax', function () {
var INFINITY = 1.7976931348623157E+10308;
var N_INFINITY = -1.7976931348623157E+10308;
var COMPUTER = 1;
var HUMAN = 2;
it('should return INFINITY when computer has won', function () {
var state = [1, 1, 1, -1, -1, -1, -1, 2, 2];
var board = new Board(state);
describe('isWinner', function () {
var COMPUTER = 1;
var HUMAN = 2;
it('should return COMPUTER if the computer has won', function () {
var state = [1, 1, 1, -1, -1, -1, -1, 2, 2];
var board = new Board(state);
assert.equal(board.isWinner(), COMPUTER); /* assertion passes */
})