Skip to content

Instantly share code, notes, and snippets.

View jcreamer898's full-sized avatar
🏠
Working from home

Jonathan Creamer jcreamer898

🏠
Working from home
View GitHub Profile
import * as React from "react";
import formatPrice from "../utils/formatPrice";
export interface IPriceProps {
num: number;
symbol: "$" | "€" | "£";
}
const Price: React.SFC<IPriceProps> = ({
num,
// @ts-check
/**
* Format a price
* @param num {number} The price
* @param symbol {string} The currency symbol
*/
const formatPrice = (num, symbol = "$") =>
`${symbol}${num.toFixed(2)}`;
formatPrice("1234");
const formatPrice = (num: number, symbol = "$": string) =>
`${symbol}${num.toFixed(2)}`; formatPrice("1234");
// num.toFixed is not a function
@jcreamer898
jcreamer898 / formatPrice.js
Last active February 2, 2018 01:35
Stuff for my typescript blog
const formatPrice = (num, symbol = "$") =>
`${symbol}${num.toFixed(2)}`; formatPrice("1234");
@jcreamer898
jcreamer898 / launch.json
Last active September 20, 2017 14:43
How I use vscode's debugger with our nodejs apps
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Run tests",
"program": "${workspaceRoot}/node_modules/.bin/jest"
},
{
Name of thing Sorta like... Mounted? Can you even setState? What would you say... ya do here?
constructor initialize() nope nope init stuff NO side effects
componentWillMount beforeDomReady() nope yeah but don't Only needed in createClass now use constructor for most things
render render nope please no render stuff and don't set any state please
componentDidMount domReady() yup yup DOM is a go init jQuery plugins dispatch stuff
componentWillReceiveProps onChange() yup yup

This works in JavaScript, but when I try to compile it with TS, I get the following error...

I want to be able to do the following...

const Auth = asyncComponent(() =>
  require.ensure([], require => require("../auth/index").default, "auth_async"),
);
@jcreamer898
jcreamer898 / README.md
Last active April 26, 2017 01:53
Setting up a node + react development environment
@jcreamer898
jcreamer898 / assigned.js
Created April 25, 2017 15:13
Github Projects Helpers
const toggleAssigned = (function () {
let showing = false;
return function (username) {
const $cards = $$(".issue-card");
Array.from($cards).forEach((el) => {
if (!showing) {
if (!el.querySelectorAll("img[alt='@" + username + "']").length) {
el.style = "display:none";
@jcreamer898
jcreamer898 / giphy.sh
Created February 7, 2017 22:06
Giphy Search
#!/bin/bash
input=$1
query=${input// /%20}
url=http://api.giphy.com/v1/gifs/search\?q=$query\&api_key\=dc6zaTOxFJmzC
image=$(curl -s $url | jq '.data[0] | { url: .images.fixed_height.url } | .url')
echo "Added $image to the clipbboard."
echo ${image//\"/ } | pbcopy