Skip to content

Instantly share code, notes, and snippets.

View dennisvennink's full-sized avatar

Dennis Vennink dennisvennink

  • Rotterdam, The Netherlands
View GitHub Profile
@dennisvennink
dennisvennink / gist:1359808
Created November 12, 2011 00:46
Better JavaScript code folding in TextMate.

For some strange reason, JavaScript code folding in TextMate is limited to functions; leaving out JSON, simple statements delimited by brackets, and arrays.

In order to change this behaviour, open up the Bundle Editor (Bundles → Bundle Editor → Show Bundle Editor). From the dropdown menu in the top left corner select 'Languages', expand 'JavaScript' (click the triangle) and choose the JavaScript Language Grammar (the item with the L next to it). Find 'foldingStartMarker' and 'foldingStopMarker' in the list on the right and replace their values with:

foldingStartMarker = '\{\s*$|\[\s*$|\(\s*$';

foldingStopMarker = '^\s*}|^\s*]|^\s*)';

@dennisvennink
dennisvennink / endian.h
Created April 23, 2013 22:00
Retrieves the host's byte order. Requires C99.
#ifndef ENDIAN_H
#define ENDIAN_H
#ifndef LITTLE_ENDIAN
#define LITTLE_ENDIAN 0
#endif
#ifndef BIG_ENDIAN
#define BIG_ENDIAN 1
#endif
#!/usr/bin/env runhaskell
import Data.Either (either)
import Network.HTTP (simpleHTTP, getRequest, rspBody)
main :: IO ()
main = simpleHTTP (getRequest "http://www.wikipedia.org/") >>= print . either show rspBody
module Main where
import Prelude hiding (until)
-- import System.CPUTime
-- 2.1 Semantic Domains
type Time = Double
type Behavior a = Time -> a
type Event a = (Time, a)
-- type Events a = [Event a]
@dennisvennink
dennisvennink / gist:1f0bcfbd3da55fcd7ec4
Created March 23, 2015 19:26
Object.prototype.extend
Object.prototype.extend = function (object) {
var Constructor = object.initialize;
Constructor.prototype = Object.create(this.prototype);
Object.keys(object).forEach(function (key) {
if (key !== "initialize") {
Constructor.prototype[key] = object[key];
}
});
@dennisvennink
dennisvennink / statusBarHidden.md
Created May 2, 2016 05:09
iOS 9 statusBarHidden Replacement

Since iOS 9 UIApplication.sharedApplication().statusBarHidden is deprecated. Use UIApplication.sharedApplication().statusBarFrame.size == CGSizeZero instead.

let s1 = [1, 2]
let s2 = [3, 4, 5]
func product <Sequence1: Sequence, Sequence2: Sequence> (_ s1: Sequence1, _ s2: Sequence2) -> AnySequence<(Sequence1.Element, Sequence2.Element)> {
return AnySequence(
s1.flatMap { e1 in
s2.map { e2 in
print(e1, e2)
return (e1, e2)
}
/// The iterator for `LazyAppendSequence`.
public struct LazyAppendIterator <BaseIterator1: IteratorProtocol, BaseIterator2: IteratorProtocol>: IteratorProtocol
where BaseIterator1.Element == BaseIterator2.Element {
public typealias Element = BaseIterator1.Element
private var baseIterator1: BaseIterator1
private var baseIterator2: BaseIterator2
private var reachedEndOfBaseIterator1 = false
private var reachedEnd = false
/// The iterator for `LazyCycleSequence`.
public struct LazyCycleIterator <BaseSequence: Sequence>: IteratorProtocol {
public typealias Element = BaseSequence.Iterator.Element
private let baseSequence: BaseSequence
private var baseIterator: BaseSequence.Iterator
internal init (_ baseSequence: BaseSequence) {
self.baseSequence = baseSequence
self.baseIterator = self.baseSequence.makeIterator()
import XCTest
@testable import SetUnion
final class SetUnionTests: XCTestCase {
let a1: [Set<Int>?] = [[1, 2], [2, 3], nil]
let n = 100000
func testX1 () {
self.measure {
for _ in 1...self.n {