Skip to content

Instantly share code, notes, and snippets.

@mooz
mooz / .rbindkeys.rb
Created November 1, 2014 14:35
rbindkeys helper
# Load rbindkeys-helper
require "path-to-rbindkeys-helper"
# Emacs-like settings
def define_emacs_keys()
bind "C-g", "ESC"
# cursor move
bind "C-f", "<right>"
bind "C-b", "<left>"
@mooz
mooz / byte-in-various-units.el
Created October 6, 2014 05:16
Display `size-byte' in various units
(defun my:byte-to-various-units (size-byte)
"Display `size-byte' in various units."
(interactive "nBytes: ")
(let ((size size-byte)
(size-kib size-byte))
(with-output-to-temp-buffer "*unit*"
(princ (format "%d B\n-----------\n" size-byte))
(dolist (unit '("K" "M" "G" "T" "P"))
(setq size (/ size 1000.0))
(setq size-kib (/ size-kib 1024.0))
@mooz
mooz / perf.rb
Created February 18, 2014 01:16
perf made easy
#!/usr/bin/env ruby
require "rios/easy"
# http://ascii-table.com/ansi-escape-sequences.php
key_remaps = {
"j" => "\e[B", # down
"k" => "\e[A", # up
"o" => "\r\n", # enter
"u" => "\e[D", # left
@mooz
mooz / parse-mozilla-ast.js
Created February 1, 2013 13:33
Use Reflect API from xpcshell
// Reflect API from xpcshell
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
function openFile(aPath) {
var file = Cc["@mozilla.org/file/local;1"]
.createInstance(Ci.nsILocalFile);
file.initWithPath(aPath);
@mooz
mooz / fix-japanese-number-usages.el
Last active December 10, 2015 20:58
Fix improper Japanese number usages
(defun fix-japanese-number-usages ()
"Fix improper japanese number usages like 1つ and 2つ."
(interactive)
(require 'japan-util)
(require 'cl)
(let ((from-regexp "\\([1-9123456789]+\\)[ \n\r\t]*つ")
(to-regexp "\\,(replace-digit-to-japanese \\1)つ")
(japanese-numbers (list "零" "一" "二" "三" "四" "五" "六" "七" "八" "九" "十")))
(flet ((query-replace-read-from
(prompt regexp-flag)
@mooz
mooz / fix-minibuffer-history.el
Created December 6, 2012 15:36
Fix minibuffer-history
(setq minibuffer-history
(mapcar (lambda (history-string)
(substring-no-properties history-string))
(remove-if-not #'stringp minibuffer-history)))
@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 / magit-blame-ignore-whitespace.el
Created November 28, 2012 03:13
Ignore coding-style related changes in magit-blame
(defadvice magit-blame-file-on (around magit-blame-ignore-whitespace activate)
(let ((buffer (ad-get-arg 0)))
(save-excursion
(with-current-buffer buffer
(save-restriction
(with-temp-buffer
(magit-git-insert (list "blame"
"-w" ; ignore coding-style related changes
"--porcelain" "--"
(file-name-nondirectory
@mooz
mooz / pretty-magit-log.el
Created November 21, 2012 05:18
Pretty magit-log
;; Display commit author and datetime in magit-log
(setq magit-present-log-line-function 'my:magit-present-log-line)
(defface my:magit-log-author
'((((class color) (background light)) :foreground "SkyBlue")
(((class color) (background dark)) :foreground "SkyBlue"))
"Face for the sha1 element of the log output."
:group 'magit-faces)
@mooz
mooz / lazyarray.py
Created November 7, 2012 10:08
Lazy array
class LazyArray(object):
"""
Wraps an iterable object and provides lazy array functionality,
namely, lazy index access and iteration. Lazily got iteration
results are cached and reused to provide consistent view
for users.
"""
def __init__(self, iterable_source):
self.source = iterable_source