Note: This was written using elasticsearch 0.9.
Elasticsearch will automatically create an index (with basic settings and mappings) for you if you post a first document:
$ curl -X POST 'http://localhost:9200/thegame/weapons/1' -d \
'{
"_id": 1,
/* Quick implementation of Exponential and Geometric random number generators | |
For example you can use it to simulate when an event is going to happen next, given its average rate: | |
Buses arrive every 30 minutes on average, so that's an average rate of 2 per hour. | |
I arrive at the bus station, I can use this to generate the next bus ETA: | |
randomExponential(2); // => 0.3213031016466269 hours, i.e. 19 minutes | |
*/ |
Note: This was written using elasticsearch 0.9.
Elasticsearch will automatically create an index (with basic settings and mappings) for you if you post a first document:
$ curl -X POST 'http://localhost:9200/thegame/weapons/1' -d \
'{
"_id": 1,
Nesting APIs and ReaderT
environments in Haskell's Servant
Environments, from parent to child (or base to extended):
App
(ReaderT AppEnv IO
):
HasLogFunc env
HasDatabase env
HasTracing env
AppAuthenticated
(ReaderT AppAuthenticatedEnv IO
):HasApp env
(everything from App
)Using MonadLogger
without LoggingT
in Haskell
node_modules | |
dist |
Using RIO with Servant in Haskell, with nested environments.
Port of servant-nested-apis Gist.
Compare using a stack of transformers vs. the ReaderT pattern for a web service.
See files:
TypeScript has support for type-checking plain JavaScript files, which is very useful if you have an existing JS codebase and you want to test the waters and gradually add types.
There are some limitations in what you can do in JSDoc, but a lot of them can be worked-around by using type-definition files .d.ts
(for example in a types/
directory). These files don't generate any JavaScript code, they are just there to provide extra type definitions to the compiler.
One thing you can't do in those .d.ts
files though, is use enums. You could define them of course, but you won't get the runtime representation since the files don't generate JS code.
var util = require('util') | |
, Transform = require('stream').Transform | |
, StreamCombiner = require('./streamcombiner'); | |
var chunks1 = []; | |
var stream1 = new Transform(); | |
var soFar = ''; | |
stream1._transform = function(chunk, encoding, done) { | |
chunks1.push(chunk.toString()); | |
var pieces = (soFar + chunk).split('\n'); |