Skip to content

Instantly share code, notes, and snippets.

@jewel12
jewel12 / gen.rb
Created June 1, 2019 02:13
(変な)おもしろコード見せ合い会
require 'json'
probs = Hash.new { |h,k| h[k] = {} }
STDIN.each do |l|
d = JSON.load(l.chomp)
probs[d['l']][d['r']] = (d['prob'] * 1000).to_i
end
def gen(probs)
@jewel12
jewel12 / q_learning.py
Last active December 21, 2016 09:06
ソートしてくれ頼む
# coding: utf-8
import random
import difflib
import json
import csv
import sort_runner as sr
GAMMA = 0.8
EPSILON_INIT = 1
@jewel12
jewel12 / ConsistentHash.hs
Last active March 13, 2016 13:41
ConsistentHashing
module ConsistentHash where
import Data.Map as M
import Data.List as L
import Data.ByteString.Lazy.Char8
import Data.Digest.Pure.MD5 hiding (hash)
type Key = String
type Node = Key
type Nodes = [Node]
@jewel12
jewel12 / midori-chap-9.ipynb
Created May 13, 2015 11:29
みどり本9章
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jewel12
jewel12 / kanidouraku.elm
Created March 4, 2015 17:18
kanidouraku.elm
import Keyboard
import Signal (..)
import Time (..)
import Color(rgb)
import Graphics.Element (..)
import Graphics.Collage (..)
import Random
import Time
type ClawPos = Left | Right
@jewel12
jewel12 / pretty_cure_printer.rb
Created August 23, 2014 07:08
Pretty(Cure)Print
# -*- coding: utf-8 -*-
require 'pp'
require 'rubicure'
module PrettyCurePrinter
# 設定ファイルに書いた方がいい
# precure_name => [foreground, background]
PRECURE_COLOR_SETTING = {
'キュアブラック' => [:white, :black],
'キュアホワイト' => [:black, :white],
@jewel12
jewel12 / index.html
Created August 2, 2014 08:34
HASH COLOR
<!DOCTYPE html>
<html lang="en">
<head>
<meata charset="UTF-8">
<title>HashColor</title>
<style>
body {
text-align: center;
font-family: arial;
@jewel12
jewel12 / Guardfile
Created May 28, 2014 16:30
メモの中にファイル名とカテゴリを書いておくとカテゴリ名のディレクトリを作って勝手にcpしてくれるやつをとりあえず
guard :shell do
watch 'tmp.md' do |f|
lines = open(f.first).readlines
file_name = $~[1] if lines.any?{ |l| l =~ /^__(.+)__$/ }
category = $~[1] if lines.any?{ |l| l =~ /^\[(.+)\]$/ }
if file_name && category
FileUtils.mkdir_p(category)
FileUtils.cp 'tmp.md', category + '/' + file_name
@jewel12
jewel12 / colorer.rb
Created May 19, 2014 16:07
自動でログ色付け君マシーン
require 'rainbow'
class WordFreq < Hash
def initialize
super(0)
end
def add(w)
self[w] += 1
end
@jewel12
jewel12 / t.rb
Created March 13, 2014 18:31
1時間単位で開始時間と終了時間が与えられたとき、全ての時間を1時間単位で小さいほうから列挙するリストを返す関数
# -*- coding: utf-8 -*-
# https://twitter.com/katzchang/status/444136941605224448
# is(hoge('2014-01-01 01:00', '2014-01-01 03:00'), ('2014-01-01 01:00', '2014-01-01 02:00', '2014-01-01 03:00')) より
# 1時間単位で開始時間と終了時間が与えられたとき => YYYY-mm-dd HH:00 が入力されるものだと予想
# 寝る
require 'time'
module RefinedTime