Skip to content

Instantly share code, notes, and snippets.

View twhid's full-sized avatar
💭
⌨️ probably clacking

Tim Whidden twhid

💭
⌨️ probably clacking
View GitHub Profile
function (state = {}, action) {
switch (action.type) {
case 'VIEW_ORDERS':
return {
...state,
pageType: 'orders',
orderId: null
};
case 'VIEW_ORDER':
return {
const Router = new AmpersandRouter({
// define all of the routes in our application.
// AmpersandRouter will invoke the method named when a route is
// matched on either page load or a browser back/forward click
routes: {
'/my/order/receipt/:orderId': 'loadReceipt'
'/my/order/:orderId': 'loadOrder',
'/my/orders': 'loadOrders',
},
initialize(options) {
@twhid
twhid / jest_webstorm_conf.sh
Last active September 22, 2016 14:41
jest webstorm config
# To run and debug jest tests using webstorm's configurations
# create a new Node.js configuration and configure it this way:
Node interpreter: /path/to/bin/node
Working Directory: /path/to/project
Javascript file: ./node_modules/.bin/jest
Application parameters: -i # ensures all tests run in 1 process
@twhid
twhid / showmethesrcs.js
Last active June 15, 2017 19:30
One-liner return an array of script srcs based on a regex (eg a domain). Handy to use in Chrome's console.
[].slice.call(document.getElementsByTagName('script')).filter(script => /example.com/.test(script.src)).map(script => script.src);
@twhid
twhid / getBabelOptions.js
Last active March 27, 2018 15:27
Set inlineRequires to false
// relay/scripts/getBabelOptions.js
const fbjsPreset = require('babel-preset-fbjs/configure')({
autoImport: options.autoImport || false,
objectAssign: false,
inlineRequires: false, // <-- FALSE!
stripDEV: options.env === 'production'
});
@twhid
twhid / readme.md
Last active December 17, 2020 22:11
minimal typescript/TSX React SSR Express example

minimal typescript/TSX React SSR Express example

To run locally..

ts-node needs to be installed. You'll also need to install express, react, and react-dom.

  1. Make tsConfig.json a sibling to server.tsx
  2. run like so $ NODE_PORT=8888 ts-node server.tsx
  3. open http://localhost:8888/ in a browser.
@twhid
twhid / app.ts
Last active February 19, 2021 21:47
Start Next.js if behind passenger
// I found bad advice online on how to use Next.js behind passenger https://www.phusionpassenger.com/
// yarn start or npm start won't work. This file is derived from the code that runs when you
// run the yarn start command. Tested only in my particular setup where the file is required
// to be called app.js. This file is TS, so you'll need to transpile to JS in your build,
// eg change package json build script to (you'll need a tsconfig.server.json file):
// "build": "next build && tsc --project ./tsconfig.server.json",
import http from 'http';
import next from 'next';