oinume journal

Scratchpad of what I learned

in English

Generating an unpredictable random value in Go

There are a lot of examples to use math/rand. However, should use crypto/rand if you want to generate an unpredictable random value. That's because crypto/rand uses getrandom(2) if available, /dev/urandom otherwise on Linux. As a real worl…

go test in practice

This blog post describes basics and practical examples of go test. Go’s automated test mechanism is well designed and easy to use. I’ll show you some techniques of go test in this article. What is go test go test is a command to run automa…

Arguments to defered functions are evaluated when the defer executes

The arguments to the deferred function (which include the receiver if the function is a method) are evaluated when the defer executes, not when the call executes. Effective Go - The Go Programming Language I sometimes make a mistake that d…

3 things I do after installing Nodejs

Installing latest npm $ npm install -g npm@latest Disabling npm’s progress bar Disabling progress bar for faster npm install. $ npm set progress=false See Progress bar noticeably slows down npm install · Issue #11283 · npm/npm Installing n…

Go Tip: Don't take the address of loop variable

stackoverflow.com If you take the address of loop variable, it may cause a bug which all values are same. You might expect following program prints 5 10 15 but it prints 15 15 15. That’s because loop variable v is initialized just once. pa…

First loaded configuration becomes default_server in nginx

How nginx processes a request server { listen 80; server_name example.org www.example.org; ... } server { listen 80; server_name example.net www.example.net; ... } server { listen 80; server_name example.com www.example.com; ... } In this …

Sorting processes by memory usage

$ ps aux --sort -rss Sorted by ascending order if you don't add -. alvinalexander.com

Making an enviroment to learn ES6 with babel

This is a just memo for me who is a beginner of front-end development.

Parsing MySQL's URL in Python3

Just add urllib.parse.uses_netloc.append("mysql") if you want to parse URL such as mysql://root:pass@localhost/demo. #!/usr/bin/env python import urllib.parse urllib.parse.uses_netloc.append("mysql") if __name__ == "__main__": url_str = "m…

Sending pull-request only with terminal and keyboard

Sending pull-request only with terminal and keyboard. Mac, Terminal and hub command are required.

Logging into dmm.com by Selenium

I use Selenium to log into dmm.com because dmm.com requires JavaScript enabled browser. Here is a sample code. You can see Firefox is launched and automatically logging into dmm.com if you use Firefox instead of PhantomJS. login_dmm.py #!/…

Get auto increment values from MySQL information schema

Information schema is metadata about MySQL. We can obtain useful information from it. For example, I get current auto increment values by following SQL. SELECT t.table_name, t.auto_increment FROM information_schema.tables AS t WHERE t.tabl…

What I read, watched, listened recently

dotGo 2014 - Andrew Gerrand - 5 things I love Andrew Gerrand is a Googler and worked for Go. I watched this video just to learn English but it was good that he was describing Go's feature very well. www.youtube.com Golang UK Conference 201…

Duplicating a MySQL table schema and data

Duplicate foo table into foo_20150904 /* Create a new table from foo's schema */ > CREATE TABLE foo_20150904 LIKE foo; /* Insert whole data into a new table */ > INSERT INTO foo_20150904 SELECT * FROM foo;

Detecting duplicated code in Golang with CPD and Jenkins

Use CPD to detect duplicated code in Golang. And visualize how much duplicated by Jenkins DRY plugin.

Make VirtualBox's network faster with paravirtualized network adapter

virtio makes VirtualBox's network faster. In my case, it's 1.7x faster.

Building Vagrant box from VirtualBox OVF

Packer can build Vagrant box from VirtualBox OVF file.

Mocking a HTTP access with http.Transport in Golang

Mocking HTTP access with http.RoundTripper

Changing bower package cache directory

bower caches packages in ~/.cache/bower. How can I change the directory? bower's document says "Add the following in .bowerrc" but it's totally wrong. "storage": { "cache" : "~/.bower/cache", "registry" : "~/.bower/registry" } I try the co…

Recent open source activities

pmd https://github.com/pmd/pmd/pull/44 CPD (Copy Paste Detector) supported GoLang. go-xorm https://github.com/go-xorm/xorm/issues/166 Suggested and implemented "soft delete" for xorm. My pull-request was immediately merged! (very impressiv…

Make Javas VM's GC log human readable with -XX:+PrintGCDateStamps

I use Java VM's option -XX:+PrintGCTimeStamps in order to output time in GC log of Java VM , Just like this. TODAY=`date "+%Y%m%d-%H%M%S"` JAVA_OPTS="-server -Xms512m -Xmx512m -Xmn256m -XX:PermSize=256m -XX:MaxPermSize=256m \ -XX:+UseConcM…

ruby-lint - Static syntax checker for Ruby

Recently I found static syntax checker for Ruby called ruby-lint. We haven't had such a syntax checker for Ruby, so I'm very happy to find it. (Although it's alpha quality) Installation $ gem install ruby-lint Try Prepare following ruby co…