Skip to content

Instantly share code, notes, and snippets.

@emasaka
emasaka / cowsay-mbswidth.patch
Created December 1, 2015 09:15
cowsay: fix width of multibyte characters
--- cowsay.orig 2015-12-01 18:05:41.636619759 +0900
+++ cowsay 2015-12-01 18:11:36.999132910 +0900
@@ -11,6 +11,7 @@ use Text::Wrap qw(wrap fill $columns);
use File::Basename;
use Getopt::Std;
use Cwd;
+use Text::CharWidth qw(mbswidth);
if (${^UTF8LOCALE}) {
binmode STDIN, ':utf8';
@emasaka
emasaka / pipeline.rb
Created November 1, 2014 13:09
shell-like pipeline in Ruby DSL (ver. 2)
#!/usr/bin/env ruby
require 'open3'
module PipeOperator
refine Array do
def |(x)
PipeLine.new(self) | x
end
end
@emasaka
emasaka / pipeline.rb
Created September 29, 2014 05:05
shell-like pipeline in Ruby DSL
#!/usr/bin/env ruby
module PipeOperator
refine Array do
def |(x)
PipeLine.new(self) | x
end
end
end
#!/usr/bin/env perl
use strict;
use warnings;
use 5.014;
use File::Basename qw(basename);
package NoteMu2Feed {
use LWP::UserAgent;
use JSON qw(decode_json);
use XML::Feed;
@emasaka
emasaka / NEWS-bash-4.3-j.txt
Last active March 16, 2018 03:49
bash 4.3のNEWSの私訳
これはbash-4.2のリリース以降bash-4.3に追加された新機能の簡潔な説明です。
いつもどおり、完全な説明を探している場合はマニュアルページ (doc/bash.1)
が適切です。
1. Bashの新機能
a. 補完の動作の`helptopic'は、シェル組み込みコマンドだけでなくすべての
ヘルプのトピックに対応します。
b. 組み込みコマンド`help'で、最初に前方一致が行われることはなくなりま
@emasaka
emasaka / dsl.mk
Created October 12, 2013 07:20
Makefile for GNU make 4.0 that rules are written by embedded Guile.
define dsl
(use-modules (srfi srfi-1))
(define targets '())
(define (showtargets)
(string-join (reverse targets) "\n") )
(define-macro (push! place item)
`(set! ,place (cons ,item ,place)) )
(defn encoded-num-seq [n digits]
(let [base (.length digits)
enc1 (fn [n r]
(let [q (quot n base) r2 (str (.charAt digits (rem n base)) r)]
(if (zero? q) r2 (recur q r2)) ))]
(map #(enc1 % "") (iterate inc n)) ))
(defmacro nth [c i & nf]
(if (and (list? c) (= (first c) 'encoded-num-seq))
(let [(f a1 a2) c] `(first (~f (+ ~i ~a1) ~a2)))
@emasaka
emasaka / enkaku.sh
Created April 1, 2013 10:44
draw circle by shell script
#!/bin/bash
R=36
RATIO=2
for ((y = -R; y <= R; y += RATIO)); do
x=$(dc -e "$R 2^${y/-/_} 2^-vp")
printf '%*s%*s%*s\n' $((R - x)) x $x '' $x x
done
@emasaka
emasaka / ltsv.clj
Last active December 12, 2015 08:39
LTSV parser by Clojure
;; LTSV (Labeled Tab-separated Values) parser by Clojure
(use '[clojure.string :only [split]])
(defn ltsv-parse-line
"Parses one LTSV line. Returns a map."
[^String line]
(reduce (fn [r s] (let [[k v] (split s #":" 2)] (assoc r k v)))
{} (split line #"\t") ))
@emasaka
emasaka / autonot.rb
Created December 14, 2012 08:40
! someobject.foo? -> someobject.not_foo?
# inspired by http://www.msng.info/archives/2012/12/php-not.php
module AutoNot
def method_missing(method, *args)
if /\Anot_(.*\?)\z/ =~ method
! send($1, *args)
end
end
end