Skip to content

Instantly share code, notes, and snippets.

View tkrs's full-sized avatar
🤯
I may be slow to respond.

Takeru Sato tkrs

🤯
I may be slow to respond.
  • Gunma, Japan
  • 04:25 (UTC +09:00)
View GitHub Profile
@tkrs
tkrs / Main.java
Last active August 29, 2015 14:09
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.stream.IntStream;
public class Main {
public static void main(String[] args) throws Exception {
int ans = new BufferedReader(
new InputStreamReader(System.in))
.lines()
.skip(1)
@tkrs
tkrs / yaml_load.vim
Created November 28, 2014 18:23
This scripts load yaml on the VIM using the if_python.
function! s:load_yaml(filename)
python << EOS
import vim, yaml
with open(vim.eval('a:filename'), 'r') as f:
obj = yaml.load(f)
obj_hash = str(obj).replace('None', '{}')
vim.command('let l:ret = %s' % obj_hash)
EOS
return l:ret
endfunction
@tkrs
tkrs / FizzBuzz.hs
Created December 2, 2014 19:06
FizzBuzz one-liner on Haskell.
f = zipWith3 (\a b c -> let x = b ++ c in if null x then show a else x) [1..] (cycle ["", "", "Fizz"]) (cycle ["", "", "", "", "Buzz"])
@tkrs
tkrs / Test.go
Last active April 1, 2019 10:20
Example golang of channels and syn.WaitGroup
package main
import (
"fmt"
"runtime"
"sync"
)
func init() {
fmt.Println("func init()")
@tkrs
tkrs / GenRsa.go
Last active August 29, 2015 14:11
Generate rsa public key
package main
import (
"crypto/rand"
"crypto/rsa"
"log"
)
func main() {
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
var Dir [][]int
@tkrs
tkrs / euclidean_distance.py
Last active July 29, 2017 16:01
DistanceAlgorithms
#!/usr/bin/env python3
import math
def distance(xs, ys):
return math.sqrt(sum([math.pow(q - p, 2) for (q,p) in zip(xs, ys)]))
a = [1,2,4,5,2]
@tkrs
tkrs / rpn.hs
Created July 6, 2015 00:40
reverse-polish-notation
import System.Environment
main = do
expr <- getArgs
print $ head $ foldl rpn [] expr
rpn :: [Double] -> String -> [Double]
rpn [] a = [read a]
rpn xs@[_] a = (read a) : xs
rpn xs@(x:y:xs') a | a == "+" = (x + y) : xs'
@tkrs
tkrs / FizzBuzz.java
Last active June 6, 2017 12:20
Challenge the FizzBuzz for some languages.
public class FizzBuzz{
public static void main(String...args){
java.util.stream.Stream.iterate(1, i -> i + 1)
.map(i -> {
String x=(i % 3 < 1 ? "Fizz" : "") + (i % 5 < 1 ? "Buzz" : "");
return x.equals("") ? i : x;
})
.limit(100)
.forEach(System.out::println);
}
@tkrs
tkrs / ShapelessAutomaticCCDerivation.scala
Last active September 22, 2016 05:50
Automatic case class derivation in shapeless
import shapeless._, labelled._, syntax._, ops.record._
import scala.annotation.implicitNotFound
object derive {
sealed trait KV
case class Obj(xs: List[(KV, KV)]) extends KV {
def ++(j: KV): KV = j match {
case Obj(xxs) => copy(xs ++ xxs)