Skip to content

Instantly share code, notes, and snippets.

Li Yao lastland

Block or report user

Report or block lastland

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@lastland
lastland / SumTest.py
Created Dec 20, 2012
The built-in function "sum" of Python 2.7 does run faster. But it's not true in PyPy.
View SumTest.py
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
@lastland
lastland / FloatSwap.cc
Created Apr 6, 2012
swap two float variables via xor
View FloatSwap.cc
#include <cstdio>
void swap(int & a, int & b)
{
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
int main()
View gist:1a1aa20c977567bc2e8aeb22e41017ce
I, the contributor, agree to licence my contributions to the Scala-Forklift project under the terms of the Apache 2.0.
@lastland
lastland / Vec.hs
Created Sep 4, 2016
Dependently Typed Vectors in Haskell
View Vec.hs
{-# 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)
@lastland
lastland / Vec.scala
Created Sep 4, 2016
Dependently Typed Vector in Scala
View Vec.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]
View clock.c
#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 / BeyesianAvg.py
Created Aug 11, 2012
尝试用这篇post: http://www.matrix67.com/blog/archives/5044 中的方法实现的一个自动中文抽词算法的Python程序
View BeyesianAvg.py
# -*- coding=utf-8 -*-
import collections
# Usage:
# 我的做法是把WordsDetector.py里的结果输出到文件,
# 然后把文件名放到下面的names列表中,运行本程序。
names = ['name0',
'name1',
'name2',
You can’t perform that action at this time.