/tools

Useful home-brewed small tools

Primary LanguageShellMIT LicenseMIT

Tools

What is it?

Must-have tools for nomlab members; mainly small CLI scripts. It includes very site-specific scripts, but some script might be useful for other audiences.

Command list

ame
Set Slack status or send message with CLI
favico
Create simple one-letter icon for placeholder.
gem-new
Create a new Gem project in sandbox using bundler.
matplot
Invoke python3 with matplotlib using Docker
nginx-docker
Pull Nginx official docker image and run instantly.
prodargs
Execute a command multiple times changing the convination of option args.
rails-new
Create a new Rails project with some useful gems.
slack-sweeper
Bulk remove all Slack files older than N days.
treetable
Convert markdown or org-mode style section tree into table. It is supposed to be used for conversion of issue list into table.

Descriptions

ame

Set Slack status or send message with CLI.

ame [-c CONFIG_FILE] [-t TOKEN_NAME] -m message CHANNEL TEXT [TITLE] [LINK]
ame [-c CONFIG_FILE] [-t TOKEN_NAME] -m status ICON TEXT
  -c Set config file (default: ~/.config/ame/config.sh).
  -t Select token name found in config.sh.
  -m Select method (message or status).
examples:
  ame -m message general "Hi"
  ame -m message general "Hi" "Title" "http://www.quickhack.net"
  ame -m status :office: "I am at office"

See also about config example examples/ame/config.sh

favico

Create simple one-letter icon for placeholder.

favico [-s size] [-c color] [-b bgcolor] [-f font] -o FILENAME STRING
examples:
  favico -s 64 -c white -b blue -o N.png 'N'
  favico -s 64 -f '/Library/Fonts/ヒラギノ丸ゴ ProN W4.ttc' -o nom.png '乃'

creates: examples/favico/N.png examples/favico/nom.png

To list-up available fonts, try:

convert -list font | grep Font:

gem-new

Create a new Gem project in sandbox using bundler.

gem-new project-name

It does:

  1. Create ./project-name directory
  2. Invoke bundle gem project-name with recommended options.
  3. Invoke bundle config set path vendor/bundle
  4. Add .gitignore from github/gitignore

matplot

Invoke python3 with matplotlib using Docker

nginx-docker

Pull Nginx official docker image and run instantly. You can serve your own HTML files in ~/Downloads/www/

nginx-docker {start|stop}

It does:

  1. Create minimum config file as $HOME/Downloads/nginx/nginx.conf
  2. Create minimum index.html as $HOME/Downloads/www/index.html
  3. pull official Nginx docker image and invoke:
    docker run -d -p 8080:8080 --name nginx \
    -v "$HOME/Downloads/nginx":/etc/nginx/conf.d/ \
    -v "$HOME/Downloads/www":/var/www \
    nginx
        
  4. open http://localhost:8080

prodargs

Execute a command multiple times changing the convination of option args. For example, if you want to perform some benchmark changing its parameters, You need to type boring commands:

some_benchmark -t 1 -r 1 -s 1
some_benchmark -t 1 -r 1 -s 10
some_benchmark -t 1 -r 2 -s 1
some_benchmark -t 1 -r 2 -s 10
some_benchmark -t 2 -r 1 -s 1
some_benchmark -t 2 -r 1 -s 10
some_benchmark -t 2 -r 2 -s 1
some_benchmark -t 2 -r 2 -s 10

By using prodarg, it becomes:

prodargs -- some_benchmark -t 1-2 -r 1-2 -s 1,10

With -n option, it perform dry-run; shows what happens.

prodargs -n -- some_benchmark -t 1-2 -r 1-2 -s 1,10

You can embed optargs in other args:

prodargs -- some_benchmark -l log-t%t-r%r-s%s.log -t 1-2 -r 1-2 -s 1,5

Does:

some_benchmark -l log-t1-r1-s1.log -t 1 -r 1 -s 1
some_benchmark -l log-t1-r1-s5.log -t 1 -r 1 -s 5
some_benchmark -l log-t1-r2-s1.log -t 1 -r 2 -s 1
some_benchmark -l log-t1-r2-s5.log -t 1 -r 2 -s 5
some_benchmark -l log-t2-r1-s1.log -t 2 -r 1 -s 1
some_benchmark -l log-t2-r1-s5.log -t 2 -r 1 -s 5
some_benchmark -l log-t2-r2-s1.log -t 2 -r 2 -s 1
some_benchmark -l log-t2-r2-s5.log -t 2 -r 2 -s 5

rails-new

Create a new Rails project in sandbox using bundler. It requires npm and yarn. Rails 7 does not need npm, yarn. However, bootstrap needs.

rails-new project-name

It does:

  1. Create ./project-name directory
  2. Create temporal Gemfile for bootstrap
  3. Install Rails with bundler
  4. Invoke bundle exec rails new overriding initial Gemfile with some additionals:
    • bootstrap
    • bootstrap_form
    • kaminari
    • ransack
  5. Add .gitignore from github/gitignore
  6. Set timezone to Tokyo (JST)
  7. Install ja locale files
    • Set default locale to ja
    • Install config/locales/ja.ym
    • Install config/locales/activerecord.ja.yml

slack-sweeper

Bulk remove all Slack files older than N(>30) days.

Usage: slack-sweeper [-n] SLACK_API_TOKEN DAYS
 -n: dry run.

For safety, this script does not remove more than 300 files.

treetable

Usage: treetable sample-todo-list.{md|org} > sample-todo-list.tex

For details about input-file format, check examples/treetable/todo-list.org or examples/treetable/todo-list.md. See also about output example examples/treetable/todo-list.pdf