Skip to content

Instantly share code, notes, and snippets.

View yurenchen000's full-sized avatar
😶‍🌫️
may be slow to respond.

yurenchen000

😶‍🌫️
may be slow to respond.
View GitHub Profile
@yurenchen000
yurenchen000 / pipenv_virtualenv_calc.py
Created November 27, 2019 17:55
pipenv calcate virtualenv name
# https://github.com/pypa/pipenv/issues/1049
# https://github.com/pypa/pipenv/blob/a4aca53b5d02a4168214a487714d9836c9415a0c/pipenv/project.py#L116
# How pipenv calc virtualenv name in `~/.local/share/virtualenvs/`
import os, re, base64, hashlib
def virtualenv_name(path):
sanitized = re.sub(r'[ $`!*@"\\\r\n\t]', '_', os.path.basename(path))[0:42]
hash = hashlib.sha256((path+'/Pipfile').encode()).digest()[:6]
encoded_hash = base64.urlsafe_b64encode(hash).decode()
return sanitized + '-' + encoded_hash
@yurenchen000
yurenchen000 / wireshark_remote.sh
Created November 29, 2019 03:39
wireshark capture on remote host ( through ssh tcpdump )
#!/bin/bash
# ssh root@yurenchen.com "tcpdump -w - -U 'host g.cn'" | sudo wireshark -k -i -
# tcpdump Capture on remote host (by ssh) & Show packets on local wireshark
# $remote Need Capture permission
# $filter is tcpdump capture filter
# example:
# $ wireshark_remote root@10.1.1.2 'host yurenchen.com'
wireshark_remote(){
@yurenchen000
yurenchen000 / _sort_test.js
Last active December 9, 2019 08:06
test cmds
//test js
console.log('hello')
@yurenchen000
yurenchen000 / comm.vimrc
Last active December 10, 2019 09:45
vimrc snippets
" show line number
set nu
" hi cursor line
set cursorline
"hi CursorLine cterm=NONE ctermbg=darkred ctermfg=white
"hi CursorLine cterm=NONE ctermbg=darkred
" highlight search
se hls
@yurenchen000
yurenchen000 / ubuntu14_fix_ssh
Last active December 12, 2019 10:57
tmp note
sudo ifconfig eth0 mtu 1200
@yurenchen000
yurenchen000 / opkg_compare-versions_oddly.md
Last active December 21, 2019 13:48
opkg compare-versions operator oddly

$ opkg --help

compare-versions <v1> <op> <v2>
                    compare versions using <= < > >= = << >>

$ man build_dir/hostpkg/opkg-2017-12-07-3b417b9f/man/opkg-cl.1.in

compare-version <version1> <operator> <version2>
 compare versions using following operators :
@yurenchen000
yurenchen000 / flag_hide_usage.go
Created December 26, 2019 04:36
goang flag hide cmdline usage & parse err
// golang hide cmdline usage & parse err
flag.CommandLine.SetOutput(ioutil.Discard)
flag.Usage = func() { }
flag.Parse()
@yurenchen000
yurenchen000 / git_config_snip.md
Last active December 27, 2019 10:11
git config snippets

show config

git config --global -l

OUT:

@yurenchen000
yurenchen000 / ping_with_timestamp.md
Created April 10, 2020 17:19
linux ping cmd with timestamp

https://askubuntu.com/a/400273/413480

1. time from ping -D

Another possibility to use the ping -D option which gets you the timestamp as Unix time.

tilo@t-ubuntu:~$ ping google.com -D
PING google.com (173.194.33.73) 56(84) bytes of data.
[1388886989.442413] 64 bytes from sea09s15-in-f9.1e100.net (173.194.33.73): icmp_req=1 ttl=57 time=11.1 ms
[1388886990.443845] 64 bytes from sea09s15-in-f9.1e100.net (173.194.33.73): icmp_req=2 ttl=57 time=11.0 ms
@yurenchen000
yurenchen000 / upnp_get_ext_ip.md
Last active April 17, 2020 16:28
IGD/UPNP client Get ExternalIPAddress

upnp get ext ip

IGD/UPNP get ExternalIPAddress of upper router

A. upnpc cmd

$ upnpc -s | grep ExternalIPAddress
ExternalIPAddress = 192.168.199.121