Skip to content

Instantly share code, notes, and snippets.

View snosrap's full-sized avatar

snosrap snosrap

View GitHub Profile
@snosrap
snosrap / unpivot.py
Created April 16, 2011 20:30
Takes a CSV through STDIN and outputs a corresponding Entity-Attribute-Value (EAV) CSV on STDOUT
#!/usr/bin/python
import sys, csv
def main():
csvIn = csv.reader(sys.stdin, delimiter=',', quotechar='"')
csvOut = csv.writer(sys.stdout)
for rowNum, row in enumerate(csvIn):
if rowNum == 0:
@snosrap
snosrap / gist:1791618
Created February 10, 2012 18:51 — forked from defnull/gist:1224387
Deploy a Bottle app on Heroku
mkdir heroku
cd heroku/
virtualenv --no-site-packages env
source env/bin/activate
pip install bottle
pip freeze > requirements.txt
cat >app.py <<EOF
import bottle, os
#!/bin/bash
if [ $# -eq 0 ] ; then
echo "Usage: $0 <flask_app_name>"
exit 1
fi
ROOT=$HOME
#### Flask ####
- (HKQueryAnchor *)anchor {
return [NSKeyedUnarchiver unarchiveTopLevelObjectWithData:[NSUserDefaults.standardUserDefaults dataForKey:@"anchor"] error:nil];
}
- (void)setAnchor:(HKQueryAnchor *)value {
[NSUserDefaults.standardUserDefaults setObject:[NSKeyedArchiver archivedDataWithRootObject:value] forKey:@"anchor"];
}
[[NSNotificationCenter defaultCenter] addObserverForName:nil
object:nil
queue:nil
usingBlock:^(NSNotification *notification) {
NSLog(@"%@", notification.name);
}];
for(int i=0;i<256;i++) {
CBUUID *u = [CBUUID UUIDWithString:[NSString stringWithFormat:@"18%02X", i]];
if(![u.UUIDString isEqualToString:u.description])
NSLog(@"%@\t%@", u.UUIDString, u.description);
}
// 1800 Generic Access Profile
// 1801 Generic Attribute Profile
// 1805 Current Time
// 1808 Glucose
// Enable parameterless options (e.g., `-verbose`) to be passed in as command line arguments.
NSMutableDictionary *arguments = [[NSUserDefaults.standardUserDefaults volatileDomainForName:NSArgumentDomain] mutableCopy];
for(NSString *arg in NSProcessInfo.processInfo.arguments)
if([arg hasPrefix:@"-"] && [arguments objectForKey:[arg substringFromIndex:1]] == nil)
[arguments setObject:@YES forKey:[arg substringFromIndex:1]];
[NSUserDefaults.standardUserDefaults removeVolatileDomainForName:NSArgumentDomain]; // remove to prevent NSInvalidArgumentException (per documentation)
[NSUserDefaults.standardUserDefaults setVolatileDomain:arguments forName:NSArgumentDomain];
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
if([view isKindOfClass:UITableViewHeaderFooterView.class]) {
((UITableViewHeaderFooterView *)view).textLabel.text = [self tableView:tableView titleForHeaderInSection:section];
}
}
struct servent *s = getservbyname("http", NULL);
if(!!s) {
NSLog(@"%s %i %s", s->s_name, CFSwapInt16BigToHost(s->s_port), s->s_proto);
for(size_t i=0; !!s->s_aliases[i]; i++) {
NSLog(@"%lu\t%s", i, s->s_aliases[i]);
}
}
@interface FPDistributedNotificationCenter : NSObject
@end
@implementation FPDistributedNotificationCenter
- (id)init {
if(self = [super init]) {
[NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(receivedDistributedNotification:) name:nil object:nil];
}
return self;
}