Skip to content

Instantly share code, notes, and snippets.

View hallski's full-sized avatar

Mikael Hallendal hallski

View GitHub Profile
/* The MIT License
Copyright (c) 2009 Mikael Hallendal
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
#
# rb_main.rb
# MacRubyTest
#
# Loading the Cocoa framework. If you need to load more frameworks, you can
# do that here too.
framework 'Cocoa'
# Loading all the Ruby project files.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Colors</key>
<dict>
<key>Background</key>
<string>0.028 0.089 0.104</string>
<key>InsertionPoint</key>
<string>0.926 0.940 0.758</string>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>0.052 0.489 0.482 1</string>
<key>DVTConsoleDebuggerInputTextFont</key>
<string>Menlo-Bold - 11.0</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>0.432 0.325 0.276 1</string>
/*
* debug.c
* Easy Shop
*
* Created by Mikael Hallendal on 2010-08-18.
*
*/
#include "debug.h"
@hallski
hallski / TCRACSocket.m
Created May 6, 2012 22:46
TCRACSocket with subjects
#import "TCRACSocket.h"
#import <AsyncSocket.h>
@interface TCRACSocket ()
@property(strong,readwrite) AsyncSocket *sock;
@property(strong) RACSubject *connectSubject;
@property(strong) RACSubject *linesSubject;
@end
@implementation TCRACSocket
- (id<RACSignal>)startWithTrigger:(id<RACSignal>)signalTrigger
{
return [RACSignal createSignal:^(id<RACSubscriber> subscriber) {
__block RACDisposable *selfDisposable = nil;
__block RACDisposable *triggerDisposable = [signalTrigger subscribe:[RACSubscriber subscriberWithNext:^(id x) {
selfDisposable = [self subscribeNext:^(id x2) {
[subscriber sendNext:x2];
} error:^(NSError *error) {
[subscriber sendError:error];
} completed:^{
@hallski
hallski / gist:4240823
Created December 8, 2012 15:56
Toggle terminal
set appName to "Terminal" -- openTerminalWindow requires Terminal
set newWindowScript to "tmux -2" -- set to "" to just run the shell
if not isRunning(appName) then tell application appName to activate
if numberOfWindows(appName) is 0 then
openTerminalWindow(appName, newWindowScript)
foregroundApp(appName)
else
if isCurrentApp(appName) then
@hallski
hallski / Partial.swift
Last active August 29, 2015 14:02
Simple implementation of a partial function in Swift
func partial<T, S, A>(f: ((T, S) -> A), t : T) -> (S -> A) {
return { (s:S) in
return f(t, s)
}
}
// Bind the first argument
let addTwenty = partial(+, 20)
// Call the new function
@hallski
hallski / IfElseExpression.swift
Last active August 29, 2015 14:02
Simple ifElse-expression in Swift to try out @auto_closure
func ifElse<T> (f: @auto_closure() -> Bool, ifValue: T, elseValue: T) -> T {
if f() {
return ifValue;
} else {
return elseValue;
}
}
let foo = ifElse(12 + 25 > 20, "Yep", "No") // -> foo = "Yep"