Skip to content

Instantly share code, notes, and snippets.

View enigmaticape's full-sized avatar

Enigmatic Ape enigmaticape

View GitHub Profile
@enigmaticape
enigmaticape / part1.m
Created November 14, 2012 19:59
You want to use NSObject performSelector with multiple parameters, but you can't ? (1)
- ( id ) methodWithOneParam:( id ) theParam {
// Do amazing stuff
return @"Srsly, Amazing!";
}
- ( id ) methodWithFirst:( id ) firstParam
andSecond:( id ) secondParam
{
// Do doubly amazing stuff
@enigmaticape
enigmaticape / ic.py
Created December 10, 2012 22:49
Compute the index of coincidence of a text file
#!/usr/bin/env python
import sys
import collections
# Bag em
cipher_file = open( sys.argv[ 1 ], 'rb')
cipher_text = cipher_file.read()
# remove all non alpha and whitespace and force uppercase
@enigmaticape
enigmaticape / theme_get_archives_link.php
Created November 5, 2012 13:46
Wordpress PHP function which adds CSS class to currently selected archive list item
@enigmaticape
enigmaticape / HTTPMessage.h
Created November 6, 2012 14:22
Minimal (ish) HTTP server in ObjC using GCD socket dispatch
#import <Foundation/Foundation.h>
@interface HTTPMessage : NSObject
@property (nonatomic, readonly) CFHTTPMessageRef request;
- ( BOOL ) isRequestComplete:(NSData *) append_data;
@end
@enigmaticape
enigmaticape / Invoker.h
Created November 17, 2012 16:30
Wrapping NSInvocation for fun and profit, for values of profit that include a better peformSelector
#import <Foundation/Foundation.h>
@interface Invoker : NSObject
+ ( NSValue * ) invoke:( SEL ) selector onTarget:( id ) target, ...;
@end
@enigmaticape
enigmaticape / SomeObject.h
Created November 19, 2012 20:13
A short digression on Objective C runtime type encoding
#import <Foundation/Foundation.h>
@interface SomeObject : NSObject
- (NSObject*) someMethodWithAchar:(char) aChar
anInt:(int) anInt
aFloat:(float) aFloat
aString:(NSString*) aString;
@end
@enigmaticape
enigmaticape / main.m
Created November 9, 2012 14:26
You want to use NSObject performSelector with multiple parameters, but you can't ?
#import <Foundation/Foundation.h>
#import <Foundation/Foundation.h>
#import <objc/message.h>
@interface AmazingClass : NSObject
- ( void ) doMultipleAmazingStuff;
@end
@implementation AmazingClass
#import <Foundation/Foundation.h>
#import <ifaddrs.h>
#import <net/if.h>
#import <SystemConfiguration/CaptiveNetwork.h>
@interface SMTWiFiStatus : NSObject
- (BOOL) isWiFiEnabled;
- (BOOL) isWiFiConnected;
@enigmaticape
enigmaticape / csv2html.py
Created November 5, 2012 12:15
Very simple CSV to HTML table in Python
#!/usr/bin/python
import sys
import os
import csv
import string
if len( sys.argv ) < 2 :
sys.stderr.write( sys.argv[ 0 ] +
": usage - " +
@enigmaticape
enigmaticape / topgrossingfreeapps.py
Last active May 29, 2017 12:49
Grab and parse iTunes App Store RSS feed and coiunt how many of the top grossing apps for a particular store are currently free
#!/usr/bin/env python
# topgrossingfreeapps.py [country code]
# us, gb, ch, etc
# quick and dirty python script to grab the percentage
# of top grossing aps in a given app store which are
# currently free
import feedparser