Skip to content

Instantly share code, notes, and snippets.

@theoremoon
theoremoon / out.csv
Last active July 28, 2018 00:13
同期加算で誤差を減らしていくようなやつです
A C00001 C10000 Nn
0.0000 0.1689 0.0136 107.8424
6.7156 7.6140 6.7031 70.9367
9.9518 10.2794 9.9450 59.2852
8.0321 10.4816 8.0463 48.3563
1.9509 1.3047 1.9560 48.2972
-5.1410 -4.8743 -5.1362 44.6529
-9.5694 -9.6891 -9.5795 40.4456
-9.0399 -9.5145 -9.0418 37.7089
-3.8268 -3.1973 -3.8463 35.8761
@theoremoon
theoremoon / rand.d
Created July 20, 2018 04:17
なんらかの乱数を集計するプログラムです
import std.stdio;
import std.random;
import std.math;
import std.range;
import std.array;
import std.algorithm;
auto boxMuller(T)(double avg, double dist, T uniform)
{
return (sqrt(dist) * sqrt(-2*log(uniform())) * sin(2*PI*uniform()) + avg);
@theoremoon
theoremoon / eulernum.d
Created July 2, 2018 01:56
オイラー数を算出するプログラム例です
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;
/// 任意のマスクにマッチする回数を数える
int filter(const(int[][]) data, const(int[][]) mask)
{
int count = 0;
import std.typecons;
mixin template BinParser()
{
class Nope {}
class A(string[] names, V...) {
auto read(string name, T)() {
return new A!(names ~ name, V, tuple!(T, Nope, Nope, Nope)(T.init, null, null, null));
}
auto should(string name, T, T should_be)() {
@theoremoon
theoremoon / tuple_template.d
Created May 6, 2018 10:54
メソッドチェーンの再帰でtupleに引数を貯める例
import std.stdio;
auto f(T)()
{
class A(U...) {
auto f(V)() {
return new A!(U, V);
}
void p() {
foreach (i, u; U) {
@theoremoon
theoremoon / rec_template.d
Created May 6, 2018 10:53
再帰(?)でテンプレート引数を貯める例
struct A {
int x;
}
void a(string name, T)(ref T v)
{
mixin("v."~name) = 1;
}
import std.stdio;
auto f(string n)() {
import std.stdio;
struct Token
{
string name;
int type;
}
class Node {}
# replace rm with move
gotrash() {
trashdir="$HOME/trash"
mkdir -p $trashdir
for f in $@; do
mv "$f" "${trashdir}/${f:t}_$(date +%s)"
done
}
alias rm='gotrash'
@theoremoon
theoremoon / order.php
Created April 27, 2017 08:19
はるかむかしのやつがのこってたので
<?php
define('JSONFILE', 'your.json');
function isLogin() {
return isset($_SESSION['you']);
}
function h($s) {
return htmlspecialchars($s, ENT_QUOTES);
module.exports = {
entry: './src/index.ts',
output: {
filename: './index.js'
},
module: {
loaders: [
{
test: /\.ts$/,
use: 'awesome-typescript-loader'