Skip to content

Instantly share code, notes, and snippets.

@blacknon
blacknon / receive_results_with_buffered_channel.go
Created August 14, 2018 10:09
channelで文字列を送信するサンプル
package main
import (
"log"
"strconv"
"time"
)
func logSender(resc chan string) {
for i := 0; i < 10; i++ {
@blacknon
blacknon / gist:ffed35811e8c78dfb0b71dc9c4654127
Created September 5, 2018 12:11
ジャンプの打ち切り漫画一覧取得のシェル芸
curl -s https://ja.wikipedia.org/wiki/%E9%80%B1%E5%88%8A%E5%B0%91%E5%B9%B4%E3%82%B8%E3%83%A3%E3%83%B3%E3%83%97%E9%80%A3%E8%BC%89%E4%BD%9C%E5%93%81%E3%81%AE%E4%B8%80%E8%A6%A7 \ |
sed -e 's/<span style="display:none[^>]*>[^>]*>//g;s/<td>/&__________/g;s|</ br>||g' | \
w3m -dump -cols 500 -T text/html | nkf -Lu | sed 's/__________/\x0/g' | \
grep -a -E '^ *[0-9]+ +' | grep -a -v -e '短期集中連載' -e '移籍' -e '連載中' -e '月1連載' -e '続編' | \
sed -r 's/^ *[0-9]+ +//g;s/\^\[[0-9]+\]//g;s/^\x0//g;s/ {2,}/\t/g;s|/[0-9]+||g' | \
awk -F"\0" '
BEGIN{OFS="\t"}
{
s=$(NF-2);
split(s, st, ".");
@blacknon
blacknon / ssh_with_rcfile
Last active September 28, 2018 02:41
ssh接続先でローカルのbashrcとvimrcを利用するためのシェル芸
ssh -t user@host '
bash --rcfile <(
echo -e ' $(cat <(echo "function lvim() { vim -u <(echo "$(cat ~/.vimrc|base64)"|base64 -d) \$@ ; }") \
~/dotfiles/{.bashrc,sh_function,sh_alias,bash_prompt} \
<(echo -e alias vim=lvim) | \
base64
) ' \
|base64 -d)'
@blacknon
blacknon / bash_anime_test.sh
Created October 4, 2018 04:06
ANIS Escapeを使ったコンソール上でのアニメーションをするスクリプト例(サンプルのため変数を配列にしてforで回すような処理をしていない)
#!/bin/bash
AA1="
AAAA
AAAA
AAAA
"
#AA1_LINE=$(echo -e "${AA1}"|wc -l)
AA2_1="
BBBB
@blacknon
blacknon / a.py
Created February 9, 2022 04:20
pythonでregex matchしたとこをハイライトさせる場合のサンプルコード(どっかからのコピペだった…はず)
#!/usr/bin/env python3
# -*- encoding: UTF-8 -*-
import re
colourFormat = '\033[{0}m'
colourStr = colourFormat.format(32)
resetStr = colourFormat.format(0)
s = "This is a sentence where I talk about interesting stuff like sencha tea."
lastMatch = 0
@blacknon
blacknon / main.rs
Created February 9, 2022 05:04
regexでmatchした箇所をハイライト表示させるためのサンプルコード(rust版)
extern crate regex;
use regex::Regex; // 1.1.8
fn main() {
let seperator = Regex::new(r"is a").unwrap();
let splits: Vec<_> = seperator.split("this... is a, test").into_iter().collect();
for split in splits {
println!("\"{}\"", split);
}
@blacknon
blacknon / test_parseopt.nim
Created January 4, 2023 23:36
nimでshort optionを書いているコマンドラインをパースしてseqにするサンプルコード
import std/parseopt
import hashes
import sets
import sequtils
var p = initOptParser("-ab -c:123 -d xyz -e:5 --foo --bar=20 file.txt")
var cmdline: OrderedSet[string] = initOrderedSet[string]()
while true:
p.next()
@blacknon
blacknon / hwatch_logviewer.py
Last active January 30, 2023 01:36
hwatchのlogをパースして出力するpythonスクリプト
#!/usr/bin/env python3
# -*- encoding: UTF-8 -*-
# Copyright(c) 2021 Blacknon. All rights reserved.
# Use of this source code is governed by an MIT license
# that can be found in the LICENSE file.
#
# User:
# blacknon
# Description: [hwatch](https://github.com/blacknon/hwatch)のlogをパースして出力するスクリプト
# =============================================
@blacknon
blacknon / get_ip_address_list.md
Last active January 30, 2023 01:39
Get IP address list from cidr perl oneliner
echo 192.168.100.9/28|perl -aF[./] -lne'for($i=0;$i<4;$i++){$x.=sprintf("%08b",$F[$i])}$y=$F[4];$k=substr($x,0,$y);$m=2**(32-$y);for($j=0;$j<$m;$j++){$a=$k.sprintf("%0".(32-$y)."b",$j);for($n=0;$n<4;$n++){$b.=".".sprintf(oct("0b".substr($a,$n*8,8)))};$b=~s/^\.//g;print $b;$b=""}'
# もうちょっと短くして改行したもの
echo 192.168.100.9/28|perl -aF[./] -E'
$x.=sprintf("%08b",$F[$_])for 0..3;
$y=$F[4];$z=32-$y;
$m=2**$z;
s@s:~$ unzip -l test1/test-1.zip
Archive:  test1/test-1.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
       35  2017-05-12 19:05   aaa.txt
        6  2017-05-12 18:55   bbb.txt
        6  2017-05-12 18:56   ccc.txt
---------                     -------
       47                     3 files