Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
⌨️ probably clacking

Tim Whidden twhid

💭
⌨️ probably clacking
View GitHub Profile
@twhid
twhid / app.ts
Last active Feb 19, 2021
Start Next.js if behind passenger
View app.ts
// 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';
@twhid
twhid / readme.md
Last active Dec 17, 2020
minimal typescript/TSX React SSR Express example
View readme.md

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 / getBabelOptions.js
Last active Mar 27, 2018
Set inlineRequires to false
View getBabelOptions.js
// 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 / showmethesrcs.js
Last active Jun 15, 2017
One-liner return an array of script srcs based on a regex (eg a domain). Handy to use in Chrome's console.
View showmethesrcs.js
[].slice.call(document.getElementsByTagName('script')).filter(script => /example.com/.test(script.src)).map(script => script.src);
@twhid
twhid / jest_webstorm_conf.sh
Last active Sep 22, 2016
jest webstorm config
View jest_webstorm_conf.sh
# 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
View ampersand-router.js
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) {
View reducer.js
function (state = {}, action) {
switch (action.type) {
case 'VIEW_ORDERS':
return {
...state,
pageType: 'orders',
orderId: null
};
case 'VIEW_ORDER':
return {
@twhid
twhid / docker.jenkins.github.sh
Last active May 24, 2016
bash script to build docker images of node apps via jenkins jobs. Requires jq and the Jenkins GitHub plugin.
View docker.jenkins.github.sh
#!/usr/bin/env bash
# AWS domain
DOMAIN=${AWS_DOMAIN}
# Set CI_TEST to true to exit the script before build commences.
TEST=${CI_TEST:-'false'}
# Defaults for testing (variables supplied by Jenkins when in that environment).
GIT_URL=${GIT_URL:-"git@github.com:foo/foo-bar-baz-qux.git"}
View image-contracts-v3.js
// NOTE* The notations below assume that there is only 1 size per image, ie. new dynamically sized images are already working :
// POST a new image :
// soa/inventory-3/2/image
// payload : multi part form-data
// return value :
{
id : '123',
original : '/path/to/original.jpeg',
master : '/path/to/master.jpeg',
@twhid
twhid / resolveModuleDirPath.js
Created Jun 11, 2015
One-liner to resolve the directory path of a module using the built-in Node.js algorithm
View resolveModuleDirPath.js
var moduleDir = require.resolve('module/package').replace('package.json', '');