Skip to content

Instantly share code, notes, and snippets.

View cryptowen's full-sized avatar
🎯
Focusing

Owen cryptowen

🎯
Focusing
View GitHub Profile
@cryptowen
cryptowen / 0_reuse_code.js
Last active August 29, 2015 14:06
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@cryptowen
cryptowen / get_html_content.py
Created September 17, 2014 08:31
python获取正文
#coding:utf-8
import urllib,chardet,re
from sgmllib import SGMLParser
from BeautifulSoup import BeautifulSoup
'''爬取网页新闻的黑标题下的网页正文部分,保存在txt文档里
以黑标题的名字作为txt文档的名字
这个黑标题不是网页打开之后的正文标题
'''
@cryptowen
cryptowen / prime.cpp
Created September 18, 2014 02:07
100万以内的素数表文件生成方法From http://blog.csdn.net/wwwsq/article/details/7383674
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define PRIME_SIZE 100000
int main(void)
{
int i,j=0,k;
int a[PRIME_SIZE];
def is_abundant(n):
max_divisor = int(n / 2) + 1
sum = 0
for x in range(1, max_divisor):
if n % x == 0:
sum += x
return sum > n
abundants = list(x for x in range(1, 28123) if is_abundant(x))
@cryptowen
cryptowen / rating_dict.py
Created October 24, 2014 09:35
带有排名功能的python 字典类,来自python cookbook 2 Ch5.14
#!/usr/bin/env python
''' An enriched dictionary that holds a mapping from keys to scores '''
from bisect import bisect_left, insort_left
import UserDict
class Ratings(UserDict.DictMixin, dict):
""" class Ratings is mostly like a dictionary, with extra features: the
value corresponding to each key is the 'score' for that key, and all
keys are ranked in terms their scores. Values must be comparable; keys,
as well as being hashable, must be comparable if any two keys may ever
have the same corresponding value (i.e., may be "tied" on score).
@cryptowen
cryptowen / five_star_flag.py
Created November 3, 2014 10:56
对于turtle类的一些封装方法,包括画正多边形,正多角形和五星红旗
#!/usr/bin/env python
# -*- coding: utf-8 –*-
''' 对于turtle类的一些封装方法,包括画正多边形,正多角形和五星红旗。'''
__author__ = 'Hu Wenchao'
import turtle
import math
def draw_polygon(aTurtle, size=50, n=3):
''' 绘制正多边形
@cryptowen
cryptowen / wooyun.recipe
Created February 11, 2015 13:59
使用calibre获取乌云知识库<http://drops.wooyun.org/>文章用的recipe
#!/usr/bin/python
# encoding: utf-8
'''
本代码为使用calibre获取 乌云知识库<http://drops.wooyun.org/> 文章用的recipe,
可用来参考获取其他网站或博客电子书。
使用方法参见:
http://blog.csdn.net/yelyyely/article/details/43741739
@cryptowen
cryptowen / .vimrc
Last active August 29, 2015 14:18
my vimrc file
"=========================================================================
" DesCRiption: 极简版vim配置
"
" 替换本地vim配置文件命令:
" $ curl -O https://gist.githubusercontent.com/yely/f3c36c56c8db1e594633/raw/6db1aef4691c735182aef6ab0f5e9a9fd75377e1/simplest.vimrc && mv simplest.vimrc ~/.vimrc --backup=t
" or
" $ wget --no-check-certificate https://gist.githubusercontent.com/yely/f3c36c56c8db1e594633/raw/6db1aef4691c735182aef6ab0f5e9a9fd75377e1/simplest.vimrc && mv simplest.vimrc ~/.vimrc --backup=t
"=========================================================================
set nu " 设置行号
syn on " 语法高亮
@cryptowen
cryptowen / install_tmux.sh
Last active August 29, 2015 14:19
centos手动安装tmux脚本
#!/bin/sh
# centos tmux install script. To install tmux version 2.0 instead of 1.6 installed by yum install command.
sudo yum install gcc make automake pkgconfig wget git-core ncurses-devel -y
mkdir ~/src
cd ~/src
wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar -zxvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure
make
@cryptowen
cryptowen / multicore_gevent.py
Created November 24, 2015 10:56
使用了多进程的gevent服务器,可以用来改进一些IO密集型操作的性能
import sys
from gevent import server
from gevent import monkey
monkey.patch_os()
from multiprocessing import Process, current_process, cpu_count
def eat_cpu():
for i in xrange(100000):
pass