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
function randomHexColor() { | |
var v = ( Math.floor( Math.random() * 0xFFFFFF ) ).toString(16); | |
while ( v.length < 6 ) { v = '0' + v; } | |
return ( '#' + v ); | |
} |
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
double d = 2.0f; // Delay | |
dispatch_time_t t = dispatch_time(DISPATCH_TIME_NOW, d * NSEC_PER_SEC); | |
dispatch_after(t, dispatch_get_main_queue(), ^(void){ | |
// Call any function | |
}); |
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
#define is_iPad ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) | |
#define is_iPhone ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ) | |
#define is_iPhone5 ( is_iPhone && [[UIScreen mainScreen] bounds].size.height == 568.0f ) | |
#define is_Retina ( [[UIScreen mainScreen] scale] == 2.0f ) |
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
#define __FILE_NAME__ [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String] | |
#ifdef DEBUG | |
#define DLog( s, ... ) NSLog( @"%s:%d %s %@", \ | |
__FILE_NAME__, \ | |
__LINE__, \ | |
__PRETTY_FUNCTION__, \ | |
[NSString stringWithFormat:(s), ##__VA_ARGS__] ) |
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
import Foundation | |
class HttpClient: NSObject { | |
let logging = true | |
let session = NSURLSession.sharedSession() | |
func makeRequest(request: NSURLRequest, completionHandler: (NSDictionary?, NSURLResponse?, NSError?) -> Void) { | |
logRequest(request) |
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
# | |
# ZSH, Mac OS X or Ubuntu | |
# | |
# Decode base 64 and convert into hex string | |
echo 'aGI32ansgxzKWh3RV4EjRwQsW1v1la+7NBTdjx8zYq0=' | base64 -D | hexdump -ve '1/1 %.2x' | pbcopy | |
# Get dirs sizes in one level and sort them | |
du --max-depth=1 -h | sort -n |
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
indirect enum LinkedList<T> { | |
case Empty | |
case Node(value: T, next: LinkedList<T>) | |
init() { self = .Empty } | |
} | |
extension LinkedList { | |
func cons(x: T) -> LinkedList<T> { | |
return .Node(value: x, next: self) |
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
extension Character { | |
var asciiValue: Int { | |
get { | |
let s = String(self).unicodeScalars | |
return Int(s[s.startIndex].value) | |
} | |
} | |
} |
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
import qualified Control.Applicative | |
import qualified Data.Char | |
import qualified Data.List | |
:set prompt "\ESC[34m\STX λ \ESC[m\STX" | |
:set +t | |
:set +m |
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
// Product of list | |
func product(list: [Double]) -> Double { | |
return list.reduce(1, combine: *) | |
} | |
// Sum of list | |
func sum(list: [Int]) -> Int { | |
return list.reduce(0, combine: +) | |
} |
OlderNewer