Skip to content

Instantly share code, notes, and snippets.

@u1and0
u1and0 / 00_reverse.go
Last active February 11, 2019 01:11
言語処理100本ノックGo言語版
/*文字列"stressed"の文字を逆に(末尾から先頭に向かって)並べた文字列を得よ.*/
package main
import (
"fmt"
)
// RevString 与えられた文字列を逆順にして返す関数
func RevString(v string) string {
// 引数の文字列をrune配列に変換
augroup MyAutoCmd
if executable('pdftotext')
" PDFファイルを開いた時、text形式に変換してから開く
autocmd BufRead *.pdf :enew | 0read !pdftotext -layout -nopgbrk "#" -
endif
" 圧縮ファイルとPDFファイルを開いた時、readonlyモードで開き、j/kキーマップを変更
autocmd BufRead *.zip,*.gz,*.bz2,*.xz,*.pdf setlocal readonly nolist
\| nn <buffer> j <C-E> | nn <buffer> k <C-Y>
augroup END
@u1and0
u1and0 / PDFをgzipで圧縮
Last active July 16, 2020 14:04
ターミナル上でPDFのテキストを読む ref: https://qiita.com/u1and0/items/f8b53348544717d7635d
$ pdftogz -layout -nopgbrk "Sed & Awk 2nd Edition.pdf"
# Sed & Awk 2nd Edition.gzが作成されます
@u1and0
u1and0 / hist.sh
Last active February 8, 2019 14:53
Counting word and sort them.
#!/bin/sh
# histgram
#
# Usage:
# $ cat <(history 1) | awk '{print $2}' | ./hist.sh | head -20
#
# Ref:
# http://www.google.co.jp/url?q=https://qiita.com/kkdd/items/88581a2d04843c3c7ce7&sa=U&ved=0ahUKEwj56-To7c3fAhUOMt4KHXDnBU4QFggXMAA&usg=AOvVaw2ipKMrPVwtPbXKKyhzSKNV
cat "$@" | sort | uniq -c | sort -k1nr | awk '{printf "%16s %4d\n",$2,$1;}'
exit 0
@u1and0
u1and0 / oneliner-pdftocompressfile
Last active January 18, 2019 23:47
Convert pdf to text and compress it.
pdftotext "somepdffile.pdf" - | apack "somepdffile.xz" -
@u1and0
u1and0 / words-rank-local.sh
Last active December 30, 2018 13:51
count words and display ranking
#!/bin/sh
# Catch local data as first argument, and ranking of words top
# Usage:
#
# In shell, top 20
# $ cat *.sh | ./words-rank-local.sh 20
#
# In vim commandline, top 5
# :new | r !cat *.sh | ./# 5
@u1and0
u1and0 / gista-file
Last active January 15, 2019 06:45
oneliner command line
# Shell commends
```sh
expac -HM '%m %n' | sort -n # display installed packages size
```
# Vim scripts
```vim
:w !tweet.sh " 選択範囲をツイート投稿.depends https://github.com/ShellShoccar-jpn/kotoriotoko
:w `=tempname()` | vim package % | cw " 現在のバッファの無名バッファを適当な名前で保存しながらpackageという文字列で検索してquickfix listに表示する
@u1and0
u1and0 / fibo.py
Last active December 27, 2018 02:05
fibonatch sequence for python
#!/usr/bin/env python3
from itertools import takewhile
# Fibonacci numbers module
# <<自己紹介>>
# フィボナッチ数列の出力
# fibに入れる数字までフィボナッチを出力
# <<使い方>>
# fibo.fib(数字)←使えない
# fibo.fib2(数字)
@u1and0
u1and0 / index.html
Last active November 15, 2018 06:18
Flask + jQueryでテーブルの入力フォームに入力があるたびに値を取得 ref: https://qiita.com/u1and0/items/6dcfdf60b02eba207064
$(function ($){
// テーブルの入力フォームにインプットした際に発動
$('td input').on('input',function () {
// name属性と入力フォームの値を取得
var inp = {name: $(this).attr('name'),
value: $(this).val()};
console.log(inp); // 入力をjavascriptでコンソールに表示
inp = JSON.stringify(inp);
$.post({
@u1and0
u1and0 / 04_useful.ipy
Last active April 25, 2020 03:32
python-pandasで複数ファイルのデータを一度にDataFrameに読み込む ref: https://qiita.com/u1and0/items/4d9a5a497f356729014a
def _read_tables(*files, **kwargs):
""" Read general delimited files into DataFrame
Super function of `pd.read_table()`
"""
return pd.DataFrame(
{f: pd.read_table(f, **kwargs).squeeze() for f in files})
setattr(pd, 'read_tables', _read_tables) # pd.read_tables()として使えるようにする