Skip to content

Instantly share code, notes, and snippets.

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 / 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 / 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 / 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 {
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 / 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
@zwhitchcox
zwhitchcox / force-kill
Created June 11, 2018 13:06
Force kill process by port in one command
#!/bin/bash
# force kill process by port
# Usage: "force-kill PORT"
sudo netstat -tulnp | grep "$1" | sed -r -e "s/.*LISTEN\\s+([0-9]+).*/\1/" | xargs sudo kill -9
@zwhitchcox
zwhitchcox / go-exercise-web-crawler.go
Created September 20, 2018 19:40
Go Exercise: Web Crawler
package main
import (
"fmt"
"sync"
)
type Fetcher interface {
Fetch(url string) (body string, urls []string, err error)
}
@zwhitchcox
zwhitchcox / install-vim-with-python
Last active September 13, 2019 01:42
Bash Script to Install Vim With Python Support
#!/bin/bash
PY2_CONFIG_DIR=$(sudo find /usr/lib -type d -regex ".*python2.[0-9]/config[^/]*")
PY3_CONFIG_DIR=$(sudo find /usr/lib -type d -regex ".*python3.[0-9]/config[^/]*")
if ( [ -d "$PY2_CONFIG_DIR" ] || [ -d "$PY3_CONFIG_DIR" ] ) ; then
py2_arg="--with-python-config-dir=$PY2_CONFIG_DIR"
py3_arg="--with-python3-config-dir=$PY3_CONFIG_DIR"
fi
@zwhitchcox
zwhitchcox / gist:82be19a9ba281737baf01d258914335f
Created December 26, 2019 21:34
keyboard shortcuts vscode
// Place your key bindings in this file to override the defaults
[
{
"key": "ctrl+`",
"command": "workbench.action.terminal.focus",
"when": "editorTextFocus"
},
{
"key": "ctrl+`",
"command": "workbench.action.focusActiveEditorGroup",