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
@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';
@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 / 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 / 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 / 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
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) {
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 17:29
bash script to build docker images of node apps via jenkins jobs. Requires jq and the Jenkins GitHub plugin.
#!/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"}
@twhid
twhid / cssmin.js
Created May 3, 2012 17:13 — forked from FiNGAHOLiC/cssmin.js
grunt cssmin sqwish task
// grunt minify CSS task using sqwish
grunt.registerMultiTask('cssmin', 'minify css with sqwish', function () {
var sqwish = require('sqwish'),
dest = this.file.dest;
try {
var css = grunt.file.read(this.file.src),
min = sqwish.minify(css);
@twhid
twhid / pre-commit
Last active November 13, 2015 18:42
Run JSHint validation before commit.
#!/bin/sh
#
# Run JSHint validation before commit.
#
# Originally: http://stackoverflow.com/a/21238963/302550
#
# Requires Node (http://nodejs.org/) and jshint (https://www.npmjs.org/package/jshint)
# be globally installed (e.g.: npm install jshint -g).
#
# Edited slightly to make it easier to work with Git GUIs (e.g. PHPStorm IDE, Tower).