Skip to content

Instantly share code, notes, and snippets.

View jklausa's full-sized avatar

Jan Klausa jklausa

View GitHub Profile
import Foundation
@infix func ==(lhs: NSDate, rhs: NSDate) -> Bool {
return lhs == rhs
}
@infix func <=(lhs: NSDate, rhs: NSDate) -> Bool {
return !(lhs > rhs)
}
@infix func >=(lhs: NSDate, rhs: NSDate) -> Bool {
protocol Comparable : Equatable {
func <=(lhs: Self, rhs: Self) -> Bool
func >=(lhs: Self, rhs: Self) -> Bool
func >(lhs: Self, rhs: Self) -> Bool
}
@jklausa
jklausa / gist:a3205c6e00dc7fbc7a00
Last active August 29, 2015 14:03
early-return obj-c init
- (instancetype)initWithFoo:(id)foo
{
self = [super initWithFoo:foo];
if (!self) {
return nil;
}
_foo = foo;
return self;
}
let users = ["klausa_qwpx", "macoscope"]
func getTweetsForUser(userName: String, completion: AnyObject? -> Void) {
let parameters: [String:AnyObject] = ["screen_name": userName, "include_rts": true,
"count": 5, "include_entities": true]
Alamofire.request(.GET, "https//api.twitter.com/1/statuses/user_timeline.json", parameters: parameters)
.responseJSON { (_, _, json, _) in
if let json = json {
completion(json)
class TestClass {
var aStruct: MyStruct;
init(inout initialStruct: MyStruct) {
aStruct = initialStruct;
}
func changeValueTo(newValue: Int) {
aStruct.aValue = newValue;
}
/* Explanation: I need to have a string that says "x days ago" BUT, if there's a word in the languague for it
(like "yesterday" in english, or "gestern" and "vorgestern" in geman), use that instead. Obviously, it needs to
support multiple languages, so no hardcoding of strings if possible.
I've inherited a .stringsdict with "x days ago" in some languages (that's the @"RELATIVE_DAYS_NEGATIVE").
I wanna avoid having external dependency just for that, but can be convinced otherwise.
How horrible is this?
*/
# Reactive Cocoa 5 crash-course
##👋
I sincerely hate most RAC/RAS/FRP/WTF/BBQ (MOAR three letter acronyms is what programming needs, definitely) that start with "oh, Reactive Cocoa is a framework for working with streams of values over time" or some other similar word-soup.
If you understand it already, I'm sure it makes sense, for newcomers it's absolutely horrible and impenetrable.
Hopefully this will be more digestible.
(lldb) po [NSBundle mainBundle]
NSBundle </var/containers/Bundle/Application/FD1BE089-EFC8-469A-AA95-84FE25E47201/WordPress.app> (loaded)
(lldb) po [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"/var/containers/Bundle/Application/FD1BE089-EFC8-469A-AA95-84FE25E47201/WordPress.app/WordPress.momd" error:nil]
<__NSArrayM 0x1c4048ee0>(
WordPress 67.mom,
WordPress 66.mom,
WordPress 68.omo,
WordPress 58.mom,
WordPress 64.mom,
@jklausa
jklausa / xcode-curl.sh
Last active April 20, 2022 14:24
curl Xcode
#!/bin/bash
# Useful for downloading Xcode on machines where you don't want to log-in with your Apple ID (e.g. CI
# machines, or other low-trust environemnts).
# Requires you to manually log-in to the Apple Dev Portal, and extract contents of the ADCDownloadAuth cookie
# (easiest way to do it is using Web Inspector, going to the "Storage" Pane, selecting "Cookies" in the left sidebar,
# and copying the appropriate value.
#
# Usage:
# curl https://gist.githubusercontent.com/jklausa/5780d5126d97f73b70a91aeab58f7f4a/raw/ | bash -s -- XCODE-URL COOKIE_VALUE
created by running: find . -type f -perm +111 -exec sh -c "file \"{}\" | head -n 1" \; | grep Mach-O > ~/macho-s
and then cat ~/macho-s | grep -v arm64
./Developer/usr/share/xcs/CouchDB/bin/makeconv: Mach-O 64-bit executable x86_64
./Developer/usr/share/xcs/CouchDB/bin/gencnval: Mach-O 64-bit executable x86_64
./Developer/usr/share/xcs/CouchDB/bin/gencfu: Mach-O 64-bit executable x86_64
./Developer/usr/share/xcs/CouchDB/bin/icuinfo: Mach-O 64-bit executable x86_64
./Developer/usr/share/xcs/CouchDB/bin/gendict: Mach-O 64-bit executable x86_64