Skip to content

Instantly share code, notes, and snippets.

Avatar

Brian Boyko brianboyko

View GitHub Profile
@brianboyko
brianboyko / eslintrc.yml
Created Mar 18, 2020
eslint isn't working
View eslintrc.yml
extends:
- 'prettier'
- 'prettier/react'
- 'plugin:react/recommended'
- 'plugin:import/errors'
- 'plugin:import/warnings'
- 'plugin:jsx-a11y/recommended'
- 'plugin:@typescript-eslint/recommended'
- 'prettier/@typescript-eslint'
overrides: [{ files: ['*.js', '*.jsx'], rules: { '@typescript-eslint/*': "off" } }]
@brianboyko
brianboyko / example.ts
Created Feb 17, 2020
makeReduxStrategy
View example.ts
import makeReduxStrategy, {ReduxAction, ReduxReducer} from './makeReduxAction';
interface CounterAction extends ReduxAction {
payload: number;
}
const counterStrategy = makeReduxStrategy<number>({
ADD: (state: number, {payload}: CounterAction) => state + payload,
SUBTRACT: (state: number, {payload}: CounterAction) => state - payload,
})
View ifTruthyThen.ts
// *REALLY* hate Ternary syntax or && in your JSX rendering? Try this handy function.
const ifTruthyThen = <T>(predicate: any, value: T): T | null => {
if(!predicate){
return null;
}
return value;
}
// usage
@brianboyko
brianboyko / urlUuid.js
Created Mar 8, 2018
Encode and decode UUIDs into URL-safe Base 64
View urlUuid.js
// converts a UUID to a URL-safe version of base 64.
const encode = uuid => {
const stripped = uuid.replace(/-/g, ""); // remove dashes from uuid
const true64 = btoa(
String.fromCharCode.apply(
null,
stripped
.replace(/\r|\n/g, "")
.replace(/([\da-fA-F]{2}) ?/g, "0x$1 ")
.replace(/ +$/, "")
@brianboyko
brianboyko / looksay.js
Created Jan 24, 2018
Would you like to build a function?
View looksay.js
// Hey Anna, wanna write a function that returns the output for a look and say sequence: https://en.wikipedia.org/wiki/Look-and-say_sequence
function lookAndSaySequence(n) {
// would you like to build a function?
// a function that returns a striiiing.
var lookSay = function(strNum) {
var sayArray = [];
var repeats = 1; // we check to see how many nums
var digit = 0; // and say the num
View gist:3b7f517d35610628036367c17336dfe3
import neo4j, { Driver, Session } from "neo4j-driver";
import config from "../config";
const neoDriver: Driver = neo4j.driver(
config.neo.url,
neo4j.auth.basic(config.neo.login, config.neo.password),
{ useNativeNumbers: true }
);
export const neo = (): Session => neoDriver.session();
View normalizedCodes.json
This file has been truncated, but you can view the full file.
{
"10001": {
"zip": "10001",
"city": "New York",
"state": "New York",
"state_abbr": "NY",
"county": "New York",
"lat": 40.7484,
"lng": -73.9967
View zipCodes.csv
We can't make this file beautiful and searchable because it's too large.
zip,city,state,state_abbr,county,lat,lng
00501,Holtsville,New York,NY,Suffolk,40.8154,-73.0451
00544,Holtsville,New York,NY,Suffolk,40.8154,-73.0451
01001,Agawam,Massachusetts,MA,Hampden,42.0702,-72.6227
01002,Amherst,Massachusetts,MA,Hampshire,42.3671,-72.4646
01003,Amherst,Massachusetts,MA,Hampshire,42.3919,-72.5248
01004,Amherst,Massachusetts,MA,Hampshire,42.3845,-72.5132
01005,Barre,Massachusetts,MA,Worcester,42.4097,-72.1084
01007,Belchertown,Massachusetts,MA,Hampshire,42.2751,-72.411
@brianboyko
brianboyko / functional.js
Last active Oct 19, 2017
Functional Tools
View functional.js
// Takes a function and additional arguments to be applied, and returns
// a new function with those provided arguments already partially applied.
export const curry = (f, ...curriedArgs) => (...newArgs) =>
f.apply(null, curriedArgs.concat(newArgs));
// Allows to iterate functions over a variable.
export const Identity = value => ({
value,
map: f => Identity(f(value))
});
View gist:bb192784d6afb6e63d6f4c2c4e2b90f8
-- Read more about this program in the official Elm guide:
-- https://guide.elm-lang.org/architecture/effects/random.html
import Html exposing (..)
import Html.Attributes exposing(src)
import Html.Events exposing (..)
import String exposing (repeat)
import Random
main =
You can’t perform that action at this time.