Skip to content

Instantly share code, notes, and snippets.

Avatar

Peter W techieshark

View GitHub Profile
View package.json
{
"name": "anything",
"version": "0.1.0",
"dependencies": {
"@mapbox/mapbox-sdk": "^0.10.0",
"@mapbox/polyline": "^1.1.0",
"@material-ui/core": "^4.8.2",
"@material-ui/icons": "^4.5.1",
"@turf/circle": "^6.2.0-alpha.1",
"@turf/distance": "^6.2.0-alpha.1",
View __mocks__stripe.ts
// __mocks__/stripe.ts: Jest Mock for Stripe class
/**
* Fake a response from stripe.customers.list().
* @example
* mockStripeCustomerList(1) === { data: ['fake customer'], object: 'list', … }
* @param count number of fake customers to return
*/
export const mockStripeCustomerList = (count: number) => ({
data: (new Array(count)).fill('fake customer'),
View send204.ts
import { NO_CONTENT } from 'http-status-codes';
const send204 = (req: Request, res: Response, next: NextFunction) => {
res.status(NO_CONTENT);
res.end();
};
@techieshark
techieshark / setAllowHeader.ts
Created Aug 29, 2019
node: setAllowHeader()
View setAllowHeader.ts
import { NextFunction, Request, Response } from 'express';
/**
* Sets Allow header.
*
* "The Allow header lists the set of methods support by a resource.
* This header must be sent if the server responds with a 405 Method Not Allowed
* status code to indicate which request methods can be used."
*
*
@techieshark
techieshark / index.js
Created Feb 22, 2019
browserFeatures
View index.js
/**
* Returns whether the current browser supports
* the `locales` argument of Number.prototype.toLocaleString().
* IE < 11 does not.
* Copied from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#Checking_for_support_for_locales_and_options_arguments
* @return {boolean} true if browser supports it, otherwise false.
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#Browser_compatibility
*/
function toLocaleStringSupportsLocales() {
const number = 0;
@techieshark
techieshark / objectValues.js
Created Feb 22, 2019
Flow-typed version of Object.values()
View objectValues.js
// @flow
// Flow-typed version of Object.values()
// @see: problem - https://github.com/facebook/flow/issues/2221
// @see: this solution - https://stackoverflow.com/a/51757027/1024811
export default function objectValues<A, B>(obj: {[key: A]: B}): Array<B> {
return ((Object.values(obj): any): Array<B>);
}
@techieshark
techieshark / pick.js
Created Feb 22, 2019
simple pick.js implementation
View pick.js
// @flow
/**
* Returns new object made of the picked paths.
* Native implementation of lodash `pick`.
* Shaves 1-2kb off download size: https://bundlephobia.com/result?p=lodash.pick@4.4.0.
* @see https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_pick
* @see https://lodash.com/docs/#pick
* @return {Object}
*/
@techieshark
techieshark / australian-postcodes.sql
Created Jun 1, 2018 — forked from randomecho/australian-postcodes.sql
Australian postcodes (with states and suburb names) geocoded with latitude and longitude.
View australian-postcodes.sql
/*
Taken and cribbed from blog.datalicious.com/free-download-all-australian-postcodes-geocod
May contain errors where latitude and longitude are off. Use at own non-validated risk.
*/
SET NAMES utf8;
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
DROP TABLE IF EXISTS postcodes_geo;
@techieshark
techieshark / add_remove_class.js
Created May 24, 2018
add/remove class without jQuery (just Vanilla JS)
View add_remove_class.js
/**
* Remove a CSS class from an HTML element.
* @param {HTMLElement} el The HTML element to modify.
* @param {string} className The class to remove.
* @returns null
* @see http://youmightnotneedjquery.com/#remove_class
*/
function removeClass(el, className) {
if (el.classList)
el.classList.remove(className);
View keybase.md

Keybase proof

I hereby claim:

  • I am techieshark on github.
  • I am techieshark (https://keybase.io/techieshark) on keybase.
  • I have a public key ASAGfHHdWMNLxRSipw5fj5uzzNELExUqoXtBuY0RPYw41go

To claim this, I am signing this object: