Skip to content

Instantly share code, notes, and snippets.

View Wizmann's full-sized avatar
⚙️
不好好学习,只能。。。

Wizmann Wizmann

⚙️
不好好学习,只能。。。
View GitHub Profile
@Wizmann
Wizmann / Palindrome.scala
Created March 15, 2013 16:03
最长回文串
//最长回文串
//有O(n)的Manacher算法,不过好难写。。。
import scala.math;
object Palindrome
{
def main(args : Array[String])
{
def isPalindrome(x : String): Boolean =
{
x equals x.reverse
@Wizmann
Wizmann / MergeSort.scala
Created March 15, 2013 16:02
归并排序
//归并排序
object MergeSort
{
def main(args:Array[String]) {
val a = readLine split(" ") map(_ toInt) toList
val b = readLine split(" ") map(_ toInt) toList
def merge_sort(a : List[Int], b: List[Int]): List[Int] = {
a match {
case Nil => b
case _ => b match
@Wizmann
Wizmann / Bottle.scala
Created March 15, 2013 16:01
瓶子问题
//瓶子问题
import scala.annotation.tailrec
object Bottle
{
val N_Bottle = 3
def main(args : Array[String])
{
val n = readLine toInt
@tailrec
def solve(full : Int, empty : Int = 0, drinked : Int = 0) : Int =
@Wizmann
Wizmann / kde.py
Created March 10, 2013 15:10
KDE with ``numpy``, ``scipy`` und ``matplotlib``
#coding=utf-8
import sys,re,os
import numpy as np
from scipy import stats
import matplotlib.pylab as plt
def draw_kde(grade):
gkde = stats.kde.gaussian_kde(grade)
ind = np.arange(0.,100.,0.01)
plt.plot(ind, gkde(ind), label='Gods\' Grade', color="g")
@Wizmann
Wizmann / lashou_parser_multiprocessing.py
Created March 2, 2013 15:53
Python XML Parser with multiprocessing
# coding=utf-8
import sys
import xml.etree.cElementTree as cElementTree
from pyquery import PyQuery
import multiprocessing as mp
import time
reload(sys)
sys.setdefaultencoding('utf-8')
@Wizmann
Wizmann / lashou_parser_single.py
Created March 2, 2013 15:50
Python XML Parser with single thread
# coding=utf-8
import sys
import xml.etree.cElementTree as cElementTree
from pyquery import PyQuery
import time
reload(sys)
sys.setdefaultencoding('utf-8')
start_time = time.time()
@Wizmann
Wizmann / lashou_parser_gevent.py
Created March 2, 2013 15:26
Python XML Parser with gevent
# coding=utf-8
import sys
import xml.etree.cElementTree as cElementTree
from pyquery import PyQuery
import time
import gevent
from gevent.queue import Queue, Empty
reload(sys)
sys.setdefaultencoding('utf-8')
@Wizmann
Wizmann / renren.py
Created February 25, 2013 14:08
人人网发状态机
#coding=utf-8
import urllib
import urllib2
import cookielib
import httplib
import json
import re
import time
import datetime
import os
@Wizmann
Wizmann / beijing_air.py
Created February 25, 2013 14:05
一个很挫很挫的抓取BeijingAir的程序
#coding=utf-8
import urllib
import urllib2
import cookielib
import httplib
import json
import re
import time
import datetime
import os
@Wizmann
Wizmann / LineCounter.scala
Created February 13, 2013 16:44
计算代码行数的程序
object LineCounter {
def main(args : Array[String]) = {
val code_exts = Set("cc", "java", "cpp", "c", "py", "cxx", "hs", "scala", "scl")
def walk(f: java.io.File): Int = {
val list = f.listFiles()
var tot = 0
list foreach { (x) =>
if(x.getName contains "模版"){}
else if(x.isFile()) {
val ext = x.getName lastIndexOf('.') match {