Skip to content

Instantly share code, notes, and snippets.

@mrwithersea
mrwithersea / react-stateless-componentdidmount.js
Last active August 11, 2017 13:19
React stateless componentDidMount
<input ref={ function(component){ component && React.findDOMNode(component).focus();} } />
/^(0[1-9]|1[0-2])-(0[1-9]|1\d|2\d|3[01])-(19|20)\d{2}$/
@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();
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 / 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
),
@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
);
/^(?!\s*$)-?(0|[1-9]\d*)?(\.\d+)?$/
@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"
@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 / 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));