Skip to content

Instantly share code, notes, and snippets.

@momota
momota / cva.rb
Last active July 5, 2017 09:50
Google Cloud Vision API client for Ruby. At run time, pass the image file to the command line argument.
require 'base64'
require 'json'
require 'net/https'
def detect_text_from(image)
api_key = 'YOUR-API-KEY'
api_url = "https://vision.googleapis.com/v1/images:annotate?key=#{api_key}"
enc_image = Base64.strict_encode64(File.new(image, 'rb').read)
@momota
momota / generate_L_size_csv.py
Last active March 28, 2024 14:27
Generate a large size of CSV file was filled random values. This script generates around 250MB size of the file. You can adjust two parameters `row` and `col` to generate the file which has desirable size.
import csv
import random
# 1000000 and 52 == roughly 1GB (WARNING TAKES a while, 30s+)
rows = 1000000
columns = 52
def generate_random_row(col):
a = []
l = [i]
@momota
momota / setting_sftp.md
Last active February 16, 2017 03:10
Configure sftp while limitting resources by using chroot

create a sftp user

We execute as root user on an SFTP server as below. First, we create a specific user is able to utilize SFTP as file transfer. Then, we create a sftp group and put the sftp user under the group.

sftp-server$ sudo -s
sftp-server$ useradd sftp_user
@momota
momota / pukiwiki_backup.sh
Last active November 9, 2015 07:47
backup pukiwiki files
#!/bin/bash -eu
echo -n "enter sudo password: "
stty -echo
read password
stty echo
echo
wiki_dir=/var/www/html/wiki
backup_file="~/backup/`/bin/date +%Y%m%d%H%M%S`_wiki.tar.gz"
@momota
momota / parallel_ping.sh
Last active November 10, 2015 11:47
ping.shの並行処理版。IPアドレスを改行区切りのファイルに列挙し第一引数へ、ping間隔を第二引数へ。
#!/bin/bash -eu
# ----------------------------------------------------------------------
# argument validation and initialize
#
if [ $# -eq 2 ]; then
echo -e "*** if you want to stop this script, exec --- kill -TERM -$$ ---"
ip_list=$1
interval=$2
else
@momota
momota / sshrc
Created March 19, 2015 11:03
sshrc
#!/bin/bash
echo
echo "------------------------------------------------------------------"
echo "HOSTNAME : `hostname`"
echo "DATE : `date \"+%Y-%m-%d %H:%M:%S\"`"
echo "USER : `whoami`"
echo "PWD : `pwd`"
echo "------------------------------------------------------------------"
echo
@momota
momota / ping.sh
Last active August 29, 2015 14:10
color ping result, and save log file
#!/bin/bash
# argument validation
if [ $# -eq 2 ];then
target=$1
interval=$2
log="`/bin/date +%Y%m%d%H%M%S`_`/bin/hostname -i`---$1_ping.log"
else
echo -e "USAGE: ./ping.sh <IP_ADDRESS or HOSTNAME> <PING_INTERVAL[sec]>\n"
exit 1
@momota
momota / generate_random_string.rb
Last active June 14, 2016 06:13
ランダムな文字列生成用。一時的なパスワードなど。
# conding: utf-8
def random_string( length )
str = ('a'..'z').to_a + ('A'..'Z').to_a +
('0'..'9').to_a + ['-', '+', '_', '@', '=', '&', '$', '#', '?']
Array.new( length ){ str[rand( str.size )] }.join
end
# -------------------------------------------------------------------