Skip to content

Instantly share code, notes, and snippets.

View bendytree's full-sized avatar

Josh Wright bendytree

View GitHub Profile
@bendytree
bendytree / Example.m
Last active December 10, 2015 06:28
Example of OKDate
// create a date
OKDate* a = [OKDate dateWithNumbers:@[2013, 6, 16, 8, 0, 0]];
[a addDays:2]; //add 2 days
a.minute = 30; //set minutes to 30
// render to "2013-06-18 8:30AM"
NSString* b = [a format:@"yyyy-MM-dd H:mma"];
// parse a date
@bendytree
bendytree / UIViewController+AlwaysAnimation.h
Created May 19, 2013 15:13
Adds an animation to a view. Then monitors `viewWillAppear` and `appWillEnterForeground` to re-add the animation whenever necessary.
#import <UIKit/UIKit.h>
@interface UIViewController (AlwaysAnimation)
- (void) alwaysAnimate:(CABasicAnimation*)animation view:(UIView*)view;
@end
@bendytree
bendytree / NSWeakTimer.m
Created May 29, 2013 23:41
A starting point for an NSTimer that has a weak reference to its target. ARC only.
//
// NSWeakTimer.m
#import "NSWeakTimer.h"
@interface NSWeakTimerTarget : NSObject
@property (assign) id target;
@property (assign) SEL selector;
@property (assign) NSTimer* timer;
@bendytree
bendytree / jquery.pubsub.js
Last active December 19, 2015 15:58 — forked from rwaldron/jquery.ba-tinypubsub.js
jQuery Tiny Pub/Sub (Ridiculous)
/*!
* jQuery Tiny Pub/Sub - v0.X - 11/18/2010
* http://benalman.com/
*
* Original Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*
* Made awesome by Rick Waldron
*
@bendytree
bendytree / ALAssetRepresentation+SaveToDisk.m
Created December 17, 2013 23:03
Objective-c category for saving an `ALAssetRepresentation` to disk using a buffer (instead of reading the whole thing into memory).
//
// ALAssetRepresentation+SaveToDisk.m
//
// Adapted from http://damir.me/import-video-from-alasset
//
// Created by Joshua Wright<@BendyTree> on 12/17/13.
// http://www.joshwright.com
//
#import "ALAssetRepresentation+SaveToDisk.h"
@bendytree
bendytree / bootstrap-select-setStylePatch.js
Created April 2, 2014 14:03
A patch for bootstrap-select v1.5.4 to fix the setStyle function. Currently setStyle doesn't properly keep track of what style was set previously, so the old style is never removed.
(function(){
//create a select so we can access the selectpicker
var $div = $("<div><select></select></div>");
//get the prototype
var prototype = $div.find("select").selectpicker().data("selectpicker").constructor.prototype;
//keep track of the original setStyle
@bendytree
bendytree / highcharts-trend.js
Created April 11, 2014 19:47
HighCharts Trend Line Series Maker
/**
* Originally this code was from:
* https://github.com/virtualstaticvoid/highcharts_trendline
*
* But it dropped a lot in the global namespace, so I added a closure and exposed:
*
* window.BuildHighChartsTrendLineSeriesFromSeries(series);
*
* If you want, I can make the name longer.
*
@bendytree
bendytree / object-id-as-string.js
Last active September 2, 2016 10:15
A custom SchemaType for Mongoose that treats `_id` as a string on the mongoose document, but as an ObjectId in the database.
/*
* ObjectIdAsString
*
* A SchemaType for MongooseJS that acts exactly like an ObjectId except that
* the field is handled as a string in the mongoose document.
*
* NOTE: If a document is fetched with `lean:true` then the field is not converted
* to a string. Ugh.
*
* //register the type
@bendytree
bendytree / document-validation.js
Created October 10, 2014 00:40
Use standard NodeJS callbacks to validate MongooseJS documents.
/**
* Josh Wright <@BendyTree>
* http://www.joshwright.com
*
* MIT
*
*
* Standard MongooseJS validation looks like this:
*
* schema.path("email").validate(function(val, callback){
var async = require('async');
var https = require('https');
async.times(5, function(n, cb){
var options = { host: 'www.google.com', port: 443, path: '', method: 'GET' };
var startTime = new Date().getTime();
var req = https.request(options, function(res) {
var ms = new Date().getTime() - startTime;
console.log(ms+"ms");
res.on('data', function(){ });