Skip to content

Instantly share code, notes, and snippets.

View babarot's full-sized avatar
:octocat:
Work Hard

Masaki ISHIYAMA babarot

:octocat:
Work Hard
View GitHub Profile
@babarot
babarot / noc.sh
Created May 31, 2014 01:18
Count the number of command made in sh
#!/bin/sh
FILE=~/.bash_myhistory
if [ "$1" = "-h" ]; then
echo 1>&2 "usage: noc [-h|-l] [<num>]"
echo 1>&2 " -h display this help and exit"
echo 1>&2 " -l display most recently used list"
echo 1>&2 " (range: 0~<num>: default num zero)"
exit 1
#!/usr/bin/env ruby
#
# NATO phonetic alphabet
#
def usage
puts "Usage: " + File.basename($0) + " num1 [num2]"
puts ""
puts "num1 - This number expresses an opening in table."
@babarot
babarot / option_templete.sh
Created May 31, 2014 10:05
Command line option parser templete for bash
#!/bin/bash
PROGNAME=$(basename $0)
VERSION="1.0.0"
usage() {
echo "Usage: $PROGNAME [OPTIONS] [FILE]"
echo " This script is ~."
echo
echo "Options:"
@babarot
babarot / tac.awk
Created May 31, 2014 10:19
Behave like the GNU tair -r command or tac command
#!/usr/local/bin/gawk -f
BEGIN {
# Set delimiter as \034, avoid conflict with other characters
sort_exe = "sort -t \"\034\" -nr"
}
{
# Pass to the child process
printf("%d\034%s\n", NR, $0) |& sort_exe;
@babarot
babarot / show256colors.pl
Created May 31, 2014 12:31
Shows 256 colors can be displayed on the console
#!/usr/bin/env perl
use strict;
use warnings;
my $fg = "\x1b[38;5;";
my $bg = "\x1b[48;5;";
my $rs = "\x1b[0m";
my $color = 0;
@babarot
babarot / base64.rb
Created May 31, 2014 12:39
Encodes standard input by base64. Vice versa.
#!/usr/bin/ruby
require 'optparse'
require 'base64'
option_hash = {}
OptionParser.new{|opt|
opt.on('-e [VAL]') {|v| option_hash[:e] = v}
opt.on('-d VAL') {|v| option_hash[:d] = v}
#!/bin/sh
ECHO="echo -e"
case `$ECHO` in
-e)
ECHO=echo;;
esac
print_bar()
{
@babarot
babarot / bookmarker.sh
Last active April 11, 2021 04:30
description
#
# @(#) bookmarker.sh ver.1.4.0 2013.08.12
#
# Copyright (c) 2013, b4b4r07
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted provided
# that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
[ "$ZSH_VERSION" ] || return 1
declare -r zshmarkdir=~/.zshmarkdir
declare -r zshmarklist=$zshmarkdir/zshmarklist
declare -r zshmarklog=$zshmarkdir/zshmarklog
declare -i exit_usage=0
function _zshmark_show() {
[ ! -e $zshmarklist ] && { echo "$(basezzname $zshmarklist): No exist"; return 1; }
#!/bin/bash
declare test_log=~/.safe/log
OLDIFS=$IFS
IFS=$'\n'
array_front=( $(tail -n "${1:-10}" $trash_log | awk '{print $1,$2}' | sed "s $HOME ~ g") )
array_center=( $(tail -n "${1:-10}" $trash_log | awk '{print $3}' | sed "s $HOME ~ g") )
array_rear=( $(tail -n "${1:-10}" $trash_log | awk '{print $4}' | sed "s $HOME ~ g") )