Skip to content

Instantly share code, notes, and snippets.

View skanehira's full-sized avatar
🦍
I'm Gorilla

skanehira skanehira

🦍
I'm Gorilla
  • 株式会社テックリード
  • Japan
  • 08:43 (UTC +09:00)
  • X @gorilla0513
View GitHub Profile
function! s:echo_err(msg) abort
echohl ErrorMsg
echom '[code2img]' a:msg
echohl None
endfunction
function! s:on_err_vim(ch, msg) abort
call s:echo_err(a:msg)
endfunction
package main
import (
"log"
"os"
)
func main() {
if len(os.Args) < 2 {
return
function! s:comment(obj, timer) abort
let winid = popup_create(a:obj.text, #{
\ col: &columns - 40,
\ line: rand(srand()) % &lines,
\ minwidth: strlen(a:obj.text),
\ maxwidth: 40,
\ tabpage: -1,
\ zindex: 300,
\ })
package main
import (
"fmt"
"log"
"golang.org/x/sys/unix"
)
func main() {

How to maintain a git repository

Check size of a repository.

$ du -hs .git/objects

If repository has more than 50 packfile or 7000 objets, you can run gc.

const app = new Vue({
el: '#app',
data: {
},
methods: {
get(file_name) {
req = window.indexedDB.open("mycache", 1)
req.onsuccess = event => {
const db = event.target.result
const idx = db.transaction("mycache", "readwrite").objectStore("mycache").index("file_name")

Goのファイルコピー時のメモ

Goでファイルをコピーする時、io.Copyを使うとメモリ効率がよいとのこと。

良くない例

ioutil.ReadFileはファイルの中身を一気に読みんでメモリ上に保持するため、 サイズが大きいファイルだとメモリをがっつり使ってしまう。

func copyFile(from string, to string) error {
document.getElementById('gorilla').addEventListener("paste", e => {
e.clipboardData.files[0].arrayBuffer().then(b => {
fs.writeFile(path.join(__dirname, "gorilla.png"), new Buffer(b), err => {
if (err) {
console.log(err)
} else {
console.log("ウホウホ")
}
})
})

mattnさんから教えてもらったgithub-flowsのやつ

  1. Makefile と .github/workflows をコピる。
  2. Makefile の BIN と VERSION_PATH を書き換える(必要があれば)
  3. main に -v 等でバージョンを吐くコードを足す。これは mmv の main.go を参考に

あとは全部 push。git tag vX.X.X したらクロスコンパイルされたバイナリが GitHub Release にアップロードされる。 https://github.com/itchyny/mmv/blob/master/Makefile

手元では 123ci.bat というバッチコマンドを用意しています。

Install ag used by fzf

Ubuntu

$ sudo apt install silversearcher-ag

set environment for fish

set -x FZF_DEFAULT_COMMAND 'ag -g .'