Skip to content

Instantly share code, notes, and snippets.

View k0nserv's full-sized avatar

Hugo Tunius k0nserv

View GitHub Profile
func _if(condition: BooleanType, action: () -> ()) {
if condition {
action()
}
}
_if(1 < 2) {
println("1 is less than 2")
}
@k0nserv
k0nserv / async.swift
Created June 5, 2014 15:50
Conccurency in swift?
println("Before async")
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)
, {
println("async")
})
println("After async")
def hours(open, close)
(0..6).to_a.map do |x|
{
start: x * 24 + open,
end: x * 24 + close
}
end
end
# Could be binary search
@k0nserv
k0nserv / person.h
Last active August 29, 2015 13:56
Setter with side effects
#import <Foundation/Foundation.h>
@interface Person
@property(nonatomic, copy) NSString *firstName;
@property(nonatomic, copy) NSString *lastName;
@property(nonatomic, readonly, strong) NSString *fullName
@end
@k0nserv
k0nserv / lazy-init.m
Last active August 29, 2015 13:56
Lazy init. Initialize the value of a variable only when it's first needed
@interface MyClass()
// Lazy inits are perfect for readonly values
// Note that strong can be used instead of copy here because
// we control the creation of the array and don't have to worry about
// being passed a mutable version
@property(nonatomic, readonly, strong) NSArray *values;
@end
@implementation MyClass
scrollId = setInterval(function () { window.scrollBy(0, 5);}, 2);
@k0nserv
k0nserv / with-example.js
Created December 30, 2013 11:08
With example in javascript. Given that no other definition of sin exists in scope the value of x will be 1.
with (Math) {
var x = sin(PI / 2); //1
}
var f = new Function("x",
"with(Math) {" +
"return " + input.value +
";}");
@k0nserv
k0nserv / gist:8151008
Created December 27, 2013 18:48
Slate configuration
# This is the default .slate file.
# If no ~/.slate file exists this is the file that will be used.
config defaultToCurrentScreen true
config windowHintsShowIcons true
config windowHintsIgnoreHiddenWindows false
config windowHintsSpread true
config nudgePercentOf screenSize
config resizePercentOf screenSize
config windowHintsDuration 10000
#!/bin/bash
(: > .irssi/fnotify ; tail -f .irssi/fnotify | \
while read heading message; do \
/usr/local/bin/growlnotify -t "${heading}" -m "${message}"; \
done)