Skip to content

Instantly share code, notes, and snippets.

View samsonjs's full-sized avatar

Sami Samhuri samsonjs

View GitHub Profile
@samsonjs
samsonjs / sad_trombone.m
Last active August 29, 2015 13:58
Auto layout sadness, what am I doing wrong?
- (void)viewDidLoad
{
[super viewDidLoad];
UITextView *hi = [[UITextView alloc] init];
hi.translatesAutoresizingMaskIntoConstraints = NO;
hi.text = @"hi there";
hi.textColor = [UIColor blackColor];
[hi sizeToFit];
[self.view addSubview:hi];
@samsonjs
samsonjs / gist:11385095
Created April 28, 2014 21:51
Keybase verification
### Keybase proof
I hereby claim:
* I am samsonjs on github.
* I am samsonjs (https://keybase.io/samsonjs) on keybase.
* I have a public key whose fingerprint is BBED 74DD 17DB 7C8F 7664 4FE2 0522 38DD 367F 2A76
To claim this, I am signing this object:
<h1>header 1</h1>
<h2>header 2</h2>
<h3>header 3</h3>
<h4>header 4</h4>
<h5>header 5</h5>
<h6>header 6</h6>
<p>paragraph</p>
<b>bold</b>
@samsonjs
samsonjs / center_this_bitch.js
Created May 26, 2014 19:20
Sometimes you just gotta centre this bitch.
// Courtesy of http://www.chupamobile.com
function center_this_bitch(target, context, animate) {
var top, left, context_target;
animate = typeof animate !== 'undefined' ? animate : false;
switch (context) {
case'parent':
context_target = target.parent();
top = ((context_target.height() - target.height()) / 2) + 'px';
left = ((context_target.width() - target.width()) / 2) + 'px';
[ 9:46am] ~/Projects % cat >hello.swift
#!/usr/bin/env xcrun swift -i
println("Hello, world!")
[ 9:47am] ~/Projects % chmod +x hello.swift
[ 9:47am] ~/Projects % ./hello.swift
Hello, world!
#import <Foundation/Foundation.h>
NSDictionary *TestD(void) {
return @{
@"string" : @"abc",
@"number" : @42,
@"dictionary" : @{
@"string" : @"abcdef",
@"array" : @[ @"a", @2 ]
},
(let ((a 1)
(b 2))
(foo a b))
@samsonjs
samsonjs / embed.js
Created August 14, 2014 18:26
Vine's embed script
! function() {
function hasClass(el, klass) {
return el.className.match(new RegExp("(\\s|^)" + klass + "(\\s|$)"))
}
function addClass(el, klass) {
hasClass(el, klass) || (el.className += " " + klass)
}
function removeClass(el, klass) {
@samsonjs
samsonjs / welf.m
Created September 12, 2014 17:06
welf
@interface AsyncAPI : NSObject
- (void)doSomethingForOwner:(__weak id)owner completionBlock:(void (^)(id welf, id result))complete;
@end
@implementation AsyncAPI
- (void)doSomethingForOwner:(__weak id)owner completionBlock:(void (^)(id welf, id result))complete {
[self doTheAsyncThing:^(id result) {
if (owner && complete) {
complete(owner, result);
}
@samsonjs
samsonjs / sunset.rb
Last active August 29, 2015 14:12
scrape sunrise/sunset data
#!/usr/bin/env ruby -w
require 'faraday'
require 'json'
require 'nokogiri'
def sunsets_from_html(html)
doc = Nokogiri::HTML(html)
table = doc.css('table').first
table.css('br').each { |newline| newline.replace("\n") }