Skip to content

Instantly share code, notes, and snippets.

import numpy as np
import pylab as pl
import pandas as pd
from sklearn import svm
from sklearn import linear_model
from sklearn import tree
from sklearn.metrics import confusion_matrix
o o o
o x
o x x x
x o
x x x o
x
o o
o
@LaoLiulaoliu
LaoLiulaoliu / down_html_tree.py
Last active August 29, 2015 14:06
abstract download an html behavior
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Yuande Liu <miracle (at) gmail.com>
import socket
import time
import requests
import lxml.html
def wrapper(url, timeout=20, retries=5, sleep=10, encoding ='gbk', text=False, errurl=None, errfunc=None):
/*****************************************
* 感知器判断数字奇偶性
*
* 关键点,阈值应该怎么定?
****************************************/
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
@LaoLiulaoliu
LaoLiulaoliu / rails_simple_auth_model.rb
Created December 19, 2014 02:58
ruby on rails simple auth
# == Schema Information
#
# Table name: admins
#
# id :integer not null, primary key
# username :string(255) not null
# encrypted_password :string(255) not null
# salt :string(255) not null
# created_at :datetime
# updated_at :datetime
@LaoLiulaoliu
LaoLiulaoliu / dns_mass_resolve.py
Last active October 5, 2016 05:17
gevent example
#!/usr/bin/env python
"""Resolve hostnames concurrently, exit after 60 seconds.
Under the hood, this might use an asynchronous resolver based on
c-ares (the default) or thread-pool-based resolver.
You can choose between resolvers using GEVENT_RESOLVER environment
variable. To enable threading resolver:
GEVENT_RESOLVER=thread python dns_mass_resolve.py
@LaoLiulaoliu
LaoLiulaoliu / meta.py
Created February 2, 2016 08:47
several articles to explain how python metaclass works
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Liu Yuande
# https://jakevdp.github.io/blog/2012/12/01/a-primer-on-python-metaclasses/
# http://stackoverflow.com/questions/100003/what-is-a-metaclass-in-python
# http://stackoverflow.com/questions/17801344/python-understanding-metaclass-and-inheritance
# give a name, create a new car class. define the class in a more dynamic way.
# classes can inherit properties from parents and add or specialize attributes and methods.
''.join(map((lambda d: lambda i: str(d[i]))([5,9,1,0,3]), [2,0,3,3,3,2,0,2,1,2,4]))
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Yuande Liu <miraclecome (at) gmail.com>
from __future__ import print_function, division
from gevent import monkey; monkey.patch_all()
import gevent
import time