Skip to content

Instantly share code, notes, and snippets.

View ntalbott's full-sized avatar
💻
Writing and Coding

Nathaniel Talbott ntalbott

💻
Writing and Coding
View GitHub Profile
#!/usr/bin/env ruby
CASES = {
"" => ["", "", "", "", ""],
"Some random data." => ["Some random data.", "", "", "", ""],
"This information should be ignored RECORD_NUM 02 This is the information for record 2 RECORD_NUM 01 This is the information for record 1 RECORD_NUM 04 This is the information for record 4" =>
[" This is the information for record 1 ", " This is the information for record 2 ", "", " This is the information for record 4", ""],
}
def process(input, expected_record_count=5)
@ntalbott
ntalbott / ipxrelay.patch
Created November 28, 2015 21:40
Patch allowing cross-compilation for ipxrelay
diff --git a/Makefile b/Makefile
index 873fb1b..20dcc64 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,5 @@
-CC = gcc
+CROSSCOMPILE ?=
+CC = $(CROSSCOMPILE)gcc
CWARN = -W -Wall
COPT = -g -O2
@ntalbott
ntalbott / msort.ex
Created July 15, 2015 18:21
Using case
defmodule MSort do
def msort(list) do
case list do
[] -> []
[e] -> [e]
_ ->
{left, right} = Enum.split(list, div(Enum.count(list), 2))
merge(msort(left), msort(right))
end
end
defmodule MSort do
def msort([]), do: []
def msort([e]), do: [e]
def msort(list) do
{left, right} = Enum.split(list, div(Enum.count(list), 2))
merge(msort(left), msort(right))
end
def merge(left, []), do: left
def merge([], right), do: right

Keybase proof

I hereby claim:

  • I am ntalbott on github.
  • I am ntalbott (https://keybase.io/ntalbott) on keybase.
  • I have a public key whose fingerprint is 5E2C CDC3 C673 A034 85BE EC4C D9B0 B680 05FC B035

To claim this, I am signing this object:

@ntalbott
ntalbott / verify
Created January 12, 2015 20:01
Verify secretsharing permutations
#!/usr/bin/env ruby
require "securerandom"
TESTS = (ARGV[0] || 1).to_i
N = (ARGV[1] || 4).to_i
K = (ARGV[2] || 2).to_i
BYTES = (ARGV[3] || 24).to_i
puts "Running #{TESTS} tests of n=#{N} k=#{K} with bytelength of #{BYTES}..."
@ntalbott
ntalbott / gpgme.rb
Last active August 29, 2015 14:12
gpgme formula using gpg1
require "formula"
class Gpgme < Formula
homepage "https://www.gnupg.org/related_software/gpgme/"
url "ftp://ftp.gnupg.org/gcrypt/gpgme/gpgme-1.5.1.tar.bz2"
mirror "https://mirrors.kernel.org/debian/pool/main/g/gpgme1.0/gpgme1.0_1.5.1.orig.tar.bz2"
sha1 "a91c258e79acf30ec86a667e07f835e5e79342d8"
depends_on "gnupg"
depends_on "libgpg-error"
@ntalbott
ntalbott / build.log
Last active August 29, 2015 14:11
Reduction showing challenge with a struct containing mutable and (intended) immutable fields.
ntalbott@lorica:~/play/rust-sandbox$ cargo build
Compiling rust-sandbox v0.0.1 (file:///Users/ntalbott/play/rust-sandbox)
/Users/ntalbott/play/rust-sandbox/src/main.rs:18:17: 18:39 error: cannot assign to `self.offset` because it is borrowed
/Users/ntalbott/play/rust-sandbox/src/main.rs:18 self.offset += c.len();
^~~~~~~~~~~~~~~~~~~~~~
/Users/ntalbott/play/rust-sandbox/src/main.rs:16:15: 16:19 note: borrow of `self.offset` occurs here
/Users/ntalbott/play/rust-sandbox/src/main.rs:16 match self.peek() {
^~~~
/Users/ntalbott/play/rust-sandbox/src/main.rs:29:41: 29:49 error: cannot borrow `s.offset` as immutable because `s` is also borrowed as mutable
/Users/ntalbott/play/rust-sandbox/src/main.rs:29 println!("char: {}, offset: {}", c, s.offset);
require "formula"
class Cargo < Formula
homepage "http://crates.io"
url "https://github.com/rust-lang/cargo/archive/master.tar.gz"
version "wip"
head "https://github.com/rust-lang/cargo.git"
depends_on "rust"
depends_on "cmake" => :build
@ntalbott
ntalbott / check-cert-revocation
Created April 15, 2014 19:31
Checks whether a cert in PEM format is revoked or not.
#!/usr/bin/env ruby
require "open-uri"
text = `openssl x509 -text -in #{ARGV[0]}`
#puts text
raw_serial = text[/Serial Number:\s*\n?\s*(\d+ \(0x\w+\)|\w{2}(?::\w{2})+)/, 1]
puts "Raw serial: #{raw_serial}"
serial = case raw_serial
when %r{\d+ \(0x(\w+)\)}