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
// Converts degrees to radians. | |
#define degreesToRadians(angleDegrees) (angleDegrees * M_PI / 180.0) | |
// Converts radians to degrees. | |
#define radiansToDegrees(angleRadians) (angleRadians * 180.0 / M_PI) |
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
function getBoundsAtLatLngWithZoom(map, center, zoom) { | |
var p = map.getProjection(); | |
if (!p) { | |
return null; | |
} | |
var el = $(map.getDiv()); | |
var zf = Math.pow(2, zoom) * 2; | |
var dw = (el.width() | 0) / zf; | |
var dh = (el.height() | 0) / zf; | |
var cpx = p.fromLatLngToPoint(center); |
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
function wrapLineAtDivisibleColumn(line) { | |
var column = 80; | |
while (line.length / column % 1) --column; | |
return line.replace(new RegExp('.{' + column + '}(?!$)', 'g'), '$&\n'); | |
} |
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
// | |
// TargetClosure is a bridge from closures to objc targets/selectors | |
// Create a TargetClosure with a closure and pass it as the target, then pass target.selector as the selector. | |
// | |
// Example: | |
// | |
// let target = TargetClosure { doYourThing() } | |
// oldSchoolFunction(target: target, action: target.selector) | |
// |
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
const encode_regex = /[\+=\/]/g; | |
const decode_regex = /[\._\-]/g; | |
// Buffer -> Base64 String -> Url Safe Base64 String | |
export function encode(buffer) { | |
return buffer.toString('base64').replace(encode_regex, encodeChar); | |
} | |
// Url Safe Base64 String -> Base64 String -> Buffer | |
export function decode(string) { |
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
function insertAt(arr, val, i) { | |
arr.splice(i, 0, val); | |
} | |
function removeAt(arr, i) { | |
return arr.splice(i, 1).length === 1; | |
} | |
function genericInsertAt(arr, val, i) { | |
Array.prototype.splice.call(arr, i, 0, val); | |
} |
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
function removeSubstring(string, substring) { | |
let result = string; | |
if (substring) { | |
let index = result.indexOf(substring); | |
while (index >= 0) { | |
result = result.substring(0, index) + result.substring(index + substring.length); | |
index = result.indexOf(substring, index); | |
} | |
} | |
return result; |
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
@interface NSIndexSet (Operations) | |
// http://en.wikipedia.org/wiki/Union_(set_theory) | |
- (NSIndexSet *)unionWith:(NSIndexSet *)other; | |
// http://en.wikipedia.org/wiki/Intersection_(set_theory) | |
- (NSIndexSet *)intersectionWith:(NSIndexSet *)other; | |
// http://en.wikipedia.org/wiki/Complement_(set_theory)#Relative_complement | |
- (NSIndexSet *)relativeComplementIn:(NSIndexSet *)universe; |
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
public class Queue<T> { | |
public private(set) var size: Int = 0 | |
private var head: QueueNode<T>? = nil | |
private var tail: QueueNode<T>? = nil | |
public func enqueue(_ value: T) { | |
let newTail = QueueNode(value: value) | |
if let oldTail = tail { | |
newTail.prev = oldTail | |
oldTail.next = newTail |
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
import Queue from './queue'; | |
const STATE_PENDING = 'pending'; | |
const STATE_RESOLVED = 'resolved'; | |
const STATE_REJECTED = 'rejected'; | |
const states = new WeakMap(); | |
const values = new WeakMap(); | |
const queues = new WeakMap(); |
NewerOlder