Skip to content

Instantly share code, notes, and snippets.

View lastland's full-sized avatar

Li Yao lastland

View GitHub Profile
@lastland
lastland / BeyesianAvg.py
Created August 11, 2012 07:14
尝试用这篇post: http://www.matrix67.com/blog/archives/5044 中的方法实现的一个自动中文抽词算法的Python程序
# -*- coding=utf-8 -*-
import collections
# Usage:
# 我的做法是把WordsDetector.py里的结果输出到文件,
# 然后把文件名放到下面的names列表中,运行本程序。
names = ['name0',
'name1',
'name2',
#include <stdio.h>
#include <string.h>
#define MAX_SQUARE 57521883
#define C1 4617
#define C2 73
#define C3 36936
#define C4 262657
#define C5 2134536
#define C6 16810048
@lastland
lastland / Vec.scala
Created September 4, 2016 04:29
Dependently Typed Vector in Scala
package dependent
import scala.language.implicitConversions
import shapeless._, shapeless.nat._
object Vector {
trait Vec[+A, N <: Nat]
case object Nil extends Vec[Nothing, _0]
@lastland
lastland / Vec.hs
Created September 4, 2016 02:19
Dependently Typed Vectors in Haskell
{-# LANGUAGE GADTs, DataKinds, KindSignatures, TypeFamilies #-}
module Vector where
data Nat = Z | S Nat
data Vec :: * -> Nat -> * where
Nil :: Vec a Z
Cons :: a -> Vec a n -> Vec a (S n)
I, the contributor, agree to licence my contributions to the Scala-Forklift project under the terms of the Apache 2.0.
@lastland
lastland / FloatSwap.cc
Created April 6, 2012 15:25
swap two float variables via xor
#include <cstdio>
void swap(int & a, int & b)
{
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
int main()
@lastland
lastland / SumTest.py
Created December 20, 2012 10:23
The built-in function "sum" of Python 2.7 does run faster. But it's not true in PyPy.
import itertools
# tstime(https://bitbucket.org/gsauthof/tstime) is used to measure the performance.
# OS: Archlinux 3.6.10-1
# Python Version: 2.7.3
# PyPy Version: 2.0.0-beta1
c = 0
for (i, j) in itertools.product(range(10000), repeat=2):
c += i * j