Skip to content

Instantly share code, notes, and snippets.

View mkhl's full-sized avatar
🖤
…at any cost

Martin Kühl mkhl

🖤
…at any cost
View GitHub Profile
This Gist is defunct (no pun intended).
If you use it, please have a look at this version:
http://github.com/mkhl/tm-terminal/tree/master
require 'net/http'
require 'uri'
# /api/v1/:format/new
# /api/v1/:format/gists/:user
# /api/v1/:format/:gist_id
res = Net::HTTP.post_form(URI.parse('http://gist.github.com/api/v1/xml/new'),
{ 'files[file1.ab]' => 'CONTNETS',
'files[file2.ab]' => 'contents' })
@mkhl
mkhl / Object#clone.js
Created December 6, 2008 09:54
JavaScript
// A workaround for Javascript's bizarre constructor semantics
// Source: http://www.dekorte.com/blog/blog.cgi?do=item&id=3749
Object.clone = function() {
var constructor = new Function;
constructor.prototype = this;
obj = new constructor;
obj.init()
return obj
}
@mkhl
mkhl / DebugLog.h
Created December 8, 2008 18:14
Objective-C Logging
// Source: http://blog.mbcharbonneau.com/post/56581688/better-logging-in-objective-c
#define DebugLog(format, ...) NSLog(@"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(format), ##__VA_ARGS__])
/Developer/Extras/Xcode\ Index\ Templates/install_templates
# Installs into:
# ~/Library/Application\ Support/Apple/Developer\ Tools/Index\ Templates
# and can be moved to:
# /Library/Application\ Support/Apple/Developer\ Tools/Index\ Templates
@mkhl
mkhl / CLITrampoline.m
Created December 8, 2008 18:19
CLI tool that trampolines to a tool in the associated app bundle
// from: somewhere around http://briksoftware.com/blog/
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSWorkspace *env = [NSWorkspace sharedWorkspace];
NSString *app = [env absolutePathForAppBundleWithIdentifier:@"com.pdfkey.pdfkeypro"];
NSString *targetPath = [[app stringByAppendingPathComponent:@"Contents/Resources/pdflock"] retain];
const char *CStringPath = [targetPath UTF8String];
@mkhl
mkhl / cflags.txt
Created December 8, 2008 18:23
GCC flags and stuff
-Wall
-Wextra
-Wfloat-equal
-Wpointer-arith
-Wstrict-prototypes
-Wold-style-definition
-Wshadow
-Wshorten-64-to-32
-Wmissing-prototypes
-Wunused-function
@mkhl
mkhl / drop-to-irb.rb
Created December 8, 2008 18:25
Collection of IRB tricks
require 'irb'
module IRB
def self.start_session(binding)
IRB.setup(nil)
workspace = WorkSpace.new(binding)
if @CONF[:SCRIPT]
irb = Irb.new(workspace, @CONF[:SCRIPT])
@mkhl
mkhl / autoscoped.h
Created December 8, 2008 18:27
Objective-C macros
// GCC Attribute for autoscoped Obj-C objects
// Source: http://www.cocoabuilder.com/archive/message/cocoa/2009/3/13/232287
#define autoscoped __attribute__((cleanup(releaseObject)))
static inline void releaseObject(id *object)
{
[*object release];
}
@mkhl
mkhl / constant.io
Created December 8, 2008 18:27
Constants in Io
Constant := Object clone do (
with := method(msg,
self msg := msg
self activate := method(call message setName(msg asString); msg)
)
)
// Lets try it out:
// Make PI a regular number