Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / .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 / find_and_wc
Created September 16, 2013 04:37
あるディレクトリ以下のscalaソースの行数をwcでカウントする
find . \( -name *.scala \) -type f | xargs cat | wc -l
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 / ndtpd.conf
Created July 11, 2014 12:29
upstart script for ndtpd
File Edit Options Buffers Tools Conf Help
# ndtpd
description "ndtpd"
author "Akimichi Tatsukawa <[email protected]>"
start on runlevel [2345]
stop on runlevel [06]
env DAEMON=/usr/sbin/ndtpd
@akimichi
akimichi / app.js
Last active April 18, 2017 12:06
express4でjohnny-fiveを使う
"use strict";
const express = require('express');
const app = express();
const http = require('http').Server(app);
const io = require('socket.io')(http);
const flash = require('connect-flash');
const bodyParser = require('body-parser');
const methodOverride = require('method-override');
const errorHandler = require('errorhandler');
@akimichi
akimichi / .gitignore
Last active May 6, 2017 04:31
.gitignore for express4
# Logs
logs
*.log
npm-debug.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock