Skip to content

Instantly share code, notes, and snippets.

View kulp's full-sized avatar
💬
ceci n'est pas un statut

Darren Kulp kulp

💬
ceci n'est pas un statut
View GitHub Profile
@kulp
kulp / get_ip.sh
Last active February 4, 2023 20:02
Check public IP address and update NearlyFreeSpeech DNS with the result
#!/usr/bin/env bash
curl --silent --fail -4 api64.ipify.org "$@" ||
curl --silent --fail https://httpbin.org/ip "$@" | jq --raw-output .origin
@kulp
kulp / tmds.pl
Last active June 26, 2021 10:45
Generate TMDS codes (for DVI / HDMI)
#!/usr/bin/env perl
# Generate TMDS codes (for DVI / HDMI)
# Takes decimal numbers 0-255 on stdin and emits ASCII binary numbers on stdout.
# Emits 462 unique codes where the standard expects 460; the user should reject
# the two zero-transition codes it produces.
use strict;
use warnings;
# LSb first
sub unbitarray ($$) { unpack "S", pack "b$_[0]", join "", @_[0 .. $#_] }
@kulp
kulp / .gitignore
Last active February 20, 2019 03:07
Simple traits demo for sub-arithmetic types
*.o
main
@kulp
kulp / intersect_n.js
Last active January 1, 2017 02:07
Return the intersection of N arrays
function intersect_n()
{
var aoa = Array.prototype.slice.call(arguments);
var c = [];
var indexes = aoa.map(function(v) { return 0 });
while (aoa.every(function(curr,i) { return indexes[i] < curr.length })) {
var currs = aoa.map(function(curr,i) { return curr[indexes[i]] });
var max = Math.max.apply(null, currs);
aoa.forEach(function(curr,i) { while (curr[indexes[i]] < max) indexes[i]++; });
@kulp
kulp / gist:7c3c33e8b8b70252efe6
Created March 6, 2016 02:59
Update AWS Route 53 DNS entry with current IP
#!/bin/sh -e
HOSTED_ZONE_IP=/hostedzone/CHANGEME
DOMAIN=CHANGEME
TTL=300
my_ip=$HOME/.my_ip
IP=$(dig +short myip.opendns.com @resolver1.opendns.com)
if [ "$IP" = "$(cat $my_ip)" ]
then
exit 0
@kulp
kulp / sha1.c
Created August 17, 2015 17:33
SHA-1 command-line implementation in C
#include <stdint.h>
#include <stdio.h>
#include <limits.h>
static inline uint32_t rol(uint32_t x, unsigned char y)
{
return (x << y) | ((x >> (32 - y)) & ~(-1 << y));
}
static void chunk(uint32_t h[5], unsigned char *ptr)
@kulp
kulp / tenyr.tmlanguage
Last active February 17, 2017 20:34
tenyr syntax file for TextMate 2 / SublimeText 2
{ patterns = (
{ name = 'variable';
match = '\b([A-Pa-p])\b';
},
{ name = 'string.quoted.double';
begin = '"';
end = '"';
},
{ name = 'string.quoted.single';
begin = "'";
@kulp
kulp / ansi16_to_ansi256.pl
Last active August 29, 2015 14:01
Map ansi16 colours to ansi256 colours
#!/usr/bin/env perl
# export PAGER="ansi16_to_ansi256.pl | ${PAGER:-less -R}"
use strict;
use Color::ANSI::Util qw(ansi16_to_rgb rgb_to_ansi256);
my $esc = qr/\x1b\[/;
my $fg = qr/3\d/;
my $bg = qr/4\d/;
my $seq = qr/$esc((?:$fg|$bg)(?:;(?:$fg|$bg))*)m/o;
@kulp
kulp / huff_decode.c
Last active December 17, 2015 04:09
Huffman encoder
#include "huffman.h"
int huff_decode(const dict_entry *dict, char *out, const huff_word **in,
size_t *len, size_t *bits, size_t *off)
{
const dict_entry *n = dict;
int found = 0;
while (!found && *len && *off < *bits) {
unsigned char bit = (**in >> *off) & 1;
@kulp
kulp / huffman.pl
Last active December 17, 2015 03:19
Huffman encoder for files with lines like `symbol = freq`
#!/usr/bin/env perl
use strict;
use warnings;
my @queue = map { [ /(\S+)\s*=\s*(\d+)/, undef ] } <>;
my $total = 0;
my $bitlen = 0;
my $keys = 0;
while ((@queue = sort { $a->[1] <=> $b->[1] } @queue) > 1) {