Skip to content

Instantly share code, notes, and snippets.

@jewel12
jewel12 / dayone.el
Created October 29, 2012 19:42
Create a new entry of DayOne on Emacs.
(defvar path-to-dayone "/usr/local/bin/dayone"
"Executable path to DayOne CLI")
(defun dayone-save-new-entry ()
"Save buffer as a new DayOne entry"
(interactive)
(if (executable-find path-to-dayone)
(call-process-region
1 (point-max) path-to-dayone nil nil nil "new")))
@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 / gist:2873112
Created June 5, 2012 06:30
move-to-next-blank-line
(defun blank-line? ()
(string-match "^\n$" (substring-no-properties (thing-at-point 'line))))
(defun move-to-next-blank-line ()
(interactive)
(progn (forward-line 1)
(if (blank-line?) () (move-to-next-blank-line))))
(defun move-to-previous-blank-line ()
(interactive)
@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 / Hachioji.pm #37.md
Last active January 4, 2016 11:08
Hachioji.pm #37

Perl最高!Emacs最高!

@jewel_x12 です。

最近はPHPを書いています。Niigata.pmにいたりしてました。Perlは書きません。

今後ともよろしくお願い申し上げます。

今書いているコードのテストファイルを開きたい

今開いているファイルがテストのファイルっぽくなかったら、テストファイルっぽいのをhelm-ls-gitの入力にする。

@jewel12
jewel12 / age.sh
Created January 9, 2014 16:42
agで検索してpercolで絞り込みエディタで開く
function age() {
if [ $# -eq 1 ]; then
ag --noheading $1 | percol | sed 's/^\(.*\):\(.*\):.*/\1 +\2/' | xargs $EDITOR
else
echo "Usage: age QUERY"
fi
}
@jewel12
jewel12 / focus_next_window.js
Last active December 28, 2015 16:19
同じアプリケーションで別のウィンドウにフォーカスする Slate.app の設定
// 同じアプリケーションで別のウィンドウにフォーカスする
S.bind('n:alt,ctrl', function() {
function get_next_win(windows) {
truth_values_of_is_main = _.map(windows, function(w){ return w.isMain(); })
next_idx = _.indexOf(truth_values_of_is_main, 1) + 1;
if (next_idx >= _.size(windows)) { return windows[0]; }
return windows[next_idx];
}
windows = [];
slate.app().eachWindow(function(win){ windows.push(win); });
; Project Euler 1
(defn multiple-numbers-of-3-or-5 []
(defn whole-numbers [] (iterate inc 1))
(defn multiple-of-3-or-5? [x]
(if (or (zero? (rem x 3))
(zero? (rem x 5)))
true false))
(filter multiprable? (whole-numbers)))
@jewel12
jewel12 / join-words-by-underscore.el
Created May 11, 2013 19:16
カーソル手前の単語群をアンダースコアでつなげる
(defun join-words-by-underscore ()
(interactive)
(save-excursion
(save-restriction
(looking-back "[\s-\]*\\(\[a-zA-Z0-9\s-\]+\\)" nil t)
(narrow-to-region (match-beginning 1) (match-end 1))
(beginning-of-line)
(replace-string " " "_"))))