Skip to content

Instantly share code, notes, and snippets.

ReVIEW::Compiler.defblock :reduce,0..1
class ReVIEW::HTMLBuilder
def reduce(lines)
origin = lines.shift
puts %Q[<div class="table">]
puts %Q[<table class='table table-borderless'>]
lines.each_with_index do |line, index|
puts %Q[<tr>]
if(index == 0)
puts %Q[<td>]
@akimichi
akimichi / find_and_wc
Created September 16, 2013 04:37
あるディレクトリ以下のscalaソースの行数をwcでカウントする
find . \( -name *.scala \) -type f | xargs cat | wc -l
@akimichi
akimichi / .mongorc.js
Last active December 16, 2015 15:29
.mongorc.js
host = db.serverStatus().host;
prompt = function() {
return db+"@"+host+"$ ";
}
// # simple-statistics
//
// A simple, literate statistics system. The code below uses the
// [Javascript module pattern](http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth),
// eventually assigning `simple-statistics` to `ss` in browsers or the
@akimichi
akimichi / MyList.scala
Created April 6, 2013 10:41
A rudimentary implementation of List collection in Scala.
describe("自前のListを定義する"){
object test {
abstract class MyList[+T] {
def isEmpty: Boolean
def head: T
def tail: MyList[T]
def ::[U>:T](item: U): MyList[U]
}
case class MyListImpl[T](val head: T, val tail: MyList[T]) extends MyList[T] {
def ::[U>:T](item: U): MyList[U] = new MyListImpl(item, this)
@akimichi
akimichi / gist:4106260
Created November 18, 2012 17:06 — forked from jonifreeman/gist:3667222
Kiama rewrite
scala> import org.kiama.rewriting.Rewriter._
import org.kiama.rewriting.Rewriter._
scala> trait Expr
defined trait Expr
scala> case class Constant(x: Int) extends Expr
defined class Constant
scala> case class Add(e1: Expr, e2: Expr) extends Expr
@akimichi
akimichi / aggregate.js
Created September 28, 2012 03:18 — forked from cwestin/aggregate.js
Mongo shell script and sample documents used for my aggregation talk at MongoSF
/* sample aggregate command queries */
// make sure we're using the right db; this is the same as "use mydb;" in shell
db = db.getSisterDB("aggdb");
// just passing through fields
var p1 = db.runCommand(
{ aggregate : "article", pipeline : [
{ $project : {
tags : 1,
pageViews : 1
@akimichi
akimichi / aggregation.js
Created September 28, 2012 03:16 — forked from cwestin/aggregation.js
Mongo shell script and sample documents used for my aggregation talks 12/2011
// make sure we're using the right db; this is the same as "use aggdb;" in shell
db = db.getSiblingDB("aggdb");
// simple projection
var p1 = db.runCommand(
{ aggregate : "article", pipeline : [
{ $project : {
tags : 1,
pageViews : 1
}}
@akimichi
akimichi / .gitignore
Created September 2, 2012 14:37
.gitignore for sbt project
*~
.emacs.desktop*
target/
@akimichi
akimichi / Reader.scala
Created August 28, 2012 14:53 — forked from blouerat/Reader.scala
Reader Monad
/*
Based on the first part of the talk "Dead-Simple Dependency Injection in Scala" by @runarorama at NEScala 2012
http://marakana.com/s/dependency_injection_in_scala,1108/index.html
*/
class Connection {
def prepareStatement(query: String) = new Statement()
}
class Statement {
@akimichi
akimichi / XPathParser.scala
Created July 11, 2012 23:47 — forked from honnix/XPathParser.scala
simple xpath alike parser in scala combinator
// _[@type=="baoc" and ts10[@value=="1" and a==2] and ts20]
package com.honnix.xml.transformer
import scala.xml.NodeSeq
import scala.util.parsing.combinator.JavaTokenParsers
object XPathParser {
def apply(conditionalPath: String, topSelector: (NodeSeq, String) => NodeSeq) =
new XPathParser(conditionalPath, topSelector)