Skip to content

Instantly share code, notes, and snippets.

View bryantee's full-sized avatar

Bryan Swagerty bryantee

View GitHub Profile
echo "hello"
{
"compilerOptions": {
"allowJs": false,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"esModuleInterop": true,
"experimentalDecorators": true,
"jsx": "react",
"lib": ["es6"],
"module": "commonjs",
interface Foo {
handleSelect(field: string): (newSelected: string) => void;
}
// vs
interface Bar {
handleSelect: (field: string) => (newSelected: string) => void;
}
/*
* Returns array of items de-duped based on primary key field
* ie: id
* */
function removeDuplications<T>(primaryKey: string, items: T[]): T[] {
if (items && items.length === 0) {
return [];
}
if (!items[0].hasOwnProperty(primaryKey)) {
@bryantee
bryantee / test.md
Last active September 20, 2018 18:29
Testing TypeScript support code blocks

TypeScript

  const things: string[] = ['foo', 'bar'];

vs

JavaScript

 const things: string[] = ['foo', 'bar'];
@bryantee
bryantee / app-criteria.md
Last active April 23, 2018 21:42
Tabris Challenge App Criteria

The Tabris 2 Challenge!

Acceptance Criteria

You can use as many APIs and concepts as you would like in your app, but it must contain at least one of each of the following:

@bryantee
bryantee / screenshot.sh
Created March 21, 2018 21:14
Take screenshots and save to you computer from an android device connected via adb
#!/bin/bash
adb shell screencap -p /sdcard/screenshot.png
adb pull /sdcard/screenshot.png
now=$(date +%d:%m-%H.%M.%S)
mv screenshot.png screenshot-${now}.png
@bryantee
bryantee / lerp.js
Created December 1, 2017 17:08
Linear Hex Interpolation fader
// props to @rosszurowski for this:
// https://gist.github.com/rosszurowski/67f04465c424a9bc0dae
function lerpColor(a, b, amount) {
let ah = parseInt(a.replace(/#/g, ''), 16),
ar = ah >> 16, ag = ah >> 8 & 0xff, ab = ah & 0xff,
bh = parseInt(b.replace(/#/g, ''), 16),
br = bh >> 16, bg = bh >> 8 & 0xff, bb = bh & 0xff,
rr = ar + amount * (br - ar),
rg = ag + amount * (bg - ag),
@bryantee
bryantee / determineWidth.js
Created November 22, 2017 22:25
determine spacing when you know width of items and total width of parent
const spaceBetweenDataPoints = (this.chartDimensions.width - data.length * DATA_POINT_SIZE) / (data.length + 1);
const leftMargin = spaceBetweenDataPoints * (index + 1) + (index > 0 ? (index) * DATA_POINT_SIZE : 0);
@bryantee
bryantee / refresh-stackoverflow.py
Last active May 13, 2017 17:33
Python script using Selenium to refresh StackOverflow every so often to get badge.
#!/usr/bin/python
from selenium import webdriver
from datetime import datetime
import time
import urllib
url = "http://stackoverflow.com"
everyXHours = 6
refreshrate = 60 * 60 * everyXHours # Refresh every hour
browser = webdriver.Firefox()