Skip to content

Instantly share code, notes, and snippets.

View mmasashi's full-sized avatar

Masashi mmasashi

View GitHub Profile
cat /dev/urandom | LC_CTYPE=C tr -dc '[:alnum:]' | head -c 40 && echo
@mmasashi
mmasashi / rvm-installer-with-comment.sh
Created August 7, 2014 14:52
RVM install script with explanation comment.
## rvm bash install script reading memo
## Based on https://github.com/wayneeseguin/rvm/blob/1.25.28/binscripts/rvm-installer
#!/usr/bin/env bash
# enable extended pattern matching
# shopt command changes the shell optional behavior
# extglob option enables you to write like `ls !(b*)`
# http://stackoverflow.com/questions/216995/how-can-i-use-inverse-or-negative-wildcards-when-pattern-matching-in-a-unix-linu
shopt -s extglob
@mmasashi
mmasashi / gist:003adc1c9a1e6bf90f6e
Created November 12, 2014 00:28
keep git merge message
We're using git's Merge commit history to list features&bug fixes in a release tag. But I found cases where no merge commit was made as a result of `git merge`. According to this article (http://arjanvandergaag.nl/blog/clarify-git-history-with-merge-commits.html) it's due to fast-forward merge. To prevent it from happening, use `--no-ff` option when you merge. e.g. `git merge --no-ff feature/u483-asdf-asdf` This create a merge commit even if fast-forward merge is possible. Or, you can make it default with `git config --add merge.ff false`
Omit them needless merge commits. Add them to convey information.
@mmasashi
mmasashi / gist:8952ce4520a030775948
Created November 27, 2014 05:35
Circleci boost lib install error
ubuntu@box432:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.04.5 LTS
Release: 12.04
Codename: precise
ubuntu@box432:~$ sudo apt-get install libboost-all-dev
Reading package lists... Done
Building dependency tree
@mmasashi
mmasashi / tcpdumpcmd.sh
Created November 28, 2014 06:19
tcpdump command
#!/bin/bash
tcpdump -s0 -i eth0 -X port 44567 -w test.cap
@mmasashi
mmasashi / gzsplit.rb
Created November 28, 2014 06:23
split gz file into multiple gz files
# gzsplit.rb
# split gz files into pieces
# usage: ruby gzsplit [file-name] [lines-per-file]
require 'zlib'
require 'fileutils'
OUTPUT_DIR = "splited_files"
file_name = ARGV[0] || "20130910-03_01_00.gz"
lines_per_file = ARGV[1] ? ARGV[1].to_i : 5
@mmasashi
mmasashi / append_load_path.rb
Created April 3, 2015 20:48
Append a new load path to the head of $LOAD_PATH if not exists.
def append_load_path_if_not_exist(new_lib_path)
absolute_path = File.realpath(new_lib_path)
$LOAD_PATH.unshift absolute_path unless $LOAD_PATH.include? absolute_path
end
another_lib_dir = File.realpath('../../lib', __FILE__)
append_load_path_if_not_exist(another_lib_dir)
@mmasashi
mmasashi / detect_boost_ver.cpp
Created April 17, 2015 22:00
How to detect boost lib version
#include <boost/version.hpp>
#include <iostream>
int main()
{
std::cout << BOOST_LIB_VERSION << std::endl;
return 0;
}
@mmasashi
mmasashi / load_submodule_models.rb
Created April 22, 2015 23:27
Load Rails submodule models with different database.
# rails_root/config/initializers/load_submodule_models.rb
RAILS_MODEL_LIST = %w(
Account
Plan
User
UserPreference
)
def apply_db_change(class_name)
@mmasashi
mmasashi / encode_for_redshift.rb
Created April 28, 2015 23:45
Encode string for redshift
class RedshiftString
# Redshift supports UTF-8 but it enforces stricter rule than other
# implementations such as MySQL or Ruby. This method returns a
# Redshift-safe string from the given string.
def self.encode(string, options = {})
result = string.encoding == Encoding::UTF_8 ? string.encode(Encoding::UTF_16, options).encode(Encoding::UTF_8) : string.encode(Encoding::UTF_8, options)
result.each_char.collect{|c|
# Per Redshift document
# http://docs.aws.amazon.com/redshift/latest/dg/multi-byte-character-load-errors.html
if c >= "\uFDD0" && c <= "\uFDEF" || c == "\uFFFE" || c == "\uFFFF"