Skip to content

Instantly share code, notes, and snippets.

@mrwithersea
mrwithersea / elasticsearch-dedup-earliest-event.json
Last active September 19, 2018 15:13
Elasticsearch dedupe earliest event
{
"size": 0,
"query": {
"match": {
"event": "generate_docx"
}
},
"aggs":{
"dedupe_event_by_factfind" : {
"terms":{
@mrwithersea
mrwithersea / prop-or-self.js
Last active January 3, 2018 15:49
Get the prop or return the identity function
const propOrSelf = R.curry((prop, value) => R.when(
R.propSatisfies(R.complement(R.isNil), prop),
R.prop(prop)
)(value));
@mrwithersea
mrwithersea / react-redux-connected-hoc.js
Created November 22, 2017 09:49
Unit tests on a react-redux connected HOC
import { compose, lifecycle } from 'recompose';
import { connect } from 'react-redux';
import { getSomeState } from '../selectors';
import { doSomething } from '../actions';
export default compose(
connect(
(state) => ({
auth: getSomeState(state),
}),
@mrwithersea
mrwithersea / docker-compose.yml
Created November 15, 2017 14:06
Web proxy poc
version: '2'
services:
service-one:
image: nginx:1.9
volumes:
- ./service1:/usr/share/nginx/html/
ports:
- "3001:80"
/^(?!\s*$)-?(0|[1-9]\d*)?(\.\d+)?$/
@mrwithersea
mrwithersea / safe-number.js
Last active November 22, 2017 09:52
Safe Number
import R from 'ramda';
const safeNumber =
R.when(
R.test(/^(?!\s*$)-?(0|[1-9]\d*)?(\.\d+)?$/),
Number
);
@mrwithersea
mrwithersea / ramda-title-case.js
Last active October 11, 2021 13:23
Ramda Title Case
import R from 'ramda';
const capitalize =
R.converge(
R.concat,
[
R.compose(
R.toUpper,
R.head
),
const { ObjectID } = require('mongodb');
const moment = require('moment');
const thisWeek = moment().startOf('isoWeek').unix();
const cursor = db.collection('records').aggregate(
{
$project: {
thisWeek: {
$cond: {
@mrwithersea
mrwithersea / mongo-records-this-week.js
Last active July 28, 2017 10:39
Get mongo records started this week
const { ObjectID } = require('mongodb');
const moment = require('moment');
const thisWeek = moment().startOf('isoWeek').unix();
const week = yield db.collection('records').find({
_id: {
$gt: ObjectID.createFromTime(thisWeek)
}
}).count();