Skip to content

Instantly share code, notes, and snippets.

View jmacqueen's full-sized avatar

Jonathan MacQueen jmacqueen

  • Bitsight
  • United States
View GitHub Profile
@jmacqueen
jmacqueen / dyncount
Last active September 15, 2016 12:10
Helper bash script for AWS command line DockerDB scan counts
#!/bin/bash
case $1 in
help)
echo 'usage: dyncount <table> <column> <"="|"<>"|"<"|"<="|">"|">="> <type> <value>';
echo 'example: ./dyncount user firstName "=" S Gary';
echo '';
echo 'usage: dyncount <table> <column> <attribute_exists|attribute_not_exists>';
echo 'example: ./dyncount user firstName attribute_exists';
echo '';
@jmacqueen
jmacqueen / docker-compose.yml
Created September 22, 2016 01:56
Basic docker-compose.yml for playing with Kafka
zookeeper:
image: wurstmeister/zookeeper:3.4.6
ports:
- "2181:2181"
kafka:
image: ches/kafka:0.9.0.1
ports:
- "9092:9092"
links:
- zookeeper
@jmacqueen
jmacqueen / application.js
Created October 6, 2016 16:06
Create an Ember application instance that can be imported into any file. Useful for container lookups in files outside of the usual hierarchy.
// app/instance-initializers/application.js
import appInst from 'appName/utils/application'
export function initialize( appInstance ) {
appInst.instance = appInstance
}
export default {
name: 'application',
initialize
};
@jmacqueen
jmacqueen / PromiseRetry.js
Created April 11, 2017 13:16
Promise with retry
function tryWithRefresh(funcs, catchFunc){
const outerPromises = funcs.map( fn => typeof fn === 'function' ? fn() : fn )
return Promise.all(outerPromises)
.catch( (err) => {
if (err.status !== 401) { console.log(err); return; }
authService.refreshToken()
.then( () => {
console.log('refresh success')
const innerPromises = funcs.map( fn => typeof fn === 'function' ? fn() : fn )
Promise.all(innerPromises)
@jmacqueen
jmacqueen / something.test.js
Created September 27, 2017 11:38
How to mock components from ui-lib
jest.mock('@echo360/ui-lib', () => {
const module = jest.genMockFromModule('@echo360/ui-lib')
module.Button = 'Button'
module.SelectSingle = 'SelectSingle'
module.TextInput = 'TextInput'
return module
})
@jmacqueen
jmacqueen / CSS Task.md
Last active July 27, 2021 16:07
CSS Exercise

The Task

Given the HTML markup:

<button class="checkout-btn">
  checkout
</button>

Without changing the HTML, make the button look reasonably similar to the screenshot below. It doesn't have to have pixel-perfect measurements. Feel free to use Google. Try not to spend more than an hour on it. The colors used are: lightsteelblue, steelblue, white and darkslategray and the font is whatever sans-serif floats your boat.

@jmacqueen
jmacqueen / React Task.md
Last active July 21, 2021 11:56
React Exercise

The Task

Implement a React component that will receive an array of options:

  [
    { label: 'Label 1', value: 1 },
    { label: 'Label 2', value: 2 },
    { label: 'Label 3', value: 3 },
    { label: 'Label 4', value: 4 }
 ]
@jmacqueen
jmacqueen / AppWithContext.js
Created January 15, 2019 15:54 — forked from dndhm/AppWithContext.js
React Context.Consumer mocking
import React, { Component } from 'react';
import FruitContext from './FruitContext';
import FruityComponent from './FruityComponent';
export class App extends Component {
state = {
fruit: 'apple',
}
@jmacqueen
jmacqueen / mockSlowAsyncService.js
Created February 14, 2019 20:05
During the mocking phase, I like to see loading states, too!
mockData = [1,2,3]
const getSlowThing = async () => {
await new Promise(resolve => setTimeout(resolve, 3000))
return Promise.resolve(mockData)
}
@jmacqueen
jmacqueen / queryObj.js
Created February 20, 2019 13:21
Object from the browser query
query = window.location.search
.replace('?','')
.split('&')
.reduce((obj, item) => {
const pair = item.split('=')
obj[pair[0]] = pair[1]
return obj
}, {})