Skip to content

Instantly share code, notes, and snippets.

View petitviolet's full-sized avatar
🕶️
😃

petitviolet petitviolet

🕶️
😃
View GitHub Profile
@petitviolet
petitviolet / add_dictionary.py
Last active October 1, 2020 16:29
人名をMeCabの辞書に登録するためのスクリプト. 編集権限が無くても使える (http://d.hatena.ne.jp/petitviolet/20130214/1360809625
# -*- encoding:utf-8 -*-
import os
import sys
csv_path = '/home/hoge/user_dic/celebs.csv' # ユーザー辞書の元となるファイル
def add_dic(fname):
'''MeCabで使う辞書に人名を追加します
更新する人名はcsv形式のfname,
csvじゃないとき(人名を引数にした時)はそれ自体
更新するユーザー辞書は/home/hoge/user_dic/celebs.csv
@petitviolet
petitviolet / Cargo.toml
Last active September 6, 2020 14:26
Simple logger implementation in Rust
[dependencies]
log = { version = "0.4", features = [ "std" ] }
@petitviolet
petitviolet / main.dig
Created April 30, 2020 05:37
digdag's `http_call>` operator sample
+run_workflow:
http_call>: http://$(ip):8000/http_call_dig
retry: false
_retry: 2
@petitviolet
petitviolet / route.go
Created April 29, 2020 11:39
oEmbed API for blog.petitviolet.net
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"regexp"
@petitviolet
petitviolet / rstruct.rb
Last active January 12, 2020 14:57
Struct implemented with Ruby
module Rstruct
def self.new(*attributes)
names = caller.map do |stack|
# ".../hoge.rb:7:in `<module:Hoge>'"
if (m = stack.match(/\A.+in `<(module|class):(.+)>.+/))
m[2]
end
end.reject(&:nil?)
file_name, line_num = caller[0].split(':')
line_executed = File.readlines(file_name)[line_num.to_i - 1]
@petitviolet
petitviolet / graphiql.html
Created December 21, 2019 11:47
GraphQL Web UI with text box to edit AccessToken
<!-- https://github.com/howtographql/sangria/blob/master/src/main/resources/graphiql.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="robots" content="noindex" />
<meta name="referrer" content="origin" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>GraphiQL</title>
<style>
@petitviolet
petitviolet / tracer.rb
Created December 17, 2019 14:25
Tracing method calls using TracePoint
class Debugger
def initialize(events)
@tp = TracePoint.new(*(events || %i[call b_call raise])) do |tp|
tp.binding.irb
end
@tp.disable
end
def trace(&block)
@tp.enable
@petitviolet
petitviolet / set_map_is_slow.md
Last active September 25, 2019 08:20
[Scala]Set#map is slow

Set#map is slow

example code

Implement custom class with overriding hashCode and equals methods.

case class Value(x: Int) { 
    override def hashCode = { 
        println(s"hashCode: $x")
" general
set autoupdategist " gistの設定を自動反映
let scrollstep = 150
let fullpagescrollpercent = 100
set smoothscroll
set noautofocus " サイトを開いた時に入力欄にフォーカスが奪われるのを抑止
let searchlimit = 20
let barposition = "bottom"
@petitviolet
petitviolet / bench_dict.py
Created December 19, 2014 08:43
python dict perfomance
# -*- encoding:utf-8 -*-
'''
'''
from collections import (defaultdict, Counter)
from functools import wraps
from datetime import datetime
N = 10000000
def timer(func):