Skip to content

Instantly share code, notes, and snippets.

@pyrtsa
pyrtsa / example.cpp
Last active August 29, 2015 13:56
C++1y: Using user-defined literals for making `std::chrono::duration`s
#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); }
@bitemyapp
bitemyapp / gist:8739525
Last active May 7, 2021 23:22
Learning Haskell
@ragingwind
ragingwind / Backend Architectures Keywords and References.md
Last active April 17, 2024 10:51
Backend Architectures Keywords and References
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
@pyrtsa
pyrtsa / get_at_it.js
Last active December 11, 2015 06:08
Get at it!
// 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.
@pyrtsa
pyrtsa / holiday.py
Last active October 9, 2015 14:48
Finnish holidays
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)
// 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>
@pyrtsa
pyrtsa / .git-ps1.bash
Last active November 4, 2016 08:00
git-ps1
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
@pyrtsa
pyrtsa / .gitconfig
Created October 31, 2011 10:41
A few `git log` commands where things are nicely aligned
[alias]
l50 = "!f () { git log --abbrev-commit --date=short --pretty=format:'%h%x00%cd%x00%s%x00%an%x00%d' $@ | gawk -F '\\0' '{ printf \"\\033[31m%s\\033[0m \\033[32m%s\\033[0m %-50s \\033[30;1m%s\\033[0m\\033[33m%s\\n\", $1, $2, gensub(/(.{49}).{2,}/, \"\\\\1…\",\"g\",$3), $4, $5 }' | less -R; }; f"
l80 = "!f () { git log --abbrev-commit --date=short --pretty=format:'%h%x00%cd%x00%s%x00%an%x00%d' $@ | gawk -F '\\0' '{ printf \"\\033[31m%s\\033[0m \\033[32m%s\\033[0m %-80s \\033[30;1m%s\\033[0m\\033[33m%s\\n\", $1, $2, gensub(/(.{79}).{2,}/, \"\\\\1…\",\"g\",$3), $4, $5 }' | less -R; }; f"
lg50 = "!f () { git log --graph --color=always --abbrev-commit --date=relative --pretty=format:'%x00%h%x00%s%x00%cd%x00%an%x00%d' $@ | gawk -F '\\0' '{ printf \"%s\\033[31m%s\\033[0m %-50s \\033[32m%14s\\033[0m \\033[30;1m%s\\033[0m\\033[33m%s\\n\", $1, $2, gensub(/(.{49}).{2,}/, \"\\\\1…\",\"g\",$3), $4, $5, $6 }' | less -R; }; f"
lg80 = "!f () { git log --graph --color=always --abbrev-commit --date=re
//
// NSObject+BlockObservation.h
// Version 1.0
//
// Andy Matuschak
// andy@andymatuschak.org
// Public domain because I love you. Let me know how you use it.
//
#import <Cocoa/Cocoa.h>