Skip to content

Instantly share code, notes, and snippets.

const htmlIndex = require('simple-html-index')
const BufferList = require('bl')
function createPage (title) {
const html = htmlIndex({ title })
const htmlBuffer = html.pipe(BufferList())
return function flush () {
// return htmlBuffer // works
return htmlBuffer.duplicate() // doesn't work (empty)
@timwis
timwis / nginx.conf
Created August 19, 2016 22:08
nginx conf to redirect
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
sendfile on;
@timwis
timwis / index.js
Created August 31, 2016 11:53
requirebin sketch
const choo = require('choo')
const html = require('choo/html')
const app = choo()
let dispatch
const listen = (cb) => dispatch = cb
app.model({
state: { foo: 'bar' },
app.router((route) => [
route('/', Layout()),
route('/:phone', requireLogin(Layout(Chat))),
route('/login', Layout(Login))
])
function requireLogin (View) {
return function (state, prev, send) {
if (!state.user.name) send('user:requireLogin')
return View(state, prev, send)
@timwis
timwis / view.js
Created September 8, 2016 11:10
couchdb view
/* global emit */
const TOKEN_LIFESPAN = 30 // seconds
module.exports = {
_id: '_design/users',
views: {
byEmail: {
map: function (doc) {
emit(doc.metadata.email)
}
function ensureParams (...params) {
params.forEach((param) => assert(window[param], `${param} must be passed`))
}

CouchDB Password Reset

Password reset implementation for CouchDB

Usage

const http = require('http')
const jsonBody = require('body/json')
const PasswordReset = require('couchdb-password-reset')
const Templates = reqiure('couchdb-password-reset/templates')
@timwis
timwis / proxy.sh
Last active September 20, 2016 15:17
Toggle proxy script for OSX
#######################
# Toggle Proxy
# Usage:
# sudo ./proxy.sh on
# sudo ./proxy.sh off
#######################
NETWORK_SERVICE=Wi-Fi # The name of the device in "Network Settings" left-hand panel
networksetup -setwebproxystate $NETWORK_SERVICE $1
/* global setState, sendVerificationEmail, sendApprovalEmail, sendRejectNotification, isValidKey */
const supervisors = [
'[email protected]',
'[email protected]'
]
module.exports = {
name: 'Travel Request',
states: [
{
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="robots" content="NONE,NOARCHIVE">
<title>AttributeError at /api/travel-request/</title>
<style type="text/css">
html * { padding:0; margin:0; }
body * { padding:10px 20px; }