Skip to content

Instantly share code, notes, and snippets.

@pyrtsa
pyrtsa / README.md
Last active August 29, 2015 14:08 — forked from otiose/README.md

Intro

All the Java code here comes from Algorithms, 4th Edition, by Robert Sedgewick and Kevin Wayne.

The Swift code was written by myself. Although it is mainly a direct port of the Java code :)

The goal was to see how fast Swift would compare to a language such as Java in a somewhat non-trivial case.

The input used was largeUF.txt, also provided by the Algorithms book. It is about 27mb, so I left it out of the gist :)

(defn get-user-from-request [request]
(when-let [ident (get-in request [:session ::friend/identity :current])]
(magic/user-by-id (get-in request [:myapp :system :db]) ident)))
(defn wrap-user
"Add user information to the request map if logged in."
[handler]
(fn [request]
(if-let [user (get-user-from-request request)]
(handler (assoc-in request [:myapp :user] user))
#include <vector>
#include <memory>
#include <cassert>
template<typename T>
struct idx_vector {
typedef int index;
std::vector<std::unique_ptr<T>> pointers_;
std::vector<index> free_indices_;
@pyrtsa
pyrtsa / gist:5849560
Last active December 18, 2015 21:48 — forked from anonymous/gist:5849554
NSDateFormatter *dateFormatter = [NSDateFormatter new];
dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
dateFormatter.dateFormat = @"YYYY-MM-dd'T'HH:mm:ss.SSS'Z'";
dateFormatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
// jQuery extensions
$.fn.valueAsObservable = function valueAsObservable() {
var changes = $(this).changeAsObservable();
var keyUps = $(this).keyupAsObservable();
var values = changes.merge(keyUps).map(function (e) {
return e.target.value;
});
return values.startWith($(this).val()).distinctUntilChanged();
}
@pyrtsa
pyrtsa / factory.cpp
Created June 30, 2011 13:25 — forked from benben/factory.cpp
Object factory using Boost.Phoenix, Boost.Function and Boost.SmartPtr libraries
#include <boost/foreach.hpp>
#include <boost/function.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/shared_ptr.hpp>
#include <iostream>
#include <map>
#include <string>
#include <vector>
struct Parent { virtual std::string hello() const = 0; };