Skip to content

Instantly share code, notes, and snippets.

View lotz84's full-sized avatar

Tatsuya Hirose lotz84

View GitHub Profile
@xeno14
xeno14 / gist:6188291aedcb2cd2dc15
Created June 15, 2015 14:30
Compile-time calculation of Pi
#include <cstdio>
#include <ratio>
template <typename R, intmax_t N>
struct ratio_pow {
using prev = typename ratio_pow<R, N-1>::value;
using value = std::ratio<R::num * prev::num, R::den * prev::den>;
};
template <typename R>
@fabichirox
fabichirox / list.md
Last active August 29, 2015 14:23
2015/06/27 できるようになったこと

できるようになったこと

  • Curl コマンドの基礎
  • Curl コマンドでYo API
  • Yoall/
  • git commit
  • OSS commit
  • hubotをherokuで動かす
  • ssh key 設定
  • while true do done
@fabichirox
fabichirox / list.md
Last active August 29, 2015 14:24
2015/07/05 日報

できるようになったこと

  • git の仕組みの薄い理解
  • herokuでpythonのappをデプロイ
  • 公開鍵の考え方の理解

できてなくてやりたいこと

  • bottle-yotoslack

インスコしたもの

  • python 3.2
@karpathy
karpathy / min-char-rnn.py
Last active May 28, 2025 02:25
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
@mathink
mathink / length_as_natrans.v
Last active November 20, 2015 11:42
length は リスト函手から定数函手への自然変換だよ on Coq.
Set Implicit Arguments.
Unset Strict Implicit.
Require Import Setoids.Setoid Morphisms.
Generalizable All Variables.
Class Setoid :=
{
carrier: Type;
equal: carrier -> carrier -> Prop;
@tdoris
tdoris / Promises.md
Last active November 10, 2023 01:15

Does Haskell make promises it can't keep?

or The big problem with wrapping numeric types

When coding financial calculations, it's common to have a variety of numeric values such as Quantity, Price, Amount and so on. In quant finance, these usually refer to the Price observed in the market, a Quantity of shares. A Quantity of shares all traded at a given Price in a given currency will give you an Amount of that currency (the total value of the trade).

It's simple and fun exercise to write the functions you'd need to perform all the correct ways of combining Price, Quantity and Amount. There are a couple of things that don't work as you might expect (e.g., multiplication is ok but you need to think about division semantics.).

Many Haskell tutorials encourage the coder to wrap Double and Int in newtypes like this, so the compiler can help by detecting incorrect combinations of the different types, and so the code documents itself better. e.g.

@twiecki
twiecki / bayesian_neural_network.ipynb
Last active February 22, 2022 01:28
Bayesian Neural Network in PyMC3
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import System.Random
import Control.Monad
main :: IO()
main = print showKiyoshi
getRandomInt :: IO Int
getRandomInt = getStdRandom $ randomR (0,1) :: IO Int
text :: [String]
import System.Random
main = do
gen1 <- getStdGen
let rand = getRandom gen1
print . showKiyoshi . getKiyoshi $ rand
text :: [String]
text = ["zun", "doko", "kiyoshi"]
@PkmX
PkmX / loeb.md
Last active January 9, 2019 15:59
Löb with error handling

Löb with error handling

löb is a well-known function in Haskell for implementing spreadsheet-like behaviors and tying the knot. It is defined as:

loeb :: Functor f => f (f a -> a) -> f a
loeb fs = xs
  where xs = fmap ($ xs) fs