Skip to content

Instantly share code, notes, and snippets.

@simenbrekken
simenbrekken / loader.js
Created April 5, 2016 11:36
Loader decorator factory
import React from 'react';
import PureComponent from 'react-pure-render/component';
import { getDisplayName } from '../utils';
function getComponentRequiredProps({ propTypes }) {
return Object.keys(propTypes).filter(key => !propTypes[key].isRequired);
}
export default function(loader = null, ownRequiredProps) {
FROM binarytales/heroku-nodejs
ENV NODE_ENV=production
WORKDIR /app
# Cache npm install
COPY package.json .
RUN npm install
@simenbrekken
simenbrekken / firebase-decorator-api.jsx
Last active December 16, 2015 09:04 — forked from danielmahal/firebase-decorator-api.jsx
Firebase decorator api
// Alternative 1
// One function at top-level that returns whatever it needs.
// Can be run multiple times, and return different things
@firebase(props => {
if (!props.projectIndex) {
return {
projectIndex: `users/${props.authId}/projects`,
};
}
@simenbrekken
simenbrekken / find-unused.sh
Created October 23, 2015 12:21
Find unused modules
#/bin/bash
JS_FILES=$(find "$@" -name "*.js*")
for FILE in $JS_FILES; do
short_name=`basename $FILE`
filename="${short_name%.*}"
git grep --quiet \/$filename\' 1>/dev/null
if [ "$?" == "1" ]; then
echo "Should delete: $FILE"
fi
@simenbrekken
simenbrekken / index.js
Last active September 23, 2015 20:15
Create CloudFront invalidations when S3 origin changes
var aws = require('aws-sdk');
var cloudFront = new aws.CloudFront();
function getDistributionDomains(distribution) {
return distribution.Origins.Items.map(function(origin) {
return origin.DomainName;
});
}
function findBucketDistributions(bucket, callback) {
@simenbrekken
simenbrekken / index.js
Created September 21, 2015 08:27
Data loader entitiy listing
groupsLoader.load('admins')
.then(users => users.map(user => userLoader.set(user.id, user))
@simenbrekken
simenbrekken / echoHttpRequest.js
Last active September 7, 2015 03:32 — forked from Marak/echoHttpRequest.js
Echo HTTP requests
module['exports'] = function echoHttp (hook) {
console.log("Console messages are sent to /logs");
console.log(hook.params);
console.log(hook.req.path);
console.log(hook.req.method);
@simenbrekken
simenbrekken / deployment.sh
Last active January 25, 2016 22:17
Codeship Azure Website Custom Deployment Script
# $AZURE_REPO_URL needs to be set in your projects Variables section
# and include both username and password, e.g: https://username:[email protected]:443/site.git
# Clone Azure repository
git clone $AZURE_REPO_URL ~/azure
cd ~/azure
# Replace repository contents
rsync --archive --delete --exclude ".*" ~/clone/public/ .
@simenbrekken
simenbrekken / 0_reuse_code.js
Last active August 29, 2015 14:21
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@simenbrekken
simenbrekken / CategoryStore.js
Last active August 29, 2015 14:19
Relay-style higher-order React components backed by Reflux
var Reflux = require('reflux')
var axios = require('axios')
var CategoryStore = Reflux.createStore({
init: function() {
this.items = null
},
list: function() {
var items = this.items