Skip to content

Instantly share code, notes, and snippets.

@snt
snt / findgap.hs
Created July 5, 2013 07:25
gaps larger than 3 seconds of the log in the format: yyyy-mm-dd HH:MM:SS.sss/JST (blah, blah, blah) something goes wrong findgap.py runs in 30 seconds for 612000 lines of log findgap.hs does in 7 minutes... what's wrong? As far as I know (by ghc -prof), regex part is its bottleneck.
import Text.Regex.TDFA
import Data.Time.Format
import Data.Time.Clock
import System.Locale
import Data.Maybe
import qualified Data.ByteString.Lazy.Char8 as B
parseTimestamp :: B.ByteString -> UTCTime
parseTimestamp s = fromJust $ parseTime defaultTimeLocale "%F %T%Q/%Z" (B.unpack s)
@snt
snt / add to .bashrc
Created August 24, 2013 07:32
Record a ssh log in Cygwin. Cygwin is slow on creating new process with `$( ... )`, so `tee` and add `$(date)` on each line would be extremely slow. run `sshlog` instead of `ssh`
function sshlog () {
if [ "x$1" = "x" ]; then
echo "simple logging wrapper for ssh."
echo "use as usual ssh"
ssh
else
TARGET=$1
mkdir -p ~/ssh-log
LOGFILE=~/ssh-log/$TARGET.$(date +%Y-%m-%d_%H.%M.%S).log
ssh $@ | python $HOME/timestamp-logger.py $LOGFILE
@snt
snt / gist:6808138
Created October 3, 2013 11:12
REXML parsing example. Parse and format recursively under the directory specified as first arg.
require 'rexml/document'
def showxml(fn)
doc = REXML::Document.new(open(fn))
doc.elements.each("//.") { |e|
x=e
ps = []
while x != nil do
ps << x.name
x = x.parent
(defn luhn-check-digit [numStr]
(let [char-to-integer (fn [c] (Integer/parseInt (str c)))
prod-tuple (fn [t] (* (t 0) (t 1)))
sum-digits (fn [n] (if (> n 9) (- n 9) n))]
(->> numStr
reverse
(map char-to-integer)
(zip (cycle [2 1]))
(map (comp sum-digits prod-tuple))
(reduce +)
@snt
snt / github_pull-request_summary.md
Last active January 1, 2016 08:59
プルリクエストを送る前に `rebase` する話

プルリクエストを送る前に rebase するためのメモ

  1. まず、こわくないgit を読む。
  2. 具体的な手順は、GitHubへpull requestする際のベストプラクティス を参考にする。
  3. すでに自分のgithubレポジトリに push しちゃった場合は、普通の push ができません。でも、 git push -f がちょっとやだなーという人は、 Rebase on github branch にあるように、 rebase してからプルリクエストを送るためのブランチを作ってしまうのがきっと良い。

AIXのkshのプロンプトをCygwin風に

ターミナルのタイトルバーも更新する。

export PS1="^[]2;$(id -n -u)@$(hostname) \${PWD}^G^[[32m$(id -n -u)@$(hostname) ^[[33m\${PWD}^[[0m
$ "

ただし、 ^[C-v + C-q + C-[ (C- はコントロールを押しながらを意味する) と入力。

@snt
snt / luhn.clj
Created April 17, 2014 06:51
Luhn algorithm checker
(ns cl1.core)
(defn prod-digits
[ps]
(->> ps
(map #(reduce * %1))
(map #(cond
(> %1 9) (- %1 9)
:else %1))
(reduce +)))
@snt
snt / IR_Recorder.ino
Created August 30, 2014 02:41
http://www.atmarkit.co.jp/ait/articles/1408/27/news036_2.html を試したけれど、ループ内で 毎回 `loop()` を呼び出しているのがオーバーヘッドになっているのか、長さが正しく記録できてなかったので、 `loop()` 内でループするように変更。
#define IR_RECV_PIN 2
#define IR_TIMEOUT_USEC 1000000
void setup()
{
Serial.begin(115200);
pinMode(IR_RECV_PIN, INPUT);
}
void loop()
@snt
snt / build.sbt
Created October 27, 2014 16:23
Gatling on sbt (scala 2.11 is not compatible with gatling 1.0)
// project/pugins.sbt:
// addSbtPlugin("io.gatling" % "sbt-plugin" % "1.0")
name := "gatling example"
version := "1.0"
scalaVersion := "2.10.4"
libraryDependencies ++= Seq(
@snt
snt / Makefile
Created December 3, 2014 07:39
ATmega328P + XBee-zb sends ZigBee message to coordinator (simple test).
# Name: Makefile
# Author: <insert your name here>
# Copyright: <insert your copyright message here>
# License: <insert your license reference here>
# This is a prototype Makefile. Modify it according to your needs.
# You should at least check the settings for
# DEVICE ....... The AVR device you compile for
# CLOCK ........ Target AVR clock rate in Hertz
# OBJECTS ...... The object files created from your source files. This list is