Skip to content

Instantly share code, notes, and snippets.

View penso's full-sized avatar

Fabien Penso penso

View GitHub Profile
import Cocoa
import Foundation
var options = Dictionary<String, AnyObject>()
options["send_at"] = "foobar"
var foo : AnyObject = options["send_at"]!
var foo2 : String = options["send_at"] as String
import Cocoa
var options = Dictionary<String, AnyObject?>()
options["body"] = "something"
var body = options["body"] as String?
@penso
penso / gist:43a3535c989c6b285876
Created June 14, 2014 21:50
xcode6-crash sample
import Cocoa
var options = Dictionary<String, AnyObject?>()
options["body"] = "something"
// Working
if let body : AnyObject = options["body"]! {
body
}
@penso
penso / crash.playground
Last active August 29, 2015 14:02
Xcode6-beta crash on swift code
// Copy paste this in your playground
// sent at rdar://17316238
import Cocoa
var date_string = "2014/06/14 20:05:13 +0000"
var rfc3339DateFormatter = NSDateFormatter()
rfc3339DateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
rfc3339DateFormatter.dateFormat = "yyyy/MM/dd HH:mm:ss Z"
rfc3339DateFormatter.timeZone = NSTimeZone(forSecondsFromGMT: 0)
@penso
penso / keybase.md
Created March 30, 2014 20:10
keybase.md

Keybase proof

I hereby claim:

  • I am penso on github.
  • I am penso (https://keybase.io/penso) on keybase.
  • I have a public key whose fingerprint is B58C 60FB B978 B3B5 C27C E404 EE62 E221 66D7 B13A

To claim this, I am signing this object:

curl -d user_credentials=MY_CREDENTIALS\
-d "notification[message]=my message" \
-d "notification[long_message]=<b>Some HTML for the full layout page notification</b>" \
-d "notification[title]=A notification title" \
-d "notification[subtitle]=A notification subtitle" \
-d "notification[long_message_preview]=the notif preview" \
-d "notification[action_loc_key]=Approve me" \
https://www.appnotifications.com/account/notifications.xml
@penso
penso / gist:6621519
Last active December 23, 2015 10:29
Friends table
mysql> desc relationships;
+-----------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+------------+------+-----+---------+-------+
| user_id | int(11) | NO | PRI | 0 | |
| friend_id | int(11) | NO | PRI | 0 | |
| status | tinyint(4) | NO | | 0 | |
+-----------+------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
@penso
penso / gist:6495732
Created September 9, 2013 13:41
Detect remaining chars for a tweet
#define TWEET_MAX_LENGTH 140
#define TWEET_URL_HTTP_LENGTH 22
#define TWEET_URL_HTTPS_LENGTH 23
+ (NSInteger) remainingChars:(NSString *)text {
NSInteger result = TWEET_MAX_LENGTH - [text length];
NSError *error = nil;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"https?://(\\S+)"
options:0
error:&error];
@penso
penso / nginx-penso.info
Created June 28, 2013 21:52
My server nginx configuration for my blog
server {
listen 80;
server_name blog.penso.info;
access_log /var/log/nginx/penso.access.log;
root /www/penso.info/htdocs;
index index.html index.htm;
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
# put this in lib/realtime_analytics.rb
#
# Then add in your config/routes.rb:
# mount AnalyticsSSE => '/realtime-analytics'
require 'em-hiredis'
class AnalyticsSSE < Sinatra::Base
include Sinatra::SSE
get '/' do
sse_stream do |out|
redis = EM::Hiredis.connect("redis://#{Settings[:redis_host]}:#{Settings[:redis_port]}")