Skip to content

Instantly share code, notes, and snippets.

View mozillazg's full-sized avatar
💭
I may be slow to respond.

Huang Huang mozillazg

💭
I may be slow to respond.
View GitHub Profile
@mozillazg
mozillazg / gist:3637230
Created September 5, 2012 14:11
cs101-unit1
# Write Python code that assigns to the
# variable url a string that is the value
# of the first URL that appears in a link
# tag in the string page.
# page = contents of a web page
page =('<div id="top_bin"><div id="top_content" class="width960">'
'<div class="udacity float-left"><a href="http://www.xkcd.com">')
start_link = page.find('<a href=')
start_quote = page.find('"', start_link)
@mozillazg
mozillazg / gist:3637302
Created September 5, 2012 14:16
cs101-unit2
def get_next_target(page):
start_link = page.find('<a href=')
if start_link == -1:
return None, 0
start_quote = page.find('"', start_link)
end_quote = page.find('"', start_quote + 1)
url = page[start_quote + 1:end_quote]
return url, end_quote
def print_all_links(page):
@mozillazg
mozillazg / gist:3870483
Created October 11, 2012 05:57
简单猜测字符串编码并返回 Unicode 字符串
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""简单猜测字符串编码并返回 Unicode 字符串
"""
def decode_(str_):
"""
"""
text = str_
@mozillazg
mozillazg / gist:4250018
Created December 10, 2012 11:09
简单的 Python 计算器(wxPython)
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import wx
def onclick(event):
button = event.GetEventObject()
label = button.GetLabel()
nums = [str(i) for i in range(10)] + ['.', '+', '-', 'x', u'÷']
<?php
$text = 'http://abc<a href="http://xxx">xsx</a> http://v2ex.com https://abc<img />abd';
print preg_replace('%(?<!"|\')https?://[^\s<]+%', '<a href="$0">$0</a>', $text);
//<a href="http://abc">http://abc</a><a href="http://xxx">xsx</a>
//<a href="http://v2ex.com">http://v2ex.com</a>
//<a href="https://abc">https://abc</a><img />abd
?>
<!doctype netscape-bookmark-file-1>
<!-- this is an automatically generated file.
it will be read and overwritten.
do not edit! -->
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>bookmarks</title>
<h1>书签菜单</h1>
<dl><p>
<dt><a href="place:folder=bookmarks_menu&folder=unfiled_bookmarks&folder=toolbar&sort=12&excludequeries=1&excludeitemifparenthasannotation=livemark%2ffeeduri&maxresults=10&querytype=1">最近使用的书签</a>
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
根据日期批量创建文件夹.
"""
from __future__ import print_function
from __future__ import unicode_literals
@mozillazg
mozillazg / ip.py
Last active December 29, 2015 17:09
get ip info
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import sys
import urllib
if __name__ == '__main__':
args = sys.argv
if len(args) < 2:
#!/usr/bin/perl
# The MySQL Partitions helper
# Copyright (C) 2008, 2009 Giuseppe Maxia
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
In [1]: class A():
...: def __call__(self, *args, **kwargs):
...: return locals()
...:
In [2]: a = A()
In [3]: a()
Out[3]: {'args': (), 'kwargs': {}, 'self': <__main__.A instance at 0x281b2d8>}