Skip to content

Instantly share code, notes, and snippets.

@mooz
mooz / check-cnf.js
Created December 30, 2011 08:05
CNF (Conjunctive Normal Form)
var cnfs = [
// (a || c) && (c || d || b)
new Term(
Term.AND,
new Term(
Term.OR,
new Term(Term.LITERAL, "a"),
new Term(Term.LITERAL, "c")
),
new Term(
@mooz
mooz / extract_slide.py
Last active October 5, 2023 16:00
Extract a slide image from a photo
# -*- coding: utf-8 -*-
# ============================================================ #
# 写真からスライド領域を切り出して保存。透視変換もおこなう
#
# Usage: python extract_slide.py YOUR_PHOTO
#
# ============================================================ #
import cv2
@mooz
mooz / ar5iv-hash-attacher.user.js
Last active February 26, 2023 13:11
Ar5iv Hash Attacher: Attach a hash to the URL to create a permanent link when elements like sections and figures are clicked
// ==UserScript==
// @name Ar5iv Hash Attacher
// @namespace http://mooz.github.io/
// @version 0.1
// @description When elements like sections and figures are clicked, attach a hash to the URL to create a permanent link
// @author Masafumi Oyamada
// @match https://ar5iv.labs.arxiv.org/html/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=arxiv.org
// @grant none
// ==/UserScript==
@mooz
mooz / zle-tmux.sh
Created November 30, 2012 12:19
zle widget which launches tmux
function tmux-attach() {
# Launching tmux inside a zle widget is not easy
# Hence, We delegate the work to the parent zsh
BUFFER=" { tmux list-sessions >& /dev/null && tmux attach } || tmux"
zle accept-line
}
zle -N tmux-attach
# Define a shortcut key for launching tmux (Ctrl+t)
bindkey '^T' tmux-attach
@mooz
mooz / emacs-regexp-tips.md
Created December 1, 2010 04:57
Emacs でバッファ中の数値をインクリメント

Emacs でバッファ中の数値をインクリメント

こんにちは. 今日はバッファ中の数値をそれぞれインクリメントする方法をご紹介したいと思います.

query-replace-regexp

まず query-replace-regexp を実行します.

そして, 置換対象のパターンに

@mooz
mooz / change_video_playback_speed_ios.md
Last active October 15, 2021 04:19
Bookmarklet for changing video playback speed on iPad/iPhone

Installation

In your browser (e.g., Safari),

  1. Add a dummy bookmark and name it Change playback speed (1.5x)
  2. Change the URL of the bookmark to javascript:(function()%7Bvar%20video%20%3D%20document.querySelector(%22video%22)%3B%20if%20(video)%20%7B%20video.playbackRate%20%3D%201.5%3B%20%7D%7D)()

Usage

On website playing a video, click 1.5x in your bookmarks.

function cc(klass) {
var Traits = function () {};
Traits.prototype = klass.prototype;
return function () {
var instance = new Traits();
var tmp = klass.apply(instance, arguments);
// For builtin-functions
config.TAB_VERTICAL = true;
@mooz
mooz / tiny_segmenter.js
Created May 9, 2020 12:25
TinySegmenter
(function (global) {
global.TinySegmenter = TinySegmenter;
var default_model = {BC1:{IH:-2384,II:3270,IK:-100,NH:2173,OH:-1008,OO:1343},BC2:{AA:-12150,HH:-4329,HI:-978,IH:1459,II:-6625,IO:4584,KI:1578,KK:-11956,KM:-2208,NH:1157,NN:-9390,OH:1131,OI:320,OO:-11227},BC3:{HH:906,IO:614,KK:170},BIAS:2252,BP1:{BB:302,OB:-231,OO:146,UB:282},BP2:{OB:1327,UB:49,UU:-146},BQ1:{BII:-100,OII:252},BQ2:{BHH:434,BHI:455,BIH:-1446,OHH:-802,OKK:-1977,UII:-661},BQ3:{BHH:-148,BHI:139,BIH:58,OHH:1008,UOH:-1190},BQ4:{BAA:-1264,BHH:-2820,BII:-3700,BOO:-353,OHI:-1024,OIH:-893,UHH:-712},BW1:{'、と':49,'いる':462,'うし':-2206,'から':1819,'こと':2372,'した':315,'して':1779,'しょ':1428,'そこ':1096,'そし':-1226,'たち':1283,'った':2355,'つい':-384,'てい':1550,'てき':250,'てく':-346,'てし':-784,'でも':589,'どこ':1229,'ない':6901,'なっ':505,'にし':1693,'ませ':1564,'まる':-3912,'よう':2051,'よっ':-317,'をし':457,'同時':-3330,'本当':-3421},BW2:{'——':-12400,'──':-6300,'いう':-4120,'いた':955,'いは':-3214,'から':-3546,'こと':-8616,'この':-4459,'させ':759,'され':9917,'しい':-642,'した':2787,'その':-5916,'たち':-3820,'