Skip to content

Instantly share code, notes, and snippets.

View natebirkholz's full-sized avatar
💻
Codin’

Nate Birkholz natebirkholz

💻
Codin’
View GitHub Profile
@lattner
lattner / TaskConcurrencyManifesto.md
Last active November 15, 2024 05:45
Swift Concurrency Manifesto
// @discardableResult to be added
// @noescape needs to move to type annotation
// needs to add _ for item
public func with<T>(item: T, @noescape update: (inout T) throws -> Void) rethrows -> T {
var this = item; try update(&this); return this
}
// taken from https://opensource.apple.com/source/CF/CF-855.17/CFDate.c
CFAbsoluteTime CFAbsoluteTimeGetCurrent(void) {
CFAbsoluteTime ret;
struct timeval tv;
gettimeofday(&tv, NULL); // http://linux.die.net/man/2/gettimeofday
ret = (CFTimeInterval)tv.tv_sec - kCFAbsoluteTimeIntervalSince1970;
ret += (1.0E-6 * (CFTimeInterval)tv.tv_usec);
return ret;
}
@willrichman
willrichman / Refreshcontrol.swift
Last active August 29, 2015 14:07
Refresh control!
/* Taken from stackOverflow http://stackoverflow.com/questions/24475792/how-to-use-pull-to-refresh-in-swift */
self.refreshControl = UIRefreshControl()
self.refreshControl?.attributedTitle = NSAttributedString(string: "Pull to refresh")
self.refreshControl?.addTarget(self, action: "refreshTweets:", forControlEvents: UIControlEvents.ValueChanged)
self.tableView.addSubview(self.refreshControl!)
func refreshTweets (sender: AnyObject) {
NetworkController.controller.fetchTimeLine(timelineType, isRefresh: true, newestTweet: self.tweets?[0], userScreenname: userTimelineShown) { (errorDescription, tweets) -> Void in
if errorDescription != nil {
@adomado
adomado / gist:1226159
Created September 19, 2011 08:41
Example mongodb script
db = connect("localhost:27017/test");
var cursor = db.unicorns.find({gender : "m"});
var total = 0;
while(cursor.hasNext()) {
var obj = cursor.next();
total += (obj.hits || 0);
}
print(total);