Skip to content

Instantly share code, notes, and snippets.

@weijia
weijia / clipboard_notification.py
Last active August 29, 2015 14:05
PyQt clipboard event capture
#!/usr/bin/env python
#coding=utf-8
import sys
from PyQt4 import QtGui, QtCore
import os
def notification():
print "good"
@weijia
weijia / gist:a5d8b47d458eb66c45f7
Created September 30, 2014 05:45
encoding_error_workaround_for_saltstack_state.py
def smart_encoding(item_or_str):
target_encoding = "utf8"
if type(item_or_str) == unicode:
return item_or_str.encode(target_encoding, "replace")
else:
if type(item_or_str) == list:
res = []
for i in item_or_str:
res.append(smart_encoding(i))
return res
@weijia
weijia / trans_camel_to_lowcase
Created October 11, 2014 09:20
clip_trans camel to lowcase
def convert(name):
import re
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
yl = []
for i in xl:
yl.append(convert(i))