Skip to content

Instantly share code, notes, and snippets.

View xudshen's full-sized avatar
:shipit:

Xudong Shen xudshen

:shipit:
  • Beijing, China
  • 21:38 (UTC +08:00)
View GitHub Profile
git config --global alias.make-patch '!bash -c "cd ${GIT_PREFIX:-.}; git add .; git commit -m ''uncommited''; git format-patch HEAD~1; git reset HEAD~1; mkdir -p ~/Dropbox/$(git config --get remote.origin.url)/$(git rev-parse HEAD); mv *.patch ~/Dropbox/$(git config --get remote.origin.url)/$(git rev-parse HEAD)/"'
git config --global alias.apply-patch '!bash -c "cd ${GIT_PREFIX:-.}; [ -d "~/Dropbox/$(git config --get remote.origin.url)/$(git rev-parse HEAD)" ] && cat ~/Dropbox/$(git config --get remote.origin.url)/$(git rev-parse HEAD)/*.patch | git am && git reset HEAD~1"'

Upgrading to Lion or Yosemite and WebStorm 9, I noticed key repeat was
turned off for the IdeaVim plugin h j k l keys.

System-wide key repeat

defaults write -g ApplePressAndHoldEnabled -bool false in a terminal will enable
key repeat for every app. This can alternatively be found in the accessibility settings in OS X' preferences.

App specific key repeat

package info.xudshen.test;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import java.io.File;
import java.io.IOException;
/*
* Copyright 2002-2014 the original author or authors.
*
* 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
*
* Unless required by applicable law or agreed to in writing, software
@xudshen
xudshen / iptables.conf
Last active August 29, 2015 14:07
iptables
*filter
# Allow all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0
-A INPUT -i lo -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
-A INPUT -d 127.0.0.0/8 -j REJECT
# Allow input establish
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
@xudshen
xudshen / chmod
Last active August 29, 2015 14:04
find /path/to/base/dir -type d -print0 | xargs -0 chmod 755
find /path/to/base/dir -type f -print0 | xargs -0 chmod 644
def create_logger(level, filename):
# create logger
logger = logging.getLogger(__name__)
logger.setLevel(level)
# create file handler and set level to debug
fh = logging.FileHandler(filename)
fh.setLevel(logging.DEBUG)
# create formatter
formatter = logging.Formatter("[%(asctime)s][%(levelname)s]%(name)s: %(message)s")
# add formatter to fh
__author__ = 'xudshen'
import hashlib
cache = {}
def insertAlert(type, timestamp, desc, host, cluster):
global cache
id = hashlib.md5((type + timestamp + desc + host).encode("utf8")).hexdigest()
if not id in cache:
cache[id] = []
#! /usr/bin/python
import time
from functools import wraps
def retry(ExceptionToCheck, tries=4, delay=3, backoff=2, logger=None):
"""Retry calling the decorated function using an exponential backoff.
http://www.saltycrane.com/blog/2009/11/trying-out-retry-decorator-python/
original from: http://wiki.python.org/moin/PythonDecoratorLibrary#Retry
:param ExceptionToCheck: the exception to check. may be a tuple of
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,04,00,00,00,1D,E0,3A,00,1D,00,5D,E0,3A,00,1D,00,00,00,00,00,00,00,00,00