Skip to content

Instantly share code, notes, and snippets.

View reorx's full-sized avatar
YOLO

Xiao Meng reorx

YOLO
View GitHub Profile
"""
Usage:
>>> class Color(SimpleEnum):
>>> red = KV
>>> green = 'green' # same as using `KV`
>>> grey = 'gray'
>>> Color.red
'red'
>>> Color.grey
@reorx
reorx / dunders_py2.py
Last active July 24, 2018 13:33
Explain the relationship between `__str__`, `__repr__`, `__bytes__` (`__unicode__`) in both Python 3 and 2.
"""
Conclusions:
1. `print(o)` equals to `print(str(o))`
2. `str(o)` will use `__repr__` if `__str__` not exist
3. `repr(o)` only uses `__repr__`
4. `unicode(o)` will use `unicode(__str__())` if `__unicode__` not exist
"""
# coding: utf-8
import gevent.monkey
gevent.monkey.patch_all()
import os
import redis
import gevent
  • grep

    • ag
    • rg
  • ls

    • exa
  • find

class BufHandler(logging.handlers.BufferingHandler):
def emit(self, record):
self.buffer.append(self.format(record))
buf_handler = BufHandler(100 * 100)
buf_handler.setFormatter(
logging.Formatter(
fmt=LOG_FMT,
)
/* Consolas: Win: 82.97% Mac: 34.77%
* Lucida Console: Win: 99.18% Mac: 0%
* Monaco: Win: 2.74% Mac: 99.82%
*/
.monospace {
font-family: Consolas, monaco, "Lucida Console", monospace;
}
@reorx
reorx / django_static_collector.py
Last active February 26, 2018 22:00
Call django collectstatic without involving the whole project, inspired by https://github.com/syntarsus/minimal-django
# coding: utf-8
# Usage: python django_static_collector.py myapp.settings
import sys
import importlib
from django.conf import settings
from django.core.management import execute_from_command_line
@reorx
reorx / networkservice.sh
Created June 27, 2017 06:50
macOS: get current active network device name, interface, mac
#!/bin/bash
services=$(networksetup -listnetworkserviceorder | grep 'Hardware Port')
while read line; do
sname=$(echo $line | awk -F "(, )|(: )|[)]" '{print $2}')
sdev=$(echo $line | awk -F "(, )|(: )|[)]" '{print $4}')
#echo "Current service: $sname, $sdev, $currentservice"
if [ -n "$sdev" ]; then
ifout="$(ifconfig $sdev 2>/dev/null)"