Skip to content

Instantly share code, notes, and snippets.

View mpj's full-sized avatar

Mattias Petter Johansson mpj

View GitHub Profile
<html>
<head>
<title>tale</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<style>
snurra = require 'snurra'
_ = require 'highland'
bus = snurra()
#snurra.register require 'snurra-request'
snurraRequest = (bus, topic) ->
#include <ctime>
#include <iostream>
using namespace std;
int main()
{
srand(time(0));
int totalsumma = 1000;
int tal1;
int tal2;
int slump = rand() % 36 + 1;
Function<List<Map<String, String>>,List<Person>> transformDbResults =
new Function<List<String>, List<Person>>() {
@Override
public List<Person> apply(List<Map<String, String>> personMapList) {
List<Person> personObjList = new ArrayList<Person>();
for(Map<String,String> personDataMap : personMapList){
personObjList.add(new Person(personDataMap);
}
return personObjList;
}
@mpj
mpj / Cannonville.md
Last active August 29, 2015 14:20
Cannonville

Cannonville

Cannonville is a log storage service that you can use instead of a traditional database like MongoDB or MySQL.

What is a log?

When we say log, we specifically mean an ordered, append-only list of immutable objects. In this document, we'll be referring to these objects as events. The log cannot be reordered, events can only be added to the end of it, and items cannot be deleted or altered. Sort of how deposits and withdrawals in a bank account works.

What is Event Sourcing?

Applications built on top of Cannonville uses the event sourcing pattern for storage. Event sourcing means that you infer your data model from a big log of events instead of persisting the data model. For example, when using event sourcing, you wouldn't store the score of a user - instead you would infer the score from a series of win and lose events. This video gives a good introduction to event sourcing.

@mpj
mpj / gist:f30d5c86479a677888ef
Last active August 29, 2015 14:21
ibex peak
Ibex Peak
A table that can be observed for deltas, using mongo or nedb storage
as it's underlying store.
let ibex = ibexpeak(adapter, name)
Creates an ibex instance. adapter is either ibexpeak-mongo or ibexpeak-nedb or
a mock adapter for testing.
ibex.update(update)
* Katy Perry / 6jJ0s89eD6GaHleKKya26X
Affinty: { w42: 30, awestrae: 193.5 }
Concerts:
- Sep 22nd Lima, Peru
- Sep 25th São Paulo, Brazil
- Sep 29th Curitiba, Brazil
- Oct 3rd Buenos Aires, Argentina
- Oct 6th Santiago, Chile
- Oct 9th Bogota, Colombia
- Oct 12th San Juan, Puerto Rico
@mpj
mpj / fin1.js
Last active August 29, 2015 14:23
function triple(x) {
return x * 3
}
console.log(triple(10)) // 30
function reduce(arr, fn, initial) {
//there's no more elements in the array, we return I get that
if (arr.length === 0) {
return initial;
} // base case, does not recurse
// we are calling the actual function here with the first element in the array
//I don't get what initial is ??
(What is recursion?)
Recursion is when a function that calls itself until it doesn't.
That is seriously all it is. A lot of people think that recursion is hard. That is because of some collective insanity among people that
try to teach programming, all explanations of recursion use fibonacci numbers as an example. If somebody tries to explain recursion to
you using fibonnaci numbers, you must murder them. I understand that sounds rough, because they mean well, but
we really need to get rid of that, because it makes everyone think that recursion is hard, when it is actually easy.
Our mission - we are going to implement this function, using recursion.