Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Fabrice Aneche akhenakh

🏠
Working from home
Block or report user

Report or block akhenakh

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@akhenakh
akhenakh / permut.m
Created Feb 27, 2014
Unoptimized Permut
View permut.m
// 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 Aug 29, 2015
Mantle conversion for timestamped json
View mantle.m
+ (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 / cache.m
Last active Aug 29, 2015
Force private cache-control requests to be public (cachable) with AFHTTPSessionManager
View cache.m
[sessionManager
setDataTaskWillCacheResponseBlock:^NSCachedURLResponse *
(NSURLSession *session,
NSURLSessionDataTask *dataTask,
NSCachedURLResponse *
proposedResponse) {
NSURLResponse *response = proposedResponse.response;
NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response;
NSDictionary *headers = HTTPResponse.allHeaderFields;
@akhenakh
akhenakh / is_airplay_active.m
Last active Aug 29, 2015
airPlayVideoActive property returns false while between two streams, here is a way to detect airplay in all condition from: http://www.ask-coder.com/3162230/how-to-customize-the-airplay-button-when-airplay-is-active
View is_airplay_active.m
- (BOOL)isAirPlayActive{
CFDictionaryRef currentRouteDescriptionDictionary = nil;
UInt32 dataSize = sizeof(currentRouteDescriptionDictionary);
AudioSessionGetProperty(kAudioSessionProperty_AudioRouteDescription, &dataSize, &currentRouteDescriptionDictionary);
if (currentRouteDescriptionDictionary) {
CFArrayRef outputs = CFDictionaryGetValue(currentRouteDescriptionDictionary, kAudioSession_AudioRouteKey_Outputs);
if(outputs && CFArrayGetCount(outputs) > 0) {
CFDictionaryRef currentOutput = CFArrayGetValueAtIndex(outputs, 0);
CFStringRef outputType = CFDictionaryGetValue(currentOutput, kAudioSession_AudioRouteKey_Type);
return (CFStringCompare(outputType, kAudioSessionOutputRoute_AirPlay, 0) == kCFCompareEqualTo);
@akhenakh
akhenakh / config.json
Created Jun 27, 2014
Peco simple config file and examples
View config.json
{
"Keymap": {
"C-p": "peco.SelectPrevious",
"C-n": "peco.SelectNext",
"Tab": "peco.ToggleSelectionAndSelectNext",
"C-r": "peco.RotateMatcher"
}
}
#alias pll='ls | peco | xargs ls -l'
View config.js
define(['settings'],
function (Settings) {
return new Settings({
datasources: {
influx: {
type: 'influxdb',
url: 'http://localhost:8086/db/test',
username: 'root',
@akhenakh
akhenakh / main.go
Created Oct 28, 2014
Test influxDB connection
View main.go
package main
import (
"fmt"
"github.com/influxdb/influxdb/client"
)
func main() {
c, err := client.NewClient(&client.ClientConfig{
@akhenakh
akhenakh / main.go
Last active Aug 29, 2015
influx test 2
View main.go
package main
import (
"fmt"
"log"
"math/rand"
"net/http"
"time"
"github.com/influxdb/influxdb/client"
@akhenakh
akhenakh / reverse
Created Nov 9, 2014
reverse a slice in Go
View reverse
for i, j := 0, len(res)-1; i < j; i, j = i+1, j-1 {
res[i], res[j] = res[j], res[i]
}
@akhenakh
akhenakh / jsontime.go
Created Dec 8, 2014
time.Time timestamp JSON in Go
View jsontime.go
type JSONTime time.Time
func (t JSONTime) MarshalJSON() ([]byte, error) {
stamp := fmt.Sprintf("\"%d\"", time.Time(t).Unix())
return []byte(stamp), nil
}
// If you are using gob you need to redefine MarshalBinary
func (t JSONTime) MarshalBinary() ([]byte, error) {
return time.Time(t).MarshalBinary()
You can’t perform that action at this time.