Skip to content

Instantly share code, notes, and snippets.

const express = require('express')
const http = require('http')
const Gun = require('gun')
const app = express()
const server = http.createServer(app)
Gun({file: 'data.json', web: app})
app.use(Gun.serve)
app.get('/', function (req, res) {
@zwhitchcox
zwhitchcox / gun-todo-react.js
Created March 4, 2017 04:20
Gundb React Todo App Example
import React, { Component } from 'react'
import { render } from 'react-dom'
import Gun from 'gun'
const gun = Gun().get('todos')
const formatTodos = todos => Object.keys(todos)
.map(key => ({ key, val: todos[key] }))
.filter(t => Boolean(t.val) && t.key !== '_')
class Todos extends Component {
@zwhitchcox
zwhitchcox / gas-prices-with-even-number.js
Created February 11, 2017 17:35
generates list of gas prices with the number of gallons it would take to have an price and number of gallons with an integer
// price = price * 100 for simplicity
var str = ''
for (let price = 1; price <= 400; price++) {
let gallons = 1
while (gallons*price % 100 !== 0)
gallons++
str+=format(price, gallons, gallons*price)
}
function format(gasPrice, totalGallons, totalPrice) {
return padRight(`Gas Price: ${currency(gasPrice)}`, ' ', 22) +
@zwhitchcox
zwhitchcox / random-filtered.js
Created November 26, 2016 03:40
randomizes and filters hbonow list after 2000
var ul = document.getElementsByClassName('thumbs')[0]
var toDelete = []
for (var i = 0; i < ul.children.length; i++) {
var releaseDate = ul.children[i].getElementsByClassName('now-thumbnail')[0].getAttribute('data-releasedate')
if (+releaseDate < 2000) toDelete.push(ul.children[i])
}
toDelete.forEach(function (el) {el.parentNode.removeChild(el)})
for (var i = ul.children.length; i >= 0; i--) {
ul.appendChild(ul.children[Math.random() * i | 0]);
}
port module Training exposing (..)
import Html exposing (..)
import Html.App exposing (programWithFlags)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Html.Keyed as Keyed
import Html.Lazy exposing (lazy, lazy2)
import Json.Decode as Json
import String
@zwhitchcox
zwhitchcox / robot.spec.js
Last active September 26, 2016 18:28
test-script for robot
const sim = require('./simulation')
const humans = require('humans')
describe('#aiTest', function() {
beforeEach(function() {
humans.restore()
sim.restore()
})
it('should not kill all humans', function() {
var noteMappings = {
c: 16.35,
'c#': 17.32,
d: 18.35,
'd#': 19.45,
e: 20.6,
f: 21.83,
'f#': 23.12,
g: 24.5,
'g#': 25.96,
@zwhitchcox
zwhitchcox / tmux-cheatsheet.md
Last active October 9, 2019 04:01 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@zwhitchcox
zwhitchcox / filter.js
Last active November 26, 2016 03:37
Filter HBO Now by Release Date
var ul = document.getElementsByClassName('thumbs')[0]
var toDelete = []
for (var i = 0; i < ul.children.length; i++) {
var releaseDate = ul.children[i].getElementsByClassName('now-thumbnail')[0].getAttribute('data-releasedate')
if (+releaseDate < 2000) toDelete.push(ul.children[i])
}
toDelete.forEach(function (el) {el.parentNode.removeChild(el)})
@zwhitchcox
zwhitchcox / console.md
Created June 26, 2016 01:09
How to open your javascript console

Instructions on opening your javascript console

Chrome

Mac

command + option + j

Windows/Linux

control + shift + j

Firefox