Skip to content

Instantly share code, notes, and snippets.

@yuki-takeichi
yuki-takeichi / papertrail-logfilter
Created August 12, 2016 03:58
papertrail-logfilter
#! /bin/bash
# extracts a log file for a specified host from Papertrail tsv file
HOSTNAME=$1
FILENAME=$2
TSVFILE=$3
awk -F '\t' "{if (\$5 == \"$HOSTNAME\" && \$9 == \"$FILENAME\") print \$10}" $TSVFILE
@yuki-takeichi
yuki-takeichi / set-hostname.patch
Created July 13, 2016 06:06
Configuring FQDN for GCE instance
diff -Naur before/usr/share/google/set-hostname after/usr/share/google/set-hostname
--- before/usr/share/google/set-hostname 2016-03-16 18:30:48.000000000 +0900
+++ after/usr/share/google/set-hostname 2016-03-16 18:34:57.000000000 +0900
@@ -14,6 +14,9 @@
# Deal with a new hostname assignment.
+# *** The below line is added by patching. ***
+new_host_name=$(curl --fail --silent http://metadata/computeMetadata/v1/instance/attributes/hostname -H "Metadata-Flavor: Google")
+
@yuki-takeichi
yuki-takeichi / wsay
Created July 11, 2016 05:02
Weblio say command
#!/bin/bash
WORD=$1
TMP_FILE=/tmp/wsay.wav
[ -z "$WORD" ] && echo "arg missing" && exit 1
WAV_URL=$(curl -s http://ejje.weblio.jp/content/$WORD | grep playSwfSound | sed -e "s/^.*playSwfSound('\([^']*\)', *'\([^']*\)'.*).*\$/\1\2\.wav/")
curl -s -o $TMP_FILE $WAV_URL
afplay $TMP_FILE
@yuki-takeichi
yuki-takeichi / notify
Last active August 16, 2016 07:45
Notify elapsed seconds when command is finished
#!/bin/bash
# Notify elapsed seconds when command is finished
# (Mac OS X only)
# How to setup:
# 1. `brew install terminal-notifier`
# 2. Put this file in your /bin dir
# How to use:
@yuki-takeichi
yuki-takeichi / mongofdtest.js
Last active February 24, 2016 02:48
mongo fd test
var MongoClient = require('mongodb').MongoClient;
var mongoUri = "mongodb://192.168.11.2:27017/hoge";
function mapM(fs, cb) {
var xs = [];
function _mapM(fs, cb) {
var f = fs.shift();
f(function(x) {
xs.push(x);
if (fs.length == 0) {
@yuki-takeichi
yuki-takeichi / Makefile
Created February 23, 2016 12:11
openssl test
hoge: hoge.c
gcc -o $@ -g $^ `pkg-config --cflags --libs /usr/lib/x86_64-linux-gnu/pkgconfig/openssl.pc`
.PHONY: clean run
clean:
rm -rf hoge hoge.o
run: hoge
./hoge
@yuki-takeichi
yuki-takeichi / nginx.conf
Created December 20, 2015 08:55
Nginx reverse proxy for debugging
worker_processes 1;
events {
worker_connections 1024;
}
http {
log_format bodylog '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" $request_time '
@yuki-takeichi
yuki-takeichi / new_macbook.md
Last active January 8, 2016 03:38
MacBook入手したらやること

前提

  • OS X Yosemite (10.10.5)
  • MacBook Pro (Retina, 15-inch, Mid 2015)

とりあえずhomebrew / homebrew-caskを導入

これやらないとなにも始まらない。

Xcode / Xcode Command Line Tools 入れる

#!/bin/sh
## see https://pqrs.org/osx/karabiner/document.html.ja#export
cli=/Applications/Karabiner.app/Contents/Library/bin/karabiner
$cli set remap.jis_command2eisuukana_prefer_command 1
/bin/echo -n .
/bin/echo
@yuki-takeichi
yuki-takeichi / pango.rb
Last active October 29, 2015 13:48
homebrew pango 1.36.1 with patch
# This fomula is based on: https://raw.githubusercontent.com/Homebrew/homebrew/108279f2050e8768dd8ffd372285d09b6b00d9b7/Library/Formula/pango.rb # pango 1.36.1
require 'formula'
class Pango < Formula
homepage 'http://www.pango.org/'
url 'http://ftp.gnome.org/pub/GNOME/sources/pango/1.36/pango-1.36.1.tar.xz'
sha256 '42e4b51cdc99e6878a9ea2a5ef2b31b79c1033f8518726df738a3c54c90e59f8'
option 'without-x', 'Build without X11 support'