Skip to content

Instantly share code, notes, and snippets.

View geowarin's full-sized avatar

Geoffroy Warin geowarin

View GitHub Profile
@geowarin
geowarin / sw.js
Created June 28, 2017 14:57
Uber service worker
function fetchNCache(e) {
return fetch(e).then(function(t) {
if (200 !== t.status)
return Promise.resolve(t);
const n = t.clone();
return caches.open(cacheName).then(function(s) {
return requestExpectsHtml(e) && !responseIsHtml(n) ? Promise.resolve(t) : void s.put(e.url, n)
}),
Promise.resolve(t)
})
declare module 'react-table' {
import * as React from "react";
interface SortMethod {
id: string;
desc: boolean
}
export type ColumnAccessor<T> = (o: T) => any
const tablify = require('tablify');
const path = require('path');
const fs = require('fs');
const modules = fs.readdirSync('node_modules');
const pkgAndAuthor = modules
.map(m => path.join(__dirname, 'node_modules', m, 'package.json'))
.filter(pkg => fs.existsSync(pkg))
.map(pkg => require(pkg))
.map(p => ({author: p.author, pkgName: p.name}))
import test from 'ava';
import Rx from 'rxjs/Rx';
import {createStore} from 'redux';
test('should be observable', t => {
const reducer = (state, action) => {
if (action.type === 'increment') {
return {...state, counter: state.counter + 1}
}
# Start an HTTP server from a directory, optionally specifying the port
function server() {
local port="${1:-8000}";
sleep 1 && open "http://localhost:${port}/" &
# Set the default Content-Type to `text/plain` instead of `application/octet-stream`
# And serve everything as UTF-8 (although not technically correct, this doesn’t break anything for binary files)
python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port";
}
@geowarin
geowarin / .npmrc
Created February 20, 2016 10:01
Packagin an electron app with node-git
runtime = electron
target = 0.36.7
target_arch = x64
disturl = https://atom.io/download/atom-shell
@geowarin
geowarin / index-template.html
Created August 5, 2015 14:33
Template index for the html-webpack-plugin and react
<!DOCTYPE html>
<html{% if(o.htmlWebpackPlugin.files.manifest) { %} manifest="{%= o.htmlWebpackPlugin.files.manifest %}"{% } %}>
<head>
<meta charset="UTF-8">
<title>{%=o.htmlWebpackPlugin.options.title || 'Webpack App'%}</title>
{% if (o.htmlWebpackPlugin.files.favicon) { %}
<link rel="shortcut icon" href="{%=o.htmlWebpackPlugin.files.favicon%}">
{% } %}
{% for (var css in o.htmlWebpackPlugin.files.css) { %}
<link href="{%=o.htmlWebpackPlugin.files.css[css] %}" rel="stylesheet">
@geowarin
geowarin / docker.fish
Created June 30, 2015 10:22
docker.fish
function docker
set -l DOCKER (which docker)
if not set -q DOCKER_HOST
set -g DOCKER_IP (boot2docker ip)
set -gx DOCKER_HOST "tcp://$DOCKER_IP:2376"
set -gx DOCKER_CERT_PATH ~/.boot2docker/certs/boot2docker-vm
set -gx DOCKER_TLS_VERIFY 1
echo "Set docker host: $DOCKER_HOST"
end
@geowarin
geowarin / gulpfile.js
Last active December 10, 2015 21:26
gulpfile.js
var gulp = require('gulp');
var downloadelectron = require('gulp-download-electron');
var shell = require('gulp-shell');
var packageJson = require('./package.json');
var electron = require('gulp-electron');
gulp.task('package', function() {
gulp.src("")
.pipe(electron({
src: '.',
@geowarin
geowarin / jk.js
Created June 14, 2015 19:08
jk.js
#!/usr/bin/env node
var inquirer = require("inquirer"),
slugify = require("underscore.string/slugify"),
fs = require('fs'),
multiline = require('multiline'),
format = require("string-template"),
dateFormat = require('dateformat');
opt = require('node-getopt').create([