Skip to content

Instantly share code, notes, and snippets.

View akm's full-sized avatar

Takeshi Akima akm

View GitHub Profile
@akm
akm / emoji_table.js
Created July 25, 2024 06:21
Generate markdown table for emoji, code, English message and Japanese message from gitmoji-vscode
// Copy this file to the root directory of local directory from ttps://github.com/seatonjiang/gitmoji-vscode/
const fs = require('fs');
const jaDict = require('./languages/bundle.l10n.ja.json');
const indexOfLineIncludes = (lines, s) => {
let idx = -1
lines.forEach((line,i) => { if (line.includes(s)) idx = i })
return idx
}
@akm
akm / schema4erb.rb
Created June 19, 2024 01:06
Remove unnecessary things for draw.io SQL import from mysqldump --no-data
lines = \
STDIN.readlines.reject{|x| x =~ /\A--/}.
reject{|x| x =~ %r{\A\s*/\*.+\*/;\s\z}}.
reject{|x| x =~ /\A\s*DROP TABLE.+;\s*\z/}.
reject{|x| x =~ /\A\s*UNIQUE KEY .+,\s*\z/}.
reject{|x| x =~ /\A\s*KEY .+,\s*\z/}.
reject{|x| x =~ /\A\s*CONSTRAINT .+,?\s*\z/}
lines = lines.map{|x| x.sub(/\A([^\`]*)\`([^\`]+)\`(.+)/, '\1\2\3') }
text = lines.join
text.gsub!(/\) ENGINE=InnoDB .+\;/, ")")
@akm
akm / graceful-shutdown.go
Created June 5, 2024 05:43
Graceful Shutdown example
package main
import (
"context"
"fmt"
"os"
"os/signal"
"strconv"
"syscall"
"time"
@akm
akm / friendsofgo-errors-main.go
Last active November 23, 2023 13:07
Stacktrace examples
package main
import (
"fmt"
"github.com/friendsofgo/errors"
)
func main() {
err := foo1()
@akm
akm / error_recovery_in_defered_function.go
Created October 11, 2023 07:52
Error recovery in deferred function
// Use go playground or https://github.com/traefik/yaegi to try
func foo(v int) (rerr error) {
if v%3 == 1 {
defer func() {
rerr = fmt.Errorf("error %d mod 3 => 1: overwrite", v)
}()
} else if v%3 == 2 {
defer func() {
err := fmt.Errorf("error %d mod 3 => 2: set error if nil", v)
@akm
akm / .golangci.yaml
Created January 18, 2023 23:47
My first golangci-lint
# https://golangci-lint.run/usage/configuration/
run:
timeout: 5m
linters-settings:
govet:
settings:
unusedresult:
funcs:
- github.com/akm/repo1/path/to/package1.Function1
@akm
akm / exercise-web-crawler.go
Created August 17, 2022 01:55
Web Crawler: Concurrency - A tour of Go
package main
// This is my first go program written in Dec 22nd, 2016
import (
"fmt"
"sync"
)
type Fetcher interface {
ARGV.each do |keyword|
image_family_names = `docker search #{keyword} --format '{{.Name}}'`.split("\n")
puts( (["image family names:"] + image_family_names).join("\n") )
image_family_names.each do |image_family_name|
tags = `curl -s https://registry.hub.docker.com/v1/repositories/#{image_family_name}/tags | jq -r '.[].name'`.split("\n")
puts("#{image_family_name} tags: #{tags.join(',')}")
tags.each do |tag|
image_name = image_family_name + ':' + tag
file_name = image_family_name.gsub('/', '-') + '-' + tag + '.tar.gz'
if File.exist?(file_name)
@akm
akm / prepend_example.rb
Last active June 20, 2020 02:00
prependでモジュールを拡張する例
module Bar
def bar
"bar"
end
end
class Foo
include Bar
end
class Prcss
attr_accessor :pid, :ppid, :command
attr_reader :done
def initialize(pid, ppid, command)
@pid = pid.to_i
@ppid = ppid.to_i
@command = command
end