Skip to content

Instantly share code, notes, and snippets.

View dmeehan1968's full-sized avatar

Dave Meehan dmeehan1968

View GitHub Profile
@dmeehan1968
dmeehan1968 / jsx-no-bind.md
Last active February 12, 2018 10:10
react/jsx-no-bind

ESLINT rule: react/jsx-no-bind

The problem

Arrow functions create a new function on every render, decreasing performance as a result of:

  • Addtional garbage collection
  • Passing changed props to components causing render to travel further into the graph

This is particularly evident when iterating over an array to generate components, which also need function props to handle state change as a result of user interaction, such as onClick/onPress.

@dmeehan1968
dmeehan1968 / cherryPick.js
Created March 4, 2018 23:04
cherryPick - recurse any value, including objects and arrays, returning an array of values that match the predicate
// @flow
type Predicate<T> = T => boolean
export default function cherryPick<T>(memo: Array<T>, predicate: Predicate<T>, subject: T): Array<T> {
if (predicate(subject)) {
return [ ...memo, subject ]
}
if (Array.isArray(subject)) {
return subject.reduce((memo, subject) => cherryPick(memo, predicate, subject), memo)
@dmeehan1968
dmeehan1968 / foo.js
Created March 5, 2018 15:54
ES6 Enumerable Getters on Class Properties
class Foo {
set foo(value) {
Object.defineProperty(this, '_foo', {
value: value,
enumerable: false
})
}
get foo() {
@dmeehan1968
dmeehan1968 / flowtype-missing-indexer-property.js
Created March 6, 2018 14:28
Exploring Flow's 'missing indexer property' on class computed properties
/* @flow */
type KeyType = string
type ValueType = any
type MyMap = {
[KeyType]: ValueType
}
const object: MyMap = {
@dmeehan1968
dmeehan1968 / hr_step.sql
Last active March 14, 2018 15:30
Combine Heart Rate and Step in MySQL from HealthKit data export
select STR_TO_DATE(CONCAT(H.date, ' ', H.time), '%d/%m/%Y %H:%i') as datetime, H.min, H.max, coalesce(S.steps,0) as steps from heartrate H
left join steps S on
(H.date = S.date or H.date is null and S.date is null)
and
(H.time = S.time or H.time is null and S.time is null)
order by H.date, H.time
@dmeehan1968
dmeehan1968 / stream.js
Last active March 18, 2018 17:34
CSV to Mongo Stream musings
fs.createReadStream(argv.heart)
.pipe(csv.parse({ objectMode: true }))
.pipe(csv.transform({
header: columns => {
const properties = {
Start: 'start',
End: 'end',
'Heart Rate (count/min)': 'heartRate',
}
return columns.map(column => properties[column] || column)
@dmeehan1968
dmeehan1968 / TestView.swift
Created October 16, 2021 15:49
How to handle SwiftUI sheet(item:onDismiss:content) unwrapping of optional whilst allowing binding to be passed to sheet view
//
// This demonstrates how to use sheet(item:...) when the requirement is to pass a binding to the
// view presented by the sheet. Also relevant to fullCoverSheet(item:...)
//
// What we want the sheet to do is provide an editable form that can be cancelled, so partial changes
// are not committed to the ancestors view state. We only want the state changed IF the form is confirmed (save action)
//
import SwiftUI
@dmeehan1968
dmeehan1968 / cucumberjs_formatter_v7.js
Last active April 8, 2022 13:54
Modified Webstorm cucumber output formatter that correct mistakes in handling cucumber output
const common = require('./cucumberjs_formatter_common.js')
const formatter = function (options) {
const cucumber = require(options.parsedArgvOptions.cucumberLibPath)
new cucumber.SummaryFormatter(options)
let currentUri = ''
let currentFeatureName = ''
/**
* American Soundex algorithm (see https://en.wikipedia.org/wiki/Soundex)
*
* @example
* americanSoundex('Robert') === 'R163'
* americanSoundex('Rupert') === 'R163'
* americanSoundex('Rubin') === 'R150'
* americanSoundex('Ashcraft') === 'A261'
* americanSoundex('Ashcroft') === 'A261'
* americanSoundex('Tymczak') === 'T522'
@dmeehan1968
dmeehan1968 / EventBridgePutEvents.ts
Created November 9, 2023 15:52
Scheduler Target for EventBridge to PutEvents
import { ScheduleTargetBase, ScheduleTargetBaseProps } from "@aws-cdk/aws-scheduler-targets-alpha"
import { IRole, Role } from "aws-cdk-lib/aws-iam"
import { EventBus } from "aws-cdk-lib/aws-events"
import { ISchedule, ScheduleTargetConfig, ScheduleTargetInput } from "@aws-cdk/aws-scheduler-alpha"
/**
* This is a simple implementation of a EventBridge Scheduler Target that will put events to an EventBus.
* It is built upon the base provided by @aws-cdk/aws-scheduler-targets-alpha.
*/