Skip to content

Instantly share code, notes, and snippets.

View styfle's full-sized avatar

Steven styfle

View GitHub Profile
@styfle
styfle / InputNumber.tsx
Last active April 17, 2018 17:01
InputNumber.tsx example for componentWillReceiveProps
interface Props {
value: number;
onChange: (value: number) => void;
widthPx?: number;
inline?: boolean;
disabled?: boolean;
}
interface State {
valueAsString: string;
@styfle
styfle / simpsons-characters.md
Created April 10, 2018 15:49
An alphabetical list of characters from The Simpsons

Simpsons Characters

An alphabetical list of characters from The Simpsons

  • Apu Nahasapeemapetilon
  • Bart Simpson
  • Carl Carlson
  • Duffman
  • Edna Krabappel
  • Fat Tony
@styfle
styfle / 49156502.ts
Created March 7, 2018 17:55
Answer to stackoverflow question 49156502
function isDate(obj: any): obj is Date {
return typeof obj === 'object' && 'toISOString' in obj;
}
function isString(obj: any): obj is string {
return typeof obj === 'string';
}
interface JWT {
id: string;
@styfle
styfle / 41705559.ts
Created November 17, 2017 15:04
TypeScript SO question 41705559
type Opt = { id: string, name: string }
interface MultiProps {
isMultiple: true;
options: Opt[];
id: string[];
onChange: (id: string[]) => void;
}
interface SingleProps {
@styfle
styfle / keybase.md
Created October 5, 2017 16:01
Proof that I am the real styfle!

Keybase proof

I hereby claim:

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

To claim this, I am signing this object:

@styfle
styfle / newsapi.json
Created August 25, 2017 18:03
newsapi.json
{
"status": "ok",
"source": "the-new-york-times",
"sortBy": "top",
"articles": [{
"author": "Michael M. Grynbaum",
"title": "Wall Street Journal Editor Admonishes Reporters Over Trump Coverage",
"description": "In internal emails, Gerard Baker described the draft of an article about the president’s rally in Phoenix as “commentary dressed up as news reporting.”",
"url": "https://www.nytimes.com/2017/08/23/business/media/wall-street-journal-editor-admonishes-reporters-over-trump-coverage.html",
"urlToImage": "https://static01.nyt.com/images/2017/08/24/business/24wsj1/24wsj1-facebookJumbo.jpg",
@styfle
styfle / web.config.xml
Created July 13, 2017 15:14
Security and Caching settings for web.config in ASP.NET
<system.web>
<httpCookies requireSSL="true" />
</system.web>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Strict-Transport-Security" value="max-age=31536000"/>
<add name="X-XSS-Protection" value="1; mode=block"/>
<add name="X-Content-Type-Options" value="nosniff"/>
@styfle
styfle / .htaccess
Last active November 12, 2018 17:04
Apache config for a https enabled, secure headers, cache headers, etc
## Set security headers per https://observatory.mozilla.org
Header set Strict-Transport-Security "max-age=15768000" env=HTTPS
Header set Content-Security-Policy "frame-ancestors 'self'"
Header set X-Frame-Options "SAMEORIGIN"
Header set X-XSS-Protection "1; mode=block"
Header set X-Content-Type-Options "nosniff"
## Add some rewrite rules per https://stackoverflow.com/a/13997498/266535
RewriteEngine On
@styfle
styfle / requirePromise.js
Created May 10, 2017 01:40
Promises in Node.js 8.x Core
function requirePromise(modName, fnName) {
return require('util').promisify(require(modName)[fnName]);
}
const stat = requirePromise('fs', 'stat');
const writeFile = requirePromise('fs', 'writeFile');
const appendFile = requirePromise('fs', 'appendFile');
@styfle
styfle / after-promisify.js
Created May 10, 2017 01:37
Promises in Node.js 8.x Core
const promisify = require('util').promisify;
const fs = require('fs');
const stat = promisify(fs.stat);
const writeFile = promisify(fs.writeFile);
const appendFile = promisify(fs.appendFile);
async function exists(f) {
try {
const stats = await stat(f);
return true;