Skip to content

Instantly share code, notes, and snippets.

View ThreeBearsDan's full-sized avatar

dan ThreeBearsDan

View GitHub Profile
import struct
# returns encoded dict
# this function assumes data in a particular format: it contains an array of field and values.
# each field is represented as a tuple of size 4 (value, wire type, field number, if field is an array)
# eg. message Msg { int64 id = 1; string text = 2; } => [[1234, 'varint', 1, False], ['hello world', 'string', 1, False]]
# also we can assume that every protobuf message is a dict at start, so this function is an entry point for encoding.
def encode_dict(data):
encoded_value = b''
for d in data:
@sshymko
sshymko / redis.service
Last active April 9, 2023 08:31
Redis service for systemd on Linux
[Unit]
Description=Redis persistent key-value storage
After=network.target
[Service]
Type=notify
ExecStart=/usr/bin/redis-server /etc/redis.conf --supervised systemd --daemonize no
ExecStop=/usr/bin/redis-cli -p 6379 shutdown
ExecReload=/bin/kill -USR2 $MAINPID
Restart=always
@ThreeBearsDan
ThreeBearsDan / gist:ad274feaa3a1b07ee64c1440cdcbc079
Created March 25, 2017 07:51 — forked from peter279k/gist:9d9b8aa7767b60bfa30413d1f138f36b
解決 Ubuntu "can’t set the locale; make sure $LC_* and $LANG are correct" 的錯誤
## 安裝語系檔
`$ sudo locale-gen "en_US.UTF-8"`
## 重新設定語系檔
`$ sudo dpkg-reconfigure locales`
## 設定檔
@nickoala
nickoala / 0_python_email.md
Last active April 29, 2024 05:54
Use Python to send and receive emails

Use Python to:

  • send a plain text email
  • send an email with attachment
  • receive and filter emails according to some criteria
@vsouza
vsouza / .bashrc
Last active April 9, 2024 05:27
Golang setup in Mac OSX with HomeBrew. Set `GOPATH` and `GOROOT` variables in zshell, fish or bash.
# Set variables in .bashrc file
# don't forget to change your path correctly!
export GOPATH=$HOME/golang
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
@clemensg
clemensg / etc_sysctl.conf
Created February 5, 2014 16:50
My FreeBSD /etc/sysctl.conf
# /etc/sysctl.conf
# Clemens Gruber, 2014
#
# Uncomment this to prevent users from seeing information about processes that
# are being run under another UID.
security.bsd.see_other_uids=0
## I/O
""" An example of a Linux daemon written in Python.
Based on http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
The changes are:
1 - Uses file open context managers instead of calls to file().
2 - Forces stdin to /dev/null. stdout and stderr go to log files.
3 - Uses print instead of sys.stdout.write prior to pointing stdout to the log file.
4 - Omits try/excepts if they only wrap one error message w/ another.