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
#include <chrono> | |
constexpr auto operator "" _days (unsigned long long n) { return std::chrono::hours(24 * n); } | |
constexpr auto operator "" _h (unsigned long long n) { return std::chrono::hours(n); } | |
constexpr auto operator "" _min (unsigned long long n) { return std::chrono::minutes(n); } | |
constexpr auto operator "" _s (unsigned long long n) { return std::chrono::seconds(n); } | |
constexpr auto operator "" _ms (unsigned long long n) { return std::chrono::milliseconds(n); } | |
constexpr auto operator "" _µs (unsigned long long n) { return std::chrono::microseconds(n); } | |
constexpr auto operator "" _ns (unsigned long long n) { return std::chrono::nanoseconds(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
;; This is probably either a silly idea or a foolish implementation of an okay one. | |
(defn ret* | |
[bindings & body] | |
(if-let [[k v & more] (not-empty bindings)] | |
`(let [k# ~v] | |
(if (reduced? k#) | |
k# | |
(let [~k k#] | |
~(apply ret* more body)))) |
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
{-# LANGUAGE Arrows #-} | |
import Control.Arrow | |
import Control.Category | |
import Prelude hiding (id, (.)) | |
-- Only for testing | |
import Text.Printf | |
newtype SF a b = SF (Float -> a -> (SF a b, b)) |
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
// The following code is in public domain. Re-releases are free to choose | |
// whether to attribute the code to its original author or not. | |
// Author: Pyry Jahkola <pyry.jahkola@iki.fi> | |
#include <sstream> | |
#include <iostream> | |
#include <map> | |
#include <cassert> | |
#include <stack> | |
#include <vector> |
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
def is_holiday(d): | |
"""Check whether the given dateutil.date is a Finnish national holiday""" | |
import dateutil.easter | |
from datetime import date, timedelta as td | |
assert isinstance(d, date) | |
md = '{}.{}'.format(d.day, d.month) | |
y = d.year | |
# Fixed-date holidays | |
if md in '1.1 6.1 1.5 6.12 24.12 25.12 26.12'.split(): return True | |
# Finnish midsummer (eve on Fri the 19..25th, day on Sat the 20..26th) |
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
// Public domain. | |
// Attribution welcome, but not required. -- Pyry Jahkola. | |
// What's the point in all this? To get the equivalent of CoffeeScript's | |
// (?.) operator into vanilla JavaScript. | |
// get(x, key1, key2, ...) -- Get the result of x[key1][key2]..., or undefined. | |
// Will short circuit if a key is not found. |
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
module Main where | |
import Control.Monad | |
import Control.Monad.ST | |
import Data.Array.ST | |
import Data.Array.Unboxed | |
import Criterion.Main (defaultMain, bgroup, bench, whnf) | |
import Debug.Trace |
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
-- | https://jeltsch.wordpress.com/2013/02/14/the-constraint-kind/ | |
{-# LANGUAGE ConstraintKinds, TypeFamilies #-} | |
import Prelude hiding (Functor(..)) | |
import Data.Set (Set) | |
import qualified Data.Set as Set | |
import GHC.Exts (Constraint) | |
class Functor f where | |
type Object f a :: Constraint |
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 git-ps1 { | |
case $1 in | |
y|yes|on) | |
export GIT_PS1_SHOWDIRTYSTATE=yes | |
export GIT_PS1_SHOWUNTRACKEDFILES=yes | |
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then | |
export PS1='\[\e[0m\e[36m\]\u@\h \[\e[1;39m\]\w\[\e[0;32m\]$(__git_ps1 " (%s)")\[\e[0m\] \\$ '; | |
else | |
export PS1='\[\e[0m\e[31m\]\u \[\e[1;39m\]\w\[\e[0;32m\]$(__git_ps1 " (%s)")\[\e[0m\] \\$ '; | |
fi |
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
// Hello, fellow Swift programmer! | |
// | |
// Here's a demonstration of a few ways of cleaning up the unwrapping of | |
// optionals in Swift. | |
// | |
// Swift is known to have both OO and functional background. Thus, there is | |
// probably some middle ground programming style that is *more* functional than | |
// Objective-C, and probably less so than Haskell. This playground tries to | |
// compare their differences in the pretty common scenario of dealing with | |
// errors or missing input. |
OlderNewer