Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

db.articles.aggregate(
[{ $match: {
$or: [{
score: { $gt: 90 }
}, {
author: "dave"
}}]
}}]
);
// Given these documents in a collection
{ "_id" : ObjectId("512bc95fe835e68f199c8686"), "author" : "dave", "score" : 80 }
{ "_id" : ObjectId("512bc962e835e68f199c8687"), "author" : "dave", "score" : 85 }
{ "_id" : ObjectId("55f5a192d4bede9ac365b257"), "author" : "ahn", "score" : 60 }
{ "_id" : ObjectId("55f5a192d4bede9ac365b258"), "author" : "li", "score" : 55 }
{ "_id" : ObjectId("55f5a1d3d4bede9ac365b259"), "author" : "annT", "score" : 60 }
{ "_id" : ObjectId("55f5a1d3d4bede9ac365b25a"), "author" : "li", "score" : 94 }
{ "_id" : ObjectId("55f5a1d3d4bede9ac365b25b"), "author" : "ty", "score" : 95 }
// Apply this aggregation
@jdjkelly
jdjkelly / reduxir.md
Last active May 6, 2017 14:38
reduxir

Elixir-flavored Redux:

defmodule Store do
 def start_link(reducer, preloadedState) do
   Agent.start_link(fn -> { reducer, preloadedState } end)
 end

 def start_link(reducer) do
   Agent.start_link(fn -> { reducer, nil } end)
@jdjkelly
jdjkelly / counter.js
Created May 1, 2017 00:43
counter app
import { createStore } from 'redux'
function counter(state = 0, action) {
switch (action.type) {
case 'INCREMENT':
return state + 1
case 'DECREMENT':
return state - 1
default:
return state
@jdjkelly
jdjkelly / createStore.js
Last active May 1, 2017 00:37
subscribe
let currentListeners = []
let nextListeners = currentListeners
...
function subscribe(listener) {
if (typeof listener !== 'function') {
throw new Error('Expected listener to be a function.')
}
@jdjkelly
jdjkelly / createStore.js
Created May 1, 2017 00:24
Dispatch Flow Type
declare type Dispatch<A: { type: $Subtype<string> }> = (action: A) => A;
@jdjkelly
jdjkelly / createStore.js
Last active May 1, 2017 00:24
dispatch
function dispatch(action) {
if (!isPlainObject(action)) {
throw new Error(
'Actions must be plain objects. ' +
'Use custom middleware for async actions.'
)
}
if (typeof action.type === 'undefined') {
throw new Error(
@jdjkelly
jdjkelly / createStore.js
Last active April 30, 2017 23:34
getState()
...
let currentState = preloadedState
...
function getState() {
return currentState
}
@jdjkelly
jdjkelly / ducks.js
Last active April 30, 2017 19:54
ducks.js
export default function createStore(reducer, preloadedState) {
let state = preloadedState
let listeners = []
let dispatching = false
function getState() {
return state
}
function dispatch(action) {
@jdjkelly
jdjkelly / preload.js
Created April 30, 2017 18:47
simplest-possible-redux-app-with-preload
import { createStore } from 'redux';
const app = createStore((state, action) => { return state }, { booted_at: new Date() });