Skip to content

Instantly share code, notes, and snippets.

View dixudx's full-sized avatar
:octocat:

Di Xu dixudx

:octocat:
View GitHub Profile
@dixudx
dixudx / demo.go
Last active February 15, 2022 14:25
Mock Golang Tests (If we want to test methodA, while it will call methodB internally, how can we mock the tests?)
package demo
import (
"context"
)
type ProviderInterface interface {
MethodA(ctx context.Context, id int) error
MethodB(ctx context.Context, id int) error
MethodC(ctx context.Context, id int) error
@dixudx
dixudx / curl-websocket.sh
Created May 11, 2021 02:36 — forked from htp/curl-websocket.sh
Test a WebSocket using curl.
curl --include \
--no-buffer \
--header "Connection: Upgrade" \
--header "Upgrade: websocket" \
--header "Host: example.com:80" \
--header "Origin: http://example.com:80" \
--header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
--header "Sec-WebSocket-Version: 13" \
http://example.com:80/
@dixudx
dixudx / prepare-commit-msg
Last active April 19, 2021 09:31
automatically sign-off new commits
#!/bin/sh
# usage:
# run command
# $ cd your-repo
# $ curl -Ls https://gist.githubusercontent.com/dixudx/7d7edea35b4d91e1a2a8fbf41d0954fa/raw/prepare-commit-msg -o .git/hooks/prepare-commit-msg
# $ chmod +x .git/hooks/prepare-commit-msg
NAME=$(git config user.name)
EMAIL=$(git config user.email)
@dixudx
dixudx / clean.sh
Last active June 22, 2020 03:50 — forked from Iman/clean.sh
Free up disk space on Ubuntu - clean log, cache, archive packages/apt archives, orphaned packages, old kernel and remove the trash
#!/bin/sh
#Check the Drive Space Used by Cached Files
du -sh /var/cache/apt/archives
#Clean all the log file
#for logs in `find /var/log -type f`; do > $logs; done
logs=`find /var/log -type f`
for i in $logs
@dixudx
dixudx / iterm2-solarized.md
Created May 14, 2020 07:05 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + Oh My Zsh + Solarized color scheme + Source Code Pro Powerline + Font Awesome + [Powerlevel10k] - (macOS)

Default

Default

Powerlevel10k

Powerlevel10k

@dixudx
dixudx / retry.sh
Created January 13, 2020 11:51 — forked from sj26/LICENSE.md
Bash retry function
# Retry a command up to a specific numer of times until it exits successfully,
# with exponential back off.
#
# $ retry 5 echo Hello
# Hello
#
# $ retry 5 false
# Retry 1/5 exited 1, retrying in 1 seconds...
# Retry 2/5 exited 1, retrying in 2 seconds...
# Retry 3/5 exited 1, retrying in 4 seconds...
@dixudx
dixudx / ansible-add-string-to-line.yml
Created July 6, 2019 05:15 — forked from iAugur/ansible-add-string-to-line.yml
Ansible: Add a String to an existing line in a file
# Adapted from solution provided by http://stackoverflow.com/users/57719/chin-huang http://stackoverflow.com/a/31465939/348868
# Scenario: You want to add a group to the list of the AllowGroups in ssh_config
# before:
# AllowGroups Group1
# After:
# AllowGroups Group1 Group2
- name: Add Group to AllowGroups
replace:
backup: yes
@dixudx
dixudx / INSTALL.txt
Created November 28, 2018 03:08 — forked from fernandoaleman/INSTALL.txt
Shell script to sync remote branches from upstream and push them up to forked origin
1. Copy 'git-sync-fork' script code from gist
2. Create a file called 'git-sync-fork' in any 'bin' directory in your $PATH
3. Paste script into this new file 'git-sync-fork' and save
4. Make the file executable `chmod +x git-sync-fork`
5. Run the script inside your locally forked git repo
Example:
git-sync-fork upstream origin
@dixudx
dixudx / deployment_initializer.go
Last active December 14, 2017 09:54
Sample Kubernetes Initializer Controller
package main
import (
"encoding/json"
"flag"
"log"
"os"
"os/signal"
"syscall"
"time"
@dixudx
dixudx / jstnow.py
Created November 22, 2017 06:49 — forked from remino/jstnow.py
Python: Print date & time in JST time zone without pytz module
# Print date & time in JST time zone
# For Python 2.7.x without pytz module
import datetime
from datetime import datetime, timedelta, tzinfo
class JST(tzinfo):
def utcoffset(self, dt):
return timedelta(hours=9)