Skip to content

Instantly share code, notes, and snippets.

View wynemo's full-sized avatar
:octocat:
吃土中

Nemo.Zhang wynemo

:octocat:
吃土中
View GitHub Profile
@wynemo
wynemo / aserver.py
Last active December 14, 2015 18:19
a simple udp server using DTLS
import ssl
from socket import socket, AF_INET, SOCK_DGRAM
from dtls import do_patch
do_patch()
import SocketServer
class UDPEchoServer(SocketServer.ThreadingMixIn, SocketServer.UDPServer):
def get_request(self):#overwritten
return self.socket.accept()
def server_activate(self):
@wynemo
wynemo / is_win_file_hidden.py
Created March 25, 2013 07:42
check if file/directory is hidden on windows
def is_win_file_hidden(path): # path should be unicode
import ctypes
import ctypes.wintypes
INVALID_HANDLE_VALUE = -1
h = INVALID_HANDLE_VALUE
FindFirstFile = ctypes.windll.kernel32.FindFirstFileW
FindClose = ctypes.windll.kernel32.FindClose
out = ctypes.wintypes.WIN32_FIND_DATAW()
import socket
import tornado.ioloop
import tornado.iostream
def test():
def on_close(data):
print len(data), 'test on_close'
def on_data(data):
@wynemo
wynemo / Django Admin - change header 'Django administration' text
Last active December 17, 2015 15:39
django virtualenv uwsgi nginx configuration
You need to create your own admin base_site.html template to do this. The easiest way is to create the file:
/<projectdir>/templates/admin/base_site.html
This should be a copy of http://code.djangoproject.com/svn/django/branches/releases/1.2.X/django/contrib/admin/templates/admin/base_site.html - except putting in your custom title:
{% block branding %}
<h1 id="site-name">{% trans 'my cool admin console' %}</h1>
{% endblock %}
For this to work, you need to have the correct settings for your project, namely in settings.py:
@wynemo
wynemo / remove_dumplicate_from_list.py
Last active December 17, 2015 15:58
remove duplicate element from a list using python, you can use build-in function reduce
a = [1, 1, 2, 3]
print reduce(lambda x, y: x if y in x else x + [y], a, [])
exec env LANG=zh_CN.UTF-8 wine sth.exe
# or
export LANG=zh_CN.UTF-8
wine sth.exe &
@wynemo
wynemo / lxml install on ubuntu.md
Last active December 17, 2015 18:49
lxml install on ubuntu

####lxml install on ubuntu

sudo aptitude install libxslt-dev
sudo aptitude install libxml2-dev
sudo aptitude install gcc

pip install lxml

@wynemo
wynemo / gist backup.py
Last active December 17, 2015 18:49
gist backup
from pyquery import PyQuery as pq
import requests
r = requests.get('https://gist.github.com/wynemo')
d = pq(r.text)
q = d(
'#js-pjax-container')(
'.site-container.js-site-container')(
'.container')(
@wynemo
wynemo / hg notes.md
Last active December 18, 2015 05:39
my hg notes

The first thing you should do is set the username Mercurial will use for commits. It's best to configure a proper email address in ~/.hgrc (or on a Windows system in %USERPROFILE%\Mercurial.ini) by creating it and adding lines like the following:

[ui]
username = John Doe <john@example.com>
[auth]

bb.prefix = https://bitbucket.org/foo/

@wynemo
wynemo / slide.md
Last active December 18, 2015 10:09

decorators

####closure in python

def generate_power_func(n):
    def nth_power(x):
        return x**n
    return nth_power