Skip to content

Instantly share code, notes, and snippets.

View akhenakh's full-sized avatar
🏠
Working from home

Fabrice Aneche akhenakh

🏠
Working from home
View GitHub Profile
@akhenakh
akhenakh / gist:5825280
Last active April 21, 2016 16:12
Decorator for Tornado function, that will log all exception in MongodB, implies all handlers have a self.db properties connected to mongo
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()
@akhenakh
akhenakh / test.c
Created July 30, 2013 12:58
test libstemmer on Mac using macports: clang -I/opt/local/include -L/opt/local/lib -lstemmer test.c -o test on Linux gcc -o test test.c -lstemmer (apt-get install libstemmer-dev See associated code in Golang http://play.golang.org/p/1QnkCZtuYr
#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");
@akhenakh
akhenakh / renderQueue.m
Last active December 24, 2015 09:19
Core Graphics rendering from another thread
- (UIImage *)renderInImageOfSize:(CGSize)size;
{
UIGraphicsBeginImageContextWithOptions(size, NO, 0);
// do drawing here
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}
@akhenakh
akhenakh / timejson.go
Last active December 24, 2015 09:59
Json Un/Marshaling Time in UNIX epoch time
package main
import (
"encoding/json"
"fmt"
"strconv"
"time"
)
type jsonTime time.Time
@akhenakh
akhenakh / NBNet.m
Last active March 5, 2017 01:45
Download image and update using NSURLSession
@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;
@akhenakh
akhenakh / guess.go
Last active March 13, 2024 13:18
Guess an image format in Golang
package main
import (
"image"
_ "image/gif"
_ "image/jpeg"
_ "image/png"
"io"
"mime"
@akhenakh
akhenakh / permut.m
Created February 27, 2014 00:52
Unoptimized Permut
// 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];
}
@akhenakh
akhenakh / mantle.m
Last active August 29, 2015 13:57
Mantle conversion for timestamped json
+ (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]];
}];
}
@akhenakh
akhenakh / cap.sh
Last active March 26, 2017 15:05
Screenshot, upload and share from your Google drive
#!/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
@akhenakh
akhenakh / influxdb
Last active November 4, 2015 22:35
influxdb on freebsd
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