Skip to content

Instantly share code, notes, and snippets.

@jackywyz
jackywyz / abstract vs trait.scala
Created August 22, 2011 09:41
scala self-types and Structure-type
abstract class Ta{
def say(a:Int):Int =a+2
}
trait T{
def say(a:Int):Int = a
}
//有实体函数的trait T会编译成
abstract trait T$class extends {
def say($this: T, a: Int): Int = a;
def /*T$class*/$init$($this: T): Unit = {
@jackywyz
jackywyz / userTimeline.scala
Created August 24, 2011 02:45
userTimeline
val statusListBuffer = new ListBuffer[Status]
def userTimeline(options : OptionalParam*) : List[Status] =
{
val optionsStr = new StringBuffer("?")
for (n <- (responseXML \\ "status").elements)
statusListBuffer += (Status.fromXml(n))
@jackywyz
jackywyz / lazy.scala
Created August 29, 2011 09:12
lazyLib
// Contributed by John Williams
package examples
object lazyLib {
/** Delay the evaluation of an expression until it is needed. */
def delay[A](value: => A): Susp[A] = new SuspImpl[A](value)
/** Get the value of a delayed expression. */
implicit def force[A](s: Susp[A]): A = s()
@jackywyz
jackywyz / Elvis.scala
Created August 31, 2011 09:59
Elvis operator
object Ternary {
implicit def coalescingOperator[T](pred: T) = new {
def ??[A >: T](alt: =>A) = if (pred == null) alt else pred
}
implicit def elvisOperator[T](alt: =>T) = new {
def ?:[A >: T](pred: A) = if (pred == null) alt else pred
}
}
@jackywyz
jackywyz / broker.py
Created September 1, 2011 01:27 — forked from derekwyatt/broker.py
This is an ENSIME broker to be used for Vim integration to ENSIME... just a prototype at this point
#!/usr/bin/python
import socket
import re
from time import sleep
from os import system
from threading import Thread
from optparse import OptionParser
parser = OptionParser()
@jackywyz
jackywyz / continuations.scala
Created September 7, 2011 03:06
scala tips
// scala -P:continuations:enable
//Continuation对于诸如异步I/O,UI事件处理以及数据流并发之类的高级控制建造十分有帮助
import util.continuations._
object Continue{
def say =
reset {
shift {
cf:(Int=>Int) =>
val even = cf(10)
@jackywyz
jackywyz / config.sbt
Created September 7, 2011 03:30
sbt 配置
//config mainClass in build.sbt
mainClass in (Compile, run) := Some("com.tujiao.Bootstrap")
@jackywyz
jackywyz / Regular.java
Created September 22, 2011 09:37 — forked from codahale/Regular.java
An example of the utility of private[this]
//decompiled with JD-GUI
import scala.ScalaObject;
import scala.reflect.ScalaSignature;
@ScalaSignature(bytes="\006\00192A!\001\002\001\013\t9!+Z4vY\006\024(\"A\002\002\017q*W\016\035;z}\r\0011c\001\001\007\035A\021q\001D\007\002\021)\021\021BC\001\005Y\006twMC\001\f\003\021Q\027M^1\n\0055A!AB(cU\026\034G\017\005\002\020%5\t\001CC\001\022\003\025\0318-\0317b\023\t\031\002CA\006TG\006d\027m\0242kK\016$\b\"B\013\001\t\0031\022A\002\037j]&$h\bF\001\030!\tA\002!D\001\003\021\035Q\002\0011A\005\nm\t\021![\013\0029A\021q\"H\005\003=A\0211!\0238u\021\035\001\003\0011A\005\n\005\nQ![0%KF$\"AI\023\021\005=\031\023B\001\023\021\005\021)f.\033;\t\017\031z\022\021!a\0019\005\031\001\020J\031\t\r!\002\001\025)\003\035\003\tI\007\005C\003+\001\021\0051&A\002j]\016$\022A\t\005\006[\001!\taG\001\004O\026$\b")
public class Regular
implements ScalaObject
{
private int i = 0;
@jackywyz
jackywyz / type-bounds.scala
Created September 26, 2011 08:02 — forked from retronym/type-bounds.scala
Tour of Scala Type Bounds
class A
class A2 extends A
class B
trait M[X]
//
// Upper Type Bound
//
def upperTypeBound[AA <: A](x: AA): A = x
@jackywyz
jackywyz / xl.py
Created October 9, 2011 09:58
analytics nginx logs with python
# -*- coding: utf-8 -*-
__version__ = '0.2.0'
#Nginx日志分析,分析歌曲热度排行
#crontab -e mting_rank.py统计周期:
#1)每月一号6点->
# 0 6 1 * * mting_rank.py
#1)每周一4点->
# 0 4 * * 1 mting_rank.py
#