Skip to content

Instantly share code, notes, and snippets.

View ratbeard's full-sized avatar

Mike Frawley ratbeard

View GitHub Profile
#
# Git
#
alias g='git'
alias gl="clear && git log"
alias gll="clear && git log --graph --pretty=format:'%Cred%h%Creset %an: %s - %Creset %C(yellow)%d%Creset %Cgreen(%cr)%Creset' --abbrev-commit --date=relative"
alias glp="clear && git log -p"
alias gs="clear && git status -sb"
// Export a helper component that allows for easy translations in views w/o
// needing to use the context directly. Only handles simple key lookup at the
// moment.
function Translate({ id }: {
id: keyof T
}) {
return (
<i18nContext.Consumer>
{
({ translate }) => translate(id)
{
"React component": {
"prefix": "com",
"body": [
"import React, { Component } from 'react';",
"",
"interface Props {",
" $3",
"}",
"",
/*
Concern 1: CUSTOM STYLES
Custom theme styles are given to us as json.
Object has one level of nesting, mostly grouped by the component w/ some higher level blocks like 'global'.
We are not allowing free reign custom styles, but highly targeted element+property styles.
We should have global 'theme color' properties so you don't need to specify the same color in 10 places.
// Current setup is a all styles go in a single file w/ a single flat `[element name]: { styles for that element }` block:
export const defaultStyles = {
quizHeader: {
display: 'flex',
},
quizHeaderLogo: {
background: '',
},
import { tryJsonParse } from "./tryJsonParse";
// Small wrapper around localStorage that converts to/from json.
//
// We also define all localStorage keys/values we store upfront here.
// This way all values are documented, and we get type saftey.
//
interface LocalStored {
device_info: string;
debugRedirects: boolean;
@ratbeard
ratbeard / classNames.ts
Created January 2, 2019 16:18
Typescript version of the classNames util w/ es6 export, so typescript is able to import it without confusion.
// Based on: https://github.com/JedWatson/classnames/blob/master/index.js
/*!
Copyright (c) 2018 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/
var hasOwn = {}.hasOwnProperty;
export function classNames(...args: any[]) {
class BaseballCards extends Component {
render() {
return <b onClick={this.onClick}> sup</b>
}
// class-level prop, gets .bind(this) when constructing the object so `this` is always the correct object instance.
onClick = (event) => {
console.log(this, 'rules!')
}
}
interface RequestOptions {
authToken?: string
}
interface Fun {
age: number;
}
const InitEndpoint = {
get({ id }: { id: string }, options?: RequestOptions): Promise<Fun> {
return Promise.resolve({ age: 1})
@ratbeard
ratbeard / styles.json
Last active July 25, 2018 18:25
Dynamic styles for react native prototype
{
"currentFolderName": {
"color": "#ff0000",
"fontSize": 30,
"textAlign": "right"
},
"childFolder": {
"fontSize": 20,
"marginBottom": 10
},