Skip to content

Instantly share code, notes, and snippets.

View crobinson42's full-sized avatar
🏠
Working from home

Cory Robinson crobinson42

🏠
Working from home
  • American Software
  • Northwest USA
View GitHub Profile
@crobinson42
crobinson42 / pubsub.ts
Last active January 23, 2022 20:02 — forked from sidola/pubsub.ts
Basic typesafe pub-sub implementation in Typescript
/**
* Defines the function type of the publish function.
*
* Extracts the keys from `E` as valid event types, and the matching
* property as the payload.
*/
type PubTypeFn<E> = <Key extends string & keyof E>(
event: Key,
fn: (message: E[Key]) => void
) => void
const { DataStore } = require('js-data')
class ExtendedDataStore extends DataStore {
constructor(props) {
super(props)
if (props.extends)
Object.assign(this, props.extends)
}
}
@crobinson42
crobinson42 / 1.txt
Created November 20, 2019 15:53
Blog SEO rewrites
Selling security guard services is admittedly not the sexiest of jobs, but with the right attitude and motivation you can do well both professionally and financially. In order to be great at security guard sales, or sales in general, it requires extensive reading and even more practice. One of the first books that I read and refer back to fairly regularly is The 25 Most Common Sales Mistakes and How to Avoid Them by Stephan Schiffman. Stephan is a Certified Management Consultant who has trained and consulted with corporations such as IBM, Motorola, and Cigna. He has trained over 500,000 professionals across 9,000+ companies. Of the 25 most common mistakes outlined in his book, there are 10 that are essential to anyone involved in security guard sales. I have taken the liberty of summarizing those 10 below.
Mastering Security Guard Sales
Security guard service is one of the most competitive industries that exists (if it isn’t it, sure does feel like it) and losing a sale can be the result of being a pen
@crobinson42
crobinson42 / mongo-to-kafka.js
Last active October 11, 2019 16:32
Watch mongodb and publish to kafka
/*
NOTE: this is a naive first attempt at tailing mongo collections to publish kafka messages
and removed module imports and other stuff for brevity....
*/
function normalizeMongoDocument(document) {
// convert "_id" to "id"
const normalized = { id: document._id, ...document }
delete normalized._id
@crobinson42
crobinson42 / Example.jsx
Created July 8, 2019 16:47
JS-Data React Hook useStoreQuery(mapperName, query)
import React from 'react'
import useStoreQuery from './useStoreQuery'
const ActiveUsers = ({ storeQuery, storeQueryLoading }) => {
const { users, loading } = useStoreQuery('users', { where: { active: true } })
return (
<div>{loading ? 'Loading...' : `${users.length} active users found`}</div>
)
@crobinson42
crobinson42 / js-data-react.jsx
Created June 7, 2019 22:55
JS-data React HOC
/* eslint-disable react/no-multi-comp, react/prop-types */
import React from 'react'
import hoistNonReactStatic from 'hoist-non-react-statics'
import shallowEqual from '../utils/shallowEqual'
function ConnectModelsHOC({ loadingProp, modelName, modelNames }, mapPropsWithModels) {
return WrappedComponent => {
class ConnectModels extends React.Component {
static contextType = ''
@crobinson42
crobinson42 / error
Created March 27, 2019 00:54
kafka-node refreshMetadataError
kafka-node:KafkaClient Connect attempt 1 +0ms
kafka-node:KafkaClient Trying to connect to host: 192.168.0.150 port: 9092 +3ms
kafka-node:KafkaClient kafka-node-client createBroker 192.168.0.150:9092 +1ms
kafka-node:KafkaClient kafka-node-client sending versions request to 192.168.0.150:9092 +902ms
kafka-node:KafkaClient broker socket connected {"host":"192.168.0.150","port":"9092"} +3ms
kafka-node:KafkaClient connected to socket, trying to load initial metadata +2ms
kafka-node:KafkaClient missing apiSupport waiting until broker is ready... +1ms
kafka-node:KafkaClient waitUntilReady [BrokerWrapper 192.168.0.150:9092 (connected: true) (ready: false) (idle: false) (needAuthentication: false) (authenticated: false)] +1ms
kafka-node:KafkaClient Received versions response from 192.168.0.150:9092 +69ms
kafka-node:KafkaClient setting api support to {"21":{"min":0,"max":1,"usable":false},"22":{"min":0,"max":1,"usable":false},"23":{"min":0,"max":2,"usable":false},"24":{"min":0,"max":1,"usable":false},"25":{"min":0,"max
@crobinson42
crobinson42 / ReactotronConfig.js
Created December 31, 2018 17:02
Reactotron react-native config - redux implementation locking up up
import Reactotron from 'reactotron-react-native';
import sagaPlugin from 'reactotron-redux-saga';
import { reactotronRedux } from 'reactotron-redux';
import envLocal from './.local.json';
export default () => Reactotron
// your local IP goes in .env.local.json (which is in .gitignore)
.configure({ host: envLocal.ip })
// .use(sagaPlugin())
@crobinson42
crobinson42 / index.html
Created December 29, 2018 14:32
Axios file upload progress indicator
<html>
<title>Axios Progress Upload</title>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.js"></script>
<input id="file" type="file" name="files" multiple="multiple" /><br />
<br>
<progress id="progress" max="100" value="0"></progress>
@crobinson42
crobinson42 / ExtendedDataStore.js
Last active November 7, 2018 23:04
JS-Data - Proxy context issue demo (https://stackoverflow.com/posts/53197772)
import { DataStore, Mapper } from 'js-data'
class ExtendedDataStore extends DataStore {
as(name) {
const props = {}
// const original = super.as(name)
const mapper = this.getMapper(name)
const self = this
// if "this" is passed instead of "self" the downstream methods fail without straightforward Error stacktrace