Skip to content

Instantly share code, notes, and snippets.

@damienklinnert
damienklinnert / promise_factory.js
Created February 20, 2013 10:32
a promise factory
/**
* dependencies
*/
var q = require('q');
/**
* lib
*/
@damienklinnert
damienklinnert / all-promise.js
Created February 19, 2013 08:37
What if we'd like to set off a bunch of async calls at once, and wait until they all finish (at various times, in any order) to set off the next promise in the chain? Q provides a simple method that takes an array of promises: Q.all()
function get_all_the_things(things) {
var the_promises = [];
for (var i = 0; i < things.length; i++) {
(function(i) { // keep i in scope
var deferred = Q.defer();
get_a_thing(things[i], function(result) {
deferred.resolve(result);
});
the_promises.push(deferred.promise);
@damienklinnert
damienklinnert / some.sh
Created January 15, 2013 19:13 — forked from tj/some.sh
function tabname {
printf "\e]1;$1\a"
}
if [ x`type -t cd` == "xfunction" ]; then
# previously wrapped cd
eval $(type cd | grep -v 'cd is a function' | sed 's/^cd/original_cd/' | sed 's/^}/;}/' )
else
# builtin
eval "original_cd() { builtin cd \$*; }"
(function () {
// this is the most important method. It creates a function
// that uses either jQuery.ajax or node request() to do
// async requests to the web.
//
// ThIS METHOD CREATES A FUNCTION DEPENDING ON THE ENVIRONMENT.
// AFTER INITIALIZING EVERYTHINGZZ AMAZZIN' FAST!!!111einself
AppDotNet
.getUser()
✓ returns a user object (827ms)
✓ returns an error when not authorized (730ms)
.followUser()
✓ returns a user object (835ms)
✓ returns an error when not authorized (747ms)
.unfollowUser()
✓ returns a user object (811ms)
✓ returns an error when not authorized (733ms)
var code = req.query.code, body = 'client_id=&client_secret=&grant_type=authorization_code&redirect_uri=https://localhost:3000/callback&code=' + code
options = {
method: 'POST',
uri: 'https://alpha.app.net/oauth/access_token',
form: body
};
request.post(options, function (err, res, body) {
console.log(body);
});
@damienklinnert
damienklinnert / example.jade
Created July 13, 2012 12:58
some example jade
!!! 5
html
head
meta(charset='utf-8')
title jadepreview
body
h1 jadepreview
h2
| Converts
a(href='http://jade-lang.com/') jade templates
@damienklinnert
damienklinnert / notifications.html
Created July 13, 2012 08:52
a simple test for html notifications from html5rocks at http://www.html5rocks.com/en/tutorials/notifications/quick/
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>notifications</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
$(function () {
if (window.webkitNotifications) {
console.log('Notifications are supported!');
@damienklinnert
damienklinnert / floating.html
Created July 12, 2012 23:44
a little script to create a input field with floating letters that are flying right in
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>floating search</title>
<style>
*:focus {
outline: 0;
}
* {
@damienklinnert
damienklinnert / ownstep.js
Created July 11, 2012 19:56
basic Step implementation
// this should work and give us 1 to 5
var Step = function (steps) {
// this only works with arrays, @todo better check
if (typeof steps !== 'object') {
return;
}
var currentStep = 0, lastStep = steps.length;