Skip to content

Instantly share code, notes, and snippets.

@na-o-ys
na-o-ys / atcoder.hs
Last active April 22, 2016 09:01
Haskell scraping
import Text.HTML.Scalpel
import Control.Applicative
import Control.Monad
data Submission
= AcSubmission {
createdTime :: String,
title :: String,
user :: String,
language :: String,
@na-o-ys
na-o-ys / anonymous_rec.cpp
Created May 20, 2016 00:41
Anonymous Recursion in C++
// $ g++-4.9 -std=c++1y anonymous_rec.cpp
#include <iostream>
template<typename Func>
struct fixed {
Func f;
template<typename... Args>
auto operator()(Args... args) {
return f(fix(f), args...);
@na-o-ys
na-o-ys / a_1.rb
Last active October 5, 2016 01:04
だんだん速くなるfizzbuzz
max = ARGV[0].to_i
1.upto(max) do |i|
if i % 15 == 0
puts "FizzBuzz"
elsif i % 3 == 0
puts "Fizz"
elsif i % 5 == 0
puts "Buzz"
else
#! /usr/bin/env ruby
require 'pp'
source = $*[0]
iseq = File.basename(source, ".*") + ".iseq.rb"
open(iseq, 'w').puts(
"@iseq = " +
RubyVM::InstructionSequence.compile_file(source).to_a.pretty_inspect
)
# value = object | array | string | number | true | false | null
# object = { string : value \{ , string : value \} }
# array = [ value \{ , value \} ]
#
# string = " .* "
# number = -?\d+(\.\d+)?([eE][-+]?\d+) -- "10", "-3.1", "0.34E-6"
# true = true
# false = false
# null = null
#include <bits/stdc++.h>
using namespace std;
random_device rnd;
mt19937 mt(rnd());
void print_array(int* arr, int len) {
cout << *arr;
while (--len) cout << ", " << *(++arr);
@na-o-ys
na-o-ys / circleci-cache.sh
Created November 17, 2016 08:49
yarn_de_kaiketu
####
# CircleCI のキャッシュを functions/*/node_modules に対して効かせるためのスクリプト.
# CircleCI 上でのみ実行される.
#
# ~/node_modules_cache をキャッシュディレクトリとして,
# 1. キャッシュのリストア
# 2. functions/* で npm install
# 3. キャッシュの保存
# を行う.
####
@na-o-ys
na-o-ys / src.ts
Last active November 29, 2016 00:31
async/await と generator
// compile: tsc src.ts --lib es2017,dom -t es2015
// 1. Async/Await
async function concatPromises(): Promise<string> {
const v0 = getValue()
const v1 = await getPromise1()
const v2 = await getPromise2()
return v0 + v1 + v2
}
concatPromises().then(console.log) //=> Value: helloworld
@na-o-ys
na-o-ys / type_level_xor.ts
Created February 9, 2017 09:06
A type level (compile time) NAND and XOR evaluation in TypeScript
type T = 1
type F = 0
function nand(v1: T, v2: T): F;
function nand(v1: T, v2: F): T;
function nand(v1: F, v2: T): T;
function nand(v1: F, v2: F): T;
function nand(v1, v2) {
return 0 // dummy
}
@na-o-ys
na-o-ys / type_level_fizzbuzz.ts
Last active July 24, 2018 10:18
A type level FizzBuzz in TypeScript.
type Zero = 0
type Num = Zero | { 0: Num }
const any: any = null
function succ<T>(v: T): { 0: T } {
return any
}
type FizzNum = Zero | {0:{0:{0: FizzNum }}}