This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def log_exception(view_func): | |
""" log exception decorator for a view, | |
""" | |
def _decorator(self, *args, **kwargs): | |
try: | |
response = view_func(self, *args, **kwargs) | |
except: | |
if self.settings['debug']: | |
raise | |
tb = traceback.format_exc() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <libstemmer.h> | |
int main () { | |
struct sb_stemmer* sb; | |
sb_symbol* res; | |
int size; | |
sb = sb_stemmer_new("english", "UTF_8"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (UIImage *)renderInImageOfSize:(CGSize)size; | |
{ | |
UIGraphicsBeginImageContextWithOptions(size, NO, 0); | |
// do drawing here | |
UIImage *result = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"strconv" | |
"time" | |
) | |
type jsonTime time.Time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface NBNet() | |
@property(nonatomic, strong) NSURLSession *imageSession; | |
@property(nonatomic, strong) NSOperationQueue *netOperationQueue; | |
@end | |
@implementation NBNet | |
+ (id)sharedNBNet { | |
static NBNet *sharedNBNet = nil; | |
static dispatch_once_t onceToken; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"image" | |
_ "image/gif" | |
_ "image/jpeg" | |
_ "image/png" | |
"io" | |
"mime" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// unoptimized permute pair elements avoiding repetitions | |
- (NSArray *) permuteArrayOfSets:(NSArray *)elements { | |
NSMutableSet *resultSet = [NSMutableSet set]; | |
for (NSUInteger i=0;i<[elements count]; i++) { | |
for (NSUInteger j=0;j<[elements count]; j++) { | |
if (i == j) continue; | |
NSSet *newSet = [NSSet setWithObjects:elements[i], elements[j], nil]; | |
if ([resultSet containsObject:newSet]) continue; | |
[resultSet addObject:newSet]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (NSValueTransformer *)publictionDateJSONTransformer { | |
return [MTLValueTransformer transformerUsingForwardBlock:^(NSNumber *timestamp, BOOL *success, NSError **error){ | |
return [NSDate dateWithTimeIntervalSince1970:[timestamp doubleValue]]; | |
} reverseBlock:^(NSDate *date, BOOL *success, NSError **error) { | |
return [NSNumber numberWithDouble:[date timeIntervalSince1970]]; | |
}]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 1st Install https://github.com/prasmussen/gdrive | |
# then use this script in Alfred or from CLI when you want to screenshot then upload to your gdrive | |
# then share the link to others from your paste board | |
# (run gdrive one first time to authenticate with Google) | |
screencapture -tjpg -i /tmp/temp_shot_gdrive.jpg | |
DATEFILENAME=`date +"%Y%m%d%H%M"` | |
# use -p id to upload to a specific folder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pkg install bison flex leveldb protobuf gmake ruby ruby-gems bzr mercurial valgrind | |
export CC=clang | |
export GOROOT=/home/akh/dev/gosrc | |
export CGO_CFLAGS="-I/usr/local/include" | |
export CGO_LDFLAGS="-L/usr/local/lib" | |
git clone https://github.com/influxdb/influxdb.git | |
./configure --with-flex=/usr/local/bin/flex --with-bison=/usr/local/bin/bison | |
# edit Makefile to change the SHELL path to /usr/local/bin/bash |