Skip to content

Instantly share code, notes, and snippets.

@zwhitchcox
zwhitchcox / git-total-lines.sh
Last active June 10, 2018 03:12
show total amount of lines added or removed from git repository without yarn.lock or package-lock.json
# total lines removed
git log --numstat --pretty="" | grep -v lock | sed -r -e "s/^([0-9]+)\\s+([0-9]+).*/\2/" | grep -v "^-" | paste -sd+ | bc
# total lines added
git log --numstat --pretty="" | grep -v lock | sed -r -e "s/^([0-9]+)\\s+([0-9]+).*/\2/" | grep -v "^-" | paste -sd+ | bc
# the main thing to edit would be git log. You could change this to whatever author you like or over
# whatever time frame or between two commits, etc. The `grep -v lock` removes all files like yarn.lock
# or package-lock.json, which is the main reason I created this command, because those files added like 40,000
# line changes to my code. Also the `grep -v "^-"`removes `png` files and such that are not countedl
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]);
}
@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)})
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 / 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