Skip to content

Instantly share code, notes, and snippets.

View reorx's full-sized avatar
YOLO

Xiao Meng reorx

YOLO
View GitHub Profile
@reorx
reorx / admin.py
Created September 3, 2016 08:42
Django Admin: hide permission for UserAdmin, exclude useless permissions for GroupAdmin
# coding: utf-8
from django.contrib import admin
from django.contrib.auth.models import Group, User
from django.contrib.auth.admin import GroupAdmin, UserAdmin
from django.utils.translation import ugettext_lazy as _
class CustomUserAdmin(UserAdmin):
fieldsets = (
# 实现ssh自动登录完成任务的expect脚本
# [root@localhost shell]# cat login.exp
#!/usr/bin/expect -f
set ipaddress [lindex $argv 0]
set passwd [lindex $argv 1]
set timeout 30
spawn ssh root@$ipaddress
expect {
"yes/no" { send "yes\r";exp_continue }
@reorx
reorx / 18.tmux.conf
Last active September 15, 2023 04:16
tmux conf for 1.8
#--Key-Bindings-----------------------------------------------------------------
# change the prefix from 'C-b' to 'C-a'
# (remap capslock to CTRL for easy access)
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# start with window 1 (instead of 0)
set -g base-index 1
@reorx
reorx / objectid.py
Created May 31, 2016 09:55
bson.objectid in pymongo, no dependency, works independently
#!/usr/bin/env python
# coding: utf-8
# Copyright 2009-2015 MongoDB, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0

Python 代码规范

命名

  • 尽量简单明了。
@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)"
@reorx
reorx / hash_ring.py
Last active August 18, 2022 14:59
Consistent hash implementation in Python.
# -*- coding: utf-8 -*-
"""
hash_ring
~~~~~~~~~~~~~~
Implements consistent hashing that can be used when
the number of server nodes can increase or decrease (like in memcached).
Consistent hashing is a scheme that provides a hash table functionality
in a way that the adding or removing of one slot
does not significantly change the mapping of keys to slots.
@reorx
reorx / thunderbird_customization.md
Last active July 27, 2022 15:50
Thunderbird customization configs
@reorx
reorx / .vimrc
Last active June 13, 2022 06:49
Minimal vimrc for server
" Minimal vimrc for server
" Author: reorx
" Usage:
" curl -sL https://gist.github.com/reorx/94e18825bc4002268f66/raw -o ~/.vimrc
" or
" curl -sL https://gist.github.com/reorx/94e18825bc4002268f66/raw | sudo tee --append /etc/vimrc
set nocompatible " choose no compatibility with legacy vi
syntax enable
set encoding=utf-8
@reorx
reorx / command_space_commitment.json
Created May 11, 2022 08:38
karabiner element complex modification to ensure command + space combination could be received by the system
{
"description": "command + space commitment",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "space",
"modifiers": {
"mandatory": [
"left_command"