Skip to content

Instantly share code, notes, and snippets.

View sskoopa's full-sized avatar

SS Koopa sskoopa

View GitHub Profile
@sskoopa
sskoopa / Dockerfile
Created October 26, 2016 20:59
Dockerfile for using google-cloud (or any native module) and sharing app with Mac local
#alpine-node is a super small distro with just the minimum to run
FROM mhart/alpine-node:6
WORKDIR /app
#allow local code to mount into this directory
VOLUME /app
#move all native plugins up to -g installs and link them one level above the app
RUN npm install -g google-cloud && cd / && npm link google-cloud && cd /app
@sskoopa
sskoopa / entries.js
Created October 26, 2016 21:52
Node v6 Object.entries shim
function entries (O) {
var entrys = []
for (var key in O) {
if (O.hasOwnProperty(key) && O.propertyIsEnumerable(key)) {
entrys.push([key, O[key]])
}
}
return entrys
};
@sskoopa
sskoopa / .babelrc
Created October 27, 2016 17:28
Need to use babel and preact-compat?
{
"plugins": [
["transform-react-jsx", { "pragma":"h" }],
["module-resolver", {
"root": ["."],
"alias": {
"react": "preact-compat",
"react-dom": "preact-compat"
}
}]
@sskoopa
sskoopa / results-before-and-after.txt
Last active November 3, 2016 21:58
Test attempt for preact #254
Before:
=============================== Coverage summary ===============================
Statements : 95.78% ( 590/616 )
Branches : 89.75% ( 473/527 )
Functions : 92.16% ( 47/51 )
Lines : 96.78% ( 541/559 )
================================================================================
After:
@sskoopa
sskoopa / docker-run-memcache.md
Created November 11, 2016 19:07
Run memcache in docker

docker run -d -p 11211:11211 --name cache memcached:alpine

@sskoopa
sskoopa / simple-xhr.js
Created November 17, 2016 18:51
Simple XHR to use like fetch in REST APIs
var oReq = new XMLHttpRequest()
oReq.onload = function (e) {
var xhr = e.target
if (xhr.status === 200 && onSuccess) {
onSuccess(xhr.response)
} else if (xhr.status !== 200 && onFailure) {
onFailure(xhr.response)
}
}
oReq.open(method, action, true)
@sskoopa
sskoopa / app.js
Created January 15, 2017 16:49
Use node-sass-middleware in express
const express = require('express')
const sassMiddleware = require('node-sass-middleware')
const app = express()
app.use(sassMiddleware({
/* Options */
src: path.join(__dirname, '../public/scss'),
response: true,
debug: true,
@sskoopa
sskoopa / ssr.js
Created November 19, 2016 16:33
Super simple and fast preact server side rendering
function ssr(req, res, url) {
let user = req.user //comes from passport
const preloadedState = { user, url } // Compile an initial state
const store = configureStore(preloadedState) // Create a new Redux store instance
const html = render(<Provider store={store}><Html /></Provider>) // Render the component to a string
const finalState = store.getState() // Grab the initial state from our Redux store
res.send(renderFullPage(html, finalState)) // Send the rendered page back to the client
}
function renderFullPage(html, preloadedState) {
@sskoopa
sskoopa / patch-require-ensure.js
Created March 4, 2017 22:22
polyfill for require.ensure on NodeJS when using webpack 1 for code-splitting
// polyfill for webpacks' require.ensure()
// credit: https://github.com/webpack/webpack/issues/183#issuecomment-169186696
//
let proto = Object.getPrototypeOf(require)
!proto.hasOwnProperty('ensure') && Object.defineProperties(proto, {
'ensure': {
value: function ensure (modules, callback) {
callback(this)
},
writable: false
@sskoopa
sskoopa / webpack-size.sh
Created October 26, 2016 17:12
Why is my webpack bundle sooo big!?
#!/bin/bash
# This is intended for use with create-react-app
#npm install -g webpack-bundle-size-analyzer
NODE_ENV=production webpack --config node_modules/react-scripts/config/webpack.config.prod.js --json src/index.js | webpack-bundle-size-analyzer