Skip to content

Instantly share code, notes, and snippets.

View chriskillpack's full-sized avatar

Chris Killpack chriskillpack

View GitHub Profile
// 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"
@chriskillpack
chriskillpack / gauss_seidel.go
Last active October 1, 2020 07:33
Solve a 2D Poisson equation problem using Gauss-Seidel
// 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
@chriskillpack
chriskillpack / 437toutf8.go
Last active March 9, 2023 23:07
Convert the box drawing characters of PC codepage 437 to Unicode
/*
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
@chriskillpack
chriskillpack / morton.go
Created June 28, 2018 05:51
Morton ordering
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...
@chriskillpack
chriskillpack / wol.go
Created December 4, 2016 23:57
Broadcast Wake on LAN packet
// 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"
@chriskillpack
chriskillpack / floating-point.rb
Last active December 26, 2015 22:59
To start my exploration of IEEE754 (floating-point numbers) I decided to write a program that converts a decimal number into it's IEEE754 32-bit counterpart.
#!/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
@chriskillpack
chriskillpack / gist:4013683
Created November 4, 2012 20:42
Exploring Ruby modules
# My explorations into ruby modules and instance variables.
module TestModule
def tm_foo
@bar = 1
end
def self.hello
'world'
end
end
@chriskillpack
chriskillpack / background.js
Created August 16, 2012 04:41
Example chrome extension that reproduces undefined chrome.tabs
chrome.tabs.onUpdated.addListener(function() {
window.console.log('updated from background');
});
@chriskillpack
chriskillpack / trie.rb
Created December 22, 2011 01:56
Word trie
# 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}"