Skip to content

Instantly share code, notes, and snippets.

View wanglun's full-sized avatar
🎯
Focusing

Lun wanglun

🎯
Focusing
View GitHub Profile
@wanglun
wanglun / myip.py
Created September 21, 2019 02:53
get my external ip in Python
#!/usr/bin/python
# pip install dnspython
def myip():
import socket
import dns.resolver
resolver = dns.resolver.Resolver()
resolver.nameservers = [socket.gethostbyname('resolver1.opendns.com')]
ans = resolver.query(qname='myip.opendns.com', rdtype='A', raise_on_no_answer=False)
@wanglun
wanglun / when_temp_var_destruct.cpp
Created October 30, 2018 11:36
when_temp_var_destruct
#include <iostream>
class T {
public:
T() {
std::cout << "T" << std::endl;
}
~T() {
std::cout << "~T" << std::endl;
}
#!/bin/sh
#
# $Id: unsnap.sh,v 1.5 2008/12/12 13:35:58 cvs Exp $
#
case "$1" in
*.old)
old="${1%/.old}"
old="${old%/}"
old="${old%/backups}"
old="${old%/}"
#!/bin/sh
#
# $Id: rc-snap.sh,v 1.9 2009/04/04 07:51:23 cvs Exp $
#
mount_backup () {
base="${1}"
if test ! -d "${base}/.snap"
then
return
@wanglun
wanglun / gist:2005790
Created March 9, 2012 09:15
google bookmark for pentadactyl
command -js gbm (function(){var a=window,b=buffer.doc,c=encodeURIComponent,d=a.openWebPanel("Google Bookmark", "https://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk="+c(b.location)+"&title="+c(b.title));})();
@wanglun
wanglun / gist:2005380
Created March 9, 2012 06:51
kindle touch
The Kindle Touch's update system has a very annoying bug. The new new update format, each package is allowed to insert metadata into the header. The format is 0x2 byte number of meta-strings, then for each string, 0x2 byte for length of string followed by the string (without a null terminator). The problem is that Amazon themselves don't know if the length of the string is little endian or big endian. In libotacheck.so (which runs in the background and deletes invalid updates so you can't even run them from the menu), it assumes the length is little endian (like all other data in the file). Meanwhile, "bundlefuncs", which is called by otaup to extract and run the update assumes it is big endian. This means if I say my string is 0x10 bytes long, libotacheck.so will check to make sure I have a 0x1000 byte string. Now, there's no problem if I my file is big enough because right after the metadata is the actual update file (and currently, there is no use for metadata), however, if I have a small update package th
@wanglun
wanglun / gist:2005341
Created March 9, 2012 06:31
kindle touch teardown 拆机
I just realized that nobody ever posted detailed opening directions for the touch. Most just go "pry the bottom half first and remove the rest of the covers. It's really easy to damage the back, so here's some detailed instructions. I will define the "top" as where the kindle text is and the "bottom" as where the FCC text is.
The case is held together by 4 hooks on the top left and top right (2 left and 2 right) and 4 tabs tabs on the bottom left and right (2 and 2). There are also 6 very tiny tabs on the bottom and 4 on the top, but you should never start from the top because of the 4 hooks. Begin by taking a very thin piece of plastic (or anything thin and hard, but not a knife because you may damage something). Insert it into the bottom between the case and the device. Carefully pry until the bottom is loose. Now move your thin plastic to the right and left until you feel half the case loose. Do NOT attempt to pry the entire case off. As I've mentioned earlier, there are 4 hooks. With half the case loose,
@wanglun
wanglun / gist:2004461
Created March 9, 2012 01:17
ROT13 vim
http://en.wikipedia.org/wiki/ROT13
abcdefghijklm
nopqrstuvwxyz
上下替换
vim
===
@wanglun
wanglun / gist:1898416
Created February 24, 2012 06:36
mysql source 乱码
set names utf8;