Skip to content

Instantly share code, notes, and snippets.

View cmittendorf's full-sized avatar

Christian Mittendorf cmittendorf

View GitHub Profile
@cmittendorf
cmittendorf / ArrayExtension.swift
Last active August 29, 2015 14:02
Adds an each closure to Arrays in Swift.
#!/usr/bin/env xcrun swift -i
extension Array {
func each(closure:(T) -> ()) {
for item:T in self {
closure(item)
}
}
func eachWithIndex(closure:(Int, T) -> ()) {
var i:Int = 0
@cmittendorf
cmittendorf / terminal-size.sh
Last active August 29, 2015 13:59
Set the size of the current terminal to number of columns and rows.
#!/usr/bin/env bash
if [ $# != 0 -a $# != 2 ]; then
echo `basename $0`" <cols> <rows>"
exit
fi
COLS=${1:-80}
ROWS=${2:-25}
@cmittendorf
cmittendorf / pbcopy.rb
Created July 11, 2013 20:32
put this into your ~/.irbrc if you like do some text stuff in your ruby console which you want to paste somewhere else. Use "pbcopy a" to copy the contents of a to the pasteboard.
require 'tempfile'
def pbcopy(s)
tmp_file = Tempfile.new("pbcopy")
begin
tmp_file.write(s.to_s)
tmp_file.rewind
system "/bin/cat #{tmp_file.path} | /usr/bin/pbcopy"
ensure
tmp_file.close
@cmittendorf
cmittendorf / array_of_blocks.mm
Last active December 17, 2015 04:49
With this objective-c category you can put blocks into an array and execute them one by one.
/**
* cc -Wall -fno-objc-arc -framework Foundation -o array_of_blocks array_of_blocks.mm
* Based on http://orangejuiceliberationfront.com/blocks-and-block-lists/ from Uli Kusterer
*/
#import <Foundation/Foundation.h>
@interface NSMutableArray (BlocksArray)
- (void)startExecutingBlocks;
- (void)executeNextBlock;
@end
@cmittendorf
cmittendorf / retrieve-cert.sh
Created April 22, 2011 08:41
get the cert from a ssl connection for importing into a keystore
#!/bin/sh
#
# usage: retrieve-cert.sh remote.host.name [port]
#
if [ $# -eq 0 -o $# -gt 2 ]; then
echo `basename $0`" <host> <port:443>"
exit
fi