Skip to content

Instantly share code, notes, and snippets.

View aherve's full-sized avatar

Aurélien aherve

View GitHub Profile
chess|1 1
chess|2 2
go|1 2
go|2 1
#!/usr/bin/env ruby
class Reducer
attr_accessor :key, :game_type
def initialize(key)
@key = key
@player_scores = Hash.new
end
def accumulate(splitted_line)
1 game_log chess
1 player_log 1 1
1 player_log 2 0
2 game_log go
2 player_log 1 2
2 player_log 2 5
1 player_log 1 1
2 player_log 1 2
1 player_log 2 0
2 player_log 2 5
1 game_log chess
2 game_log go
#!/usr/bin/env ruby
class Mapper
# initialize a mapper with raw data.
def initialize(line)
# chomp will remove endline characters
# split will split the line for every tab character \t
# strip will remove whitespaces at begining and end of every words
@data = line.chomp.split("\t").map(&:strip)
Player_id GameType AverageRank
1 chess 1
1 go 2
2 chess 2
2 go 1
GameId Type
1 chess
2 go
PlayerId Score GameId
1 1 1
1 2 2
2 0 1
2 5 2
async function main () {
const user = await User.findOne({})
// execution is paused until a user is found and returned
console.log(user.email)
}
import app from '../../app'
import fixtures from '../ourFixtures'
import * as supertest from 'supertest-as-promised'
const request = supertest(app)
describe('Things', () => {
before(async () => {
await fixtures.clearDb() // assume clearDb is a function that returns a promise
await Thing.create({}) // mongoose style
}))