Skip to content

Instantly share code, notes, and snippets.

View Fordi's full-sized avatar

Bryan Elliott Fordi

View GitHub Profile
@Fordi
Fordi / response-to-how-to-power-a-city.md
Last active November 2, 2016 18:00
Response to "How to power a city of 100.000 people using only renewable energy"

Since you didn't include sources, and got your units all confused, I figured I'd try to rewrite some of this.


We'll use the United States as a model, as it will give us the "worst-case". The US Population is about [323 million][Population Clock], and we consume about [3,900 TWh/year][US Electricity Consumption] across all sectors - so the per-capita demand for a US citizen and all the support she requires to live, is about 12 MWh/year. For our city of 100,000, therefore, we'll need about 1.2 TWh/year of clean energy.

/**
* Today in code golf.
*
* This defines a class that, in an optimized way, is able to search a dictionary
* for words containing only a subset of the specified letters.
*
* To do this, it first ingests the dictionary words, one by one.
*
* The words are broken up into their constituent letters, converted to indices,
* then the letters are sorted The top level of the resulting table is, then, the
@Fordi
Fordi / vc-rev
Last active December 9, 2020 17:16
vc-rev: similar to git-hash, except it works on svn repositories as well. Minimal dependency on sqlite3 for SVN repos
#!/bin/sh
# From the Stack response:
# http://stackoverflow.com/a/33133769/353872
#
# Also acts as a low-complexity example of how to flexibly parse the argument
# list in raw sh without external programs or a lot of fuss.
# For use in usage() and in log messages
SCRIPT_NAME="$(basename $0)"
@Fordi
Fordi / git-hash
Last active December 29, 2020 18:51
Get the current hash from a Git repository without external dependencies (including Git)
#!/bin/sh
# From the Stack response:
# http://stackoverflow.com/a/33133769/353872
#
# Also acts as a low-complexity example of how to flexibly parse the argument
# list in raw sh without external programs or a lot of fuss.
# For use in usage() and in log messages
SCRIPT_NAME="$(basename $0)"
@echo off
:: If you have Xming installed, this will get you connected to your Raspberry Pi, and will start blueman-manager,
:: thereby enabling you to pair bluetooth like a civilized human being
:: Remember to close the X Server from the system tray when you're done.
set XMING_HOME=C:\Program Files (x86)\Xming
set PI_HOST=raspberry
set PI_USER=pi
set PI_PASS=raspberry
cd %XMING_HOME%
start "Xming" /B "%XMING_HOME%\xming.exe" -from localhost -multiwindow
@Fordi
Fordi / jsdaemon.sh
Last active August 29, 2015 03:31
Bluetooth joypad-watching daemon for RetroPie
#!/bin/bash
# For my RetroPie-based Game Frame
# When a bluetooth controller is connected, will turn on the screen, put the processor into
# "performance" mode, and start EmulationStation
# When any controller presses L+R+Start+Select, the reverse will occur:
# ES is killed, the processor is put into "ondemand" mode, HDMI is turned off, and all BT
# devices are disconnected.
watch_pad() {
DEV=/dev/input/$1
/**
* ImmutableArray - exactly what it sounds like: an Array you can't change.
*
* Usage:
* var myArray = [1, 2, 3],
* myImmutableArray = myArray.immutable;
*
* ImmutableArrays can be used in place of normal Arrays in most cases, with the exception of the following mutator functions:
* #pop(), #push(item), #reverse(), #shift(), #unshift(item), #splice(start, length, items...), and #sort([sortfn])
* If used, these will throw a warning, copy the array, mutate it, and return the mutated array.
@Fordi
Fordi / index.html
Last active August 29, 2015 14:18 — forked from TheMcMurder/index.html
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap-responsive.css" rel="stylesheet">
<link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap.css" rel="stylesheet">
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
</head>
<div class="page-header">
<center>
@Fordi
Fordi / Object.watch.js
Last active August 29, 2015 14:17
Object.watch and Object.getMetadata for all browsers
/***
* Object.watch / Object.unwatch for all browsers
* Plus bonus: Object.assign / Object.getMetadata / Object.getGUID
* @author Bryan Elliott
* @copyright 2015 GPLv2
**/
(function () {
"use strict";
var meta = {},
guid = 1,
@Fordi
Fordi / lzw.js
Last active March 3, 2019 04:05 — forked from anonymous/lzw.js
export const lzw = {
decode: str => {
var i, code, phrase,
dict = {},
chr = str[0],
last = chr,
out = [chr],
next = 256;
for (i = 1; i < str.length; i++) {
code = str[i].charCodeAt(0);