This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// node-jquery - port of jquery 1.4.2 (http://jquery.com/)to node.js by alex bosworth (http://alexbosworth.net/) | |
function now() { | |
return (new Date).getTime(); | |
} | |
var window = {}, | |
jsc = now(), | |
rscript = /<script(.|\s)*?\/script>/gi, | |
rselectTextarea = /select|textarea/i, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Alex Bosworth | |
* | |
* A straightforward S3 library | |
* | |
* USE: var s3 = new S3(AWS_KEY, AWS_SECRET, {defaultBucket : MY_BUCKET}); | |
* s3.put(KEY, DATA); | |
* s3.get(KEY).on('success', function(data) { console.log(data); }); | |
* (more operations: buckets, info, list) | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// for node-jquery.js (http://gist.github.com/599831) | |
// add this to a script to show how long it took to complete | |
process.on('exit', $.proxy(function () { | |
var sec = Math.round((new Date().getTime() - this.start.getTime()) / 1000); | |
console.log('completed', 'in ' + sec + ' seconds'); | |
}, {start:new Date()})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Alex Bosworth | |
* | |
* A straightforward S3 library | |
* | |
* USE: var s3 = new S3(AWS_KEY, AWS_SECRET, {defaultBucket : MY_BUCKET}); | |
* s3.put(KEY, {data:{},headers:{}}, [bucket]); | |
* s3.get(KEY, [bucket]).on('success', function(data) { console.log(data); }); | |
* (more operations: buckets, info, list) | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
require('fs').readFile('image.png',function(err, data){ | |
console.log(require('crypto').createHash('sha1').update(data).digest('hex')) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Extend the Underscore object with the following methods */ | |
// Rate limit ensures a function is never called more than every [rate]ms | |
// Unlike underscore's _.throttle function, function calls are queued so that | |
// requests are never lost and simply deferred until some other time | |
// | |
// Parameters | |
// * func - function to rate limit | |
// * rate - minimum time to wait between function calls | |
// * async - if async is true, we won't wait (rate) for the function to complete before queueing the next request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Deferreds are useful for chaining: doSomething().success(doSomethingElse).failure(stopStuff); | |
function Deferred() { | |
this._successCbk = function() {}, | |
this._failureCbk = function() {}; | |
return this; | |
} | |
Deferred.prototype.success = function(cbk) { | |
this._successCbk = cbk; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (NSDictionary *)downloadableFonts | |
{ | |
CTFontDescriptorRef desc = CTFontDescriptorCreateWithAttributes((CFDictionaryRef)@{(id)kCTFontDownloadableAttribute : (id)kCFBooleanTrue}); | |
CFArrayRef matchedDescs = CTFontDescriptorCreateMatchingFontDescriptors(desc, NULL); | |
NSArray *array = (__bridge NSArray *)matchedDescs; | |
NSMutableDictionary *families = [NSMutableDictionary dictionary]; | |
for (UIFontDescriptor *fontDescriptor in array) { | |
NSString *familyName = fontDescriptor.fontAttributes[UIFontDescriptorFamilyAttribute]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while true; do date; sleep 5; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// First Topological Sort in Apple's new language Swift | |
// Updated on 10/30/2016 to account for the newest version of Swift (3.0) | |
// Michael Recachinas | |
enum TopologicalSortError : Error { | |
case CycleError(String) | |
} | |
/// Simple helper method to check if a graph is empty | |
/// - parameters: | |
/// - dependency_list: a `Dictionary<String, [String]>` containing the graph structure |
OlderNewer