Skip to content

Instantly share code, notes, and snippets.

class Promise<X> {
map<B>(onValue: (x: X) => B): Promise<B> {
AS.assertParameter(onValue, "onValue");
return new Promise<B>((resolve, reject) => {
this.parsePromise.then(x => {
resolve(onValue(x));
}, e => {
reject(e);
return Parse.Promise.as();
});
static fromPromise<S>(promise: Parse.Promise<S>): Parse.Promise<Maybe<S>> {
return promise.then(x => Maybe.fromValue(x));
}
// Example
Maybe.fromPromise(
this.stack.moment.tz(today, timezone).isoWeekday() === 1 ? generateWeeklyDigest(today) : Parse.Promise.as()
)
@msanders
msanders / smoothly_move_mouse.py
Created May 24, 2011 15:08
The autopy.mouse.smooth_move() function implemented in Python instead of C.
import autopy
import math
import random
import time
# The autopy.mouse.smooth_move() function implemented in Python instead of C.
def smoothly_move_mouse(dst_x, dst_y):
'''
Smoothly moves the cursor to the given (x, y) coordinate in a
straight line.
@msanders
msanders / NSColor+CGColor.m
Created November 20, 2010 16:11
Category for AppKit that converts an NSColor to a CGColor (ala UIColor in the iOS)
//
// NSColor+CGColor.m
//
// Created by Michael Sanders on 11/19/10.
//
#import "NSColor+CGColor.h"
@implementation NSColor (CGColor)