Skip to content

Instantly share code, notes, and snippets.

View tbl3rd's full-sized avatar
👣
Scalawag

Tom Lyons tbl3rd

👣
Scalawag
View GitHub Profile
@tbl3rd
tbl3rd / EtcDhcpDhcpdConf.java
Created April 4, 2015 14:14
manage private LAN addresses
package tbl3rd.provider;
import tbl3rd.provider.Api_2015_04_01;
import tbl3rd.provider.Api_2015_04_01.NetworkInformation;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
@tbl3rd
tbl3rd / EtcHosts.java
Created April 4, 2015 14:13
manage private LAN addresses
package tbl3rd.provider;
import tbl3rd.provider.Api_2015_04_01;
import tbl3rd.provider.Api_2015_04_01.NetworkInformation;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
@tbl3rd
tbl3rd / Inet4CidrBlock.java
Created April 4, 2015 14:00
manage private LAN addresses
package tbl3rd.provider;
import tbl3rd.provider.Api_2015_04_01;
import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
@tbl3rd
tbl3rd / ComplexMat.h
Created March 26, 2015 20:01
Because C++ forbids std::complex<cv::Mat> for who knows what reason ...
#ifndef COMPLEX_MAT_H_INCLUDED
#define COMPLEX_MAT_H_INCLUDED
#include <opencv2/core/core.hpp>
// Because C++ forbids std::complex<cv::Mat> for who knows what reason ...
//
// ComplexMat and CompExpMat are just two suggestive names for the same
// type. ComplexMat has real and imaginary parts. ComplexExp has cosine
@tbl3rd
tbl3rd / kerry.clj
Last active August 29, 2015 14:17
Good luck, Kerry!
(ns kerry)
(defn make-rand-x-to-y
"A function that uses rand-x to generate rand-y,
where (rand-n) has the integer range [0, n)."
[x y]
(let [randx (fn [] (rand-int x))
size (* x y)
choices (into [] (take size (cycle (range y))))]
(fn []
@tbl3rd
tbl3rd / macForInterface.c
Created March 6, 2015 17:54
MACs for Macs
/* Write at result the hardware (MAC) address of the network interface name.
Return -1 on failure or 0 on success.
*/
static int macForInterface(const char *name, struct sockaddr *result)
#ifdef __APPLE__
{
int failed = -1;
struct ifaddrs *ifap = NULL;
if (0 == getifaddrs(&ifap)) {
struct ifaddrs *p = ifap;
@tbl3rd
tbl3rd / timestamp.sh
Created March 3, 2015 02:01
system programing in bash
#!/bin/bash
# This script is designed to make sure that a signal delivered to it
# is propagated to a subshell running the program feeding the lines to
# be timestamped. The usual command line is:
#
# timestamp command ... arguments ...
# The 'builtin' specifications are not necessary, but are included to
# convey that what follows them are internal shell commands, so bash
@tbl3rd
tbl3rd / call-periodically-when-visible.cljs
Created February 25, 2015 21:07
Call f with args every ms milliseconds when document is visible.
(defn call-periodically-when-visible
"Call f with args every ms milliseconds when document is visible."
([ms f]
(letfn [(call [id]
(let [id (if (.-hidden js/document)
(and id (js/clearInterval id) nil)
(js/setInterval f ms))]
(goog.events/listenOnce
js/document "visibilitychange" #(call id))))]
(call nil)))
(defn drop-nth-tbl3rd
"coll with every nth element removed"
[n coll]
(letfn [(drop-when [coll drops]
(lazy-seq
(when-let [s (seq coll)]
(let [more (drop-when (rest s) (rest drops))]
(if (first drops) more (cons (first s) more))))))]
(drop-when coll (rest (cycle (cons true (repeat (dec n) false)))))))
@tbl3rd
tbl3rd / responder.clj
Last active August 29, 2015 14:15
difficult
(ns responder.core
(:import [com.google.common.collect ImmutableMap$Builder]))
(def responses
(letfn [(+ [& lines] (clojure.string/join " " lines))]
(-> (new ImmutableMap$Builder)
(. put "weather" (+ "There is an 80% chance of rain this afternoon."
"The high will be 8 and the low 2."))
(. put "window" "Sensors indicate that all windows are closed.")
(. put "heat" "Your thermostat is currently set to 20.")