Skip to content

Instantly share code, notes, and snippets.

@TzuChiehHung
TzuChiehHung / snippet.ps1
Last active December 27, 2022 15:52
[Windows 10 OpenSSH Server Setup] #windows
Start-Service sshd
# OPTIONAL but recommended:
Set-Service -Name sshd -StartupType 'Automatic'
# Confirm the Firewall rule is configured. It should be created automatically by setup.
Get-NetFirewallRule -Name *ssh*
# There should be a firewall rule named "OpenSSH-Server-In-TCP", which should be enabled
# If the firewall does not exist, create one
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
# Set default shell
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force
@TzuChiehHung
TzuChiehHung / snippet.sh
Last active June 30, 2020 03:33
[Raspberry Pi iptables setup] #rpi
sudo iptables -t nat -A POSTROUTING -o usb0 -s 192.168.0.0/24 -j SNAT --to-source 192.168.42.82
@TzuChiehHung
TzuChiehHung / snippet.py
Last active September 23, 2019 00:48
[Argument parser] #python
from argparse import ArgumentParser
if __name__ == '__main__':
parser = ArgumentParser(description='')
parser.add_argument('position', type=str, help='position argument')
parser.add_argument('-o', '--optional', type=str, default='some string', help='optional argument')
parser.add_argument('-l', '--optional', type=int, nargs='+', help='parse a list')
parser.add_argument('-b', '--boolean', action='store_true', dest='visual', help='Show image frame')
@TzuChiehHung
TzuChiehHung / snippet.py
Last active September 23, 2019 00:47
[Get a filtered file list in a directory] #python
import os
from fnmatch import fnmatch
for path, _, files in os.walk('root/dir'):
for filename in files:
if fnmatch(filename, 'match_pattern'):
print(os.path.join(path, filename))
@TzuChiehHung
TzuChiehHung / settings.json
Last active February 10, 2020 04:51
[VSCode user config] #vscode #config
{
// general
"editor.renderWhitespace": "all",
"terminal.integrated.fontFamily": "Source Code Pro for Powerline",
// LaTeX
"workbench.settings.editor": "json",
"latex-workshop.latex.tools": [
{
"name": "xelatex",
"command": "xelatex",
@TzuChiehHung
TzuChiehHung / README.md
Last active May 4, 2021 07:47
[Auto mount Samba share on Linux] #ubuntu
  • Create .smbcredentials

    username=username
    passowrd=password
    
  • Chage permission to prevent unwanted access

@TzuChiehHung
TzuChiehHung / run.sh
Last active September 23, 2019 00:54
[Change author and Email] #git
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="hungtc@solab.me.ntu.edu.tw"
CORRECT_NAME="tc.hung"
CORRECT_EMAIL="hungtc@solab.me.ntu.edu.tw"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
@TzuChiehHung
TzuChiehHung / .gitconfig
Last active June 25, 2018 08:21
[git config] #git #config
[user]
email = hungtc@solab.me.ntu.edu.tw
name = tc.hung
[core]
editor = vim
ignorecase = false
[push]
default = matching
[alias]
tree = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) %C(cyan)%ar%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)' --all
@TzuChiehHung
TzuChiehHung / .inputrc
Last active May 14, 2020 01:53
[inputrc config] #config
"\e[A": history-search-backward
"\e[B": history-search-forward
set completion-ignore-case on
set completion-prefix-display-length 3
set mark-symlinked-directories On
set show-all-if-ambiguous On
set show-all-if-unmodified On
set visible-stats On
@TzuChiehHung
TzuChiehHung / snippet.py
Last active September 23, 2019 00:48
[Parse argument into class] #python
import argparse
class MyClass(object):
def __init__(self, foo, bar):
self.foo = foo
self.bar = bar
def Print(self):
print self.foo
print self.bar