Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View ymmt2005's full-sized avatar

Yamamoto, Hirotaka ymmt2005

View GitHub Profile
@ymmt2005
ymmt2005 / annotate-id-ns.py
Last active October 9, 2015 00:21
Annotate "nvme id-ns -b" output tersely.
#!/usr/bin/env python
from __future__ import print_function
from argparse import ArgumentParser, RawDescriptionHelpFormatter
import re
import sys
# Constants
HELP_DESCRIPTION = '''\
Annotate id-ns output for humans.
@ymmt2005
ymmt2005 / OSDistro.patch
Created January 14, 2013 07:51
Patch for libvirt virt-install script to install Ubuntu with image ISO file and w/o networking.
--- OSDistro.py.orig 2012-06-15 06:05:53.966087512 +0000
+++ OSDistro.py 2012-06-15 06:09:42.362805372 +0000
@@ -951,7 +951,11 @@
# regular tree:
# http://archive.ubuntu.com/ubuntu/dists/natty/main/installer-amd64/
+ def _set_media_paths(self):
+ self._hvm_kernel_paths = [ ("vmlinuz", "initrd.gz") ]
+
def isValidStore(self, fetcher, progresscb):
@ymmt2005
ymmt2005 / ifenslave.patch
Created January 14, 2013 06:58
Patch for ifenslave-2.6 in Ubuntu 12.04 to modify the timing for enslaving slaves.
--- /etc/network/if-pre-up.d/ifenslave 2012-01-24 02:26:28.000000000 +0900
+++ ifenslave 2012-09-12 01:03:22.558799876 +0900
@@ -224,6 +224,7 @@
# Setup the master interface
early_setup_master
setup_master
+ enslave_slaves
# Indicate that we're done setting up the master
# this is required as ifstate is modified at the beginning
#include <chrono>
#include <typeinfo>
#include <cxxabi.h>
#include <cstdlib>
#include <string>
#include <iostream>
typedef std::chrono::microseconds us_t;
template <typename T>
@ymmt2005
ymmt2005 / auto-insert-cxx.el
Created June 11, 2013 23:36
Emacs skeleton for C++ header files.
(add-hook 'find-file-hook 'auto-insert)
(setq auto-insert-alist
'(("\\.hpp\\'"
nil
'(setq v1 (read-string "Namespace: " "cybozu"))
'(setq v2 (upcase (concat v1 "_"
(file-name-nondirectory
(file-name-sans-extension buffer-file-name))
"_" (file-name-extension buffer-file-name))))
"// " (file-name-nondirectory buffer-file-name) n
@ymmt2005
ymmt2005 / protocol_binary.cpp
Created July 26, 2013 04:55
yrmcds のバイナリプロトコルの自動テストツール(書きかけ)
#include "../src/memcache.hpp"
#include <cybozu/dynbuf.hpp>
#include <cybozu/tcp.hpp>
#define TEST_DISABLE_AUTO_RUN
#include <cybozu/test.hpp>
#include <cybozu/util.hpp>
#include <cstdint>
#include <cstring>
@ymmt2005
ymmt2005 / fizzbuzz.py
Created October 17, 2013 12:49
FizzBuzz using generators.
def fizbuz():
n = 0
while True:
n += 1
yield n
n += 1
yield n
n += 1
yield 'Fizz' # 3
n += 1
@ymmt2005
ymmt2005 / kill_thread.c
Created December 25, 2013 07:07
Kill a specific thread externally by using tgkill(2).
#include <signal.h>
#include <sys/syscall.h> /* For SYS_xxx definitions */
#include <sys/types.h>
#include <unistd.h>
int main() {
pid_t tgid=18456;
pid_t tid=24671;
return syscall(SYS_tgkill, tgid, tid, SIGABRT);
}
@ymmt2005
ymmt2005 / atomic_rename.py
Last active July 4, 2016 09:00
atomic_rename.py
#!/usr/bin/python3
from argparse import ArgumentParser
import os
from os.path import dirname, realpath
from tempfile import NamedTemporaryFile
def syncdir(d: str):
fd = os.open(d, os.O_RDONLY|os.O_DIRECTORY)
os.fsync(fd)
@ymmt2005
ymmt2005 / compressions.txt
Last active October 4, 2016 10:51
gzip, zstd, brotli
Ubuntu VM ディスクイメージを gzip, Zstd, Brotli で圧縮
$ time lzop -d < vm-generic.lzo | gzip > vm-generic.gz
real 0m44.422s
user 0m46.736s
sys 0m1.312s
$ time lzop -d < vm-generic.lzo | zstd > vm-generic.zstd
real 0m9.863s
user 0m10.336s