This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A vanilla Trie class. | |
# Only interesting thing is gather_words_along_path. | |
class Trie | |
def initialize(filename = nil) | |
@trie = [{}, false] | |
@word_count = 0 | |
end | |
def to_s | |
"words: #{@word_count}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chrome.tabs.onUpdated.addListener(function() { | |
window.console.log('updated from background'); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# My explorations into ruby modules and instance variables. | |
module TestModule | |
def tm_foo | |
@bar = 1 | |
end | |
def self.hello | |
'world' | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Convert a decimal number into its 32-bit IEEE754 floating-point | |
# representation. | |
# Example: | |
# $ ./floating-point.rb -1313.3125 | |
# Decimal: -1313.3125 | |
# As binary fraction: 010100100001.0101 | |
# Exponent = ^10 = 1024 = 10001001 | |
# Mantissa = 01001000010101000000000 | |
# 11000100101001000010101000000000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Broadcast Wake On LAN packet, see https://en.wikipedia.org/wiki/Wake-on-LAN#Magic_packet | |
package main | |
import ( | |
"fmt" | |
"log" | |
"net" | |
"os" | |
"strings" | |
"time" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
// A Morton code (aka z-order) interleaves the individual bits of X & Y | |
// coordinates. Below are routines that show how to generate a Morton | |
// code from X & Y integer coordinates in range [0,31) and do the reverse. | |
// The goal of these routines is to be educational (primarily me) and | |
// are not optimal. A diagram showing how Morton codes cover a 2D space | |
// would be nice... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Convert the box drawing characters of PC codepage 437 to Unicode | |
and encode as UTF-8. | |
If no argument is provided then program reads from stdin. These are equivalent: | |
437toutf8 437in.txt > utf8out.txt | |
437toutf8 < 437in.txt > utf8out.txt | |
*/ | |
package main |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Solve the Poisson equation for a 2D grid using the Gauss-Seidel method | |
// Gauss-Seidel method: https://en.wikipedia.org/wiki/Gauss–Seidel_method | |
// The problem used is Example 1 from https://my.ece.utah.edu/~ece6340/LECTURES/Feb1/Nagel%202012%20-%20Solving%20the%20Generalized%20Poisson%20Equation%20using%20FDM.pdf | |
// A 4x4 grid of electrical values | |
// - top boundary is Dirichlet boundary fixed at 1.0V | |
// - bottom boundary is Dirichlet boundary fixed at 0.0V | |
// - left & right boundaries are Neumann boundaries fixed at derivative 0.0V | |
package main |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Middleware provides an http.Handler that verifies an incoming request as coming from the Alexa | |
// web service using the steps described at https://developer.amazon.com/en-US/docs/alexa/custom-skills/host-a-custom-skill-as-a-web-service.html#manually-verify-request-sent-by-alexa | |
// Note: validation requires an HTTP GET of an Amazon certificate. Configure the middleware with an | |
// http.Client to have some control over the fetch. | |
package alexa | |
import ( | |
"bytes" | |
"context" | |
"crypto" |