Skip to content

Instantly share code, notes, and snippets.

View cmittendorf's full-sized avatar

Christian Mittendorf cmittendorf

View GitHub Profile
@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
@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 / 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 / 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 / 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 / View WWDC 2014 Videos with QT7.scpt
Last active August 29, 2015 14:02
This AppleScript will allow you to select a WWDC 2014 video and open it automatically using the QuickTime 7 player (http://support.apple.com/kb/DL923) allowing you to increase the playback speed as mentioned in BitsUndSo episode #379 (http://www.bitsundso.de/bus379/). Be aware that the script does not check if the QT7 player is already installed.
(***
Use this AppleScript to launch WWDC 2014 videos in QuickTime Player 7, where
you can adjust the playback speed to your needs (⌘ + k). Have fun!
Christian Mittendorf, 15.06.2014
cmittendorf<et>me.com
***)
set page_url to "https://developer.apple.com/videos/wwdc/2014/"
set videos to missing value
@cmittendorf
cmittendorf / safari-text.sh
Created June 20, 2014 07:08
Retrieve the text content of the current web page from Safari
#!/usr/bin/env bash
# prepared for Yosemite (10.10)
# osascript -l JavaScript -e "Application('Safari').documents()[0].text()"
CONTENT=$(osascript -ss << EOF
tell application "Safari"
tell its first document
get its text
end tell
@cmittendorf
cmittendorf / safari-url.sh
Created June 20, 2014 07:10
Get the URL of the current web page from Safari
#!/usr/bin/env bash
URL=$(osascript << EOF
tell application "Safari"
tell its first document
URL
end tell
end tell
EOF)
@cmittendorf
cmittendorf / MakeNewFileOrFolder.applescript
Last active August 29, 2015 14:04
Create new files or folders with a keystroke and by using the Tool FastScripts (http://www.red-sweater.com/fastscripts/) you can overwrite the default Finder Shift-Command-N shortcut to create a new folder for invoking our new script.
(**
Create new files or folders with a keystroke and by using the Tool
FastScripts http://www.red-sweater.com/fastscripts/
you can overwrite the default Finder Shift-Command-N shortcut
to create a new folder for invoking our new script.
**)
tell application "Finder"
-- default name for a new file following
-- the Finders convention for naming folders
set newFileName to "untitled file"
@cmittendorf
cmittendorf / display-notification.sh
Last active August 29, 2015 14:04
A little snippet showing how to create a log function in bash that displays its log message in the Mac OS X notification center as well as on the console.
#!/usr/bin/env bash
function log()
{
echo `date +"[%d.%m.%Y %H:%M:%S] "`$1
# Available Sounds:
# Basso, Blow, Bottle, Frog, Funk, Glass, Hero,
# Morse, Ping, Pop, Purr, Sosumi, Submarine, Tink
osascript << EOF