Skip to content

Instantly share code, notes, and snippets.

View Techcable's full-sized avatar
🇺🇸
Procrastinating

Techcable

🇺🇸
Procrastinating
View GitHub Profile
@Techcable
Techcable / BooleanConsumer.java
Created May 25, 2016 23:45
A list of booleans packed into a byte
@FunctionalInterface
public interface BooleanConsumer {
public void accept(boolean b);
}
@Techcable
Techcable / checkstyle.xml
Last active August 1, 2016 17:23
Techcable's Checkstyle/Formatting System
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="charset" value="UTF-8"/>
<module name="NewlineAtEndOfFile">
<property name="lineSeparator" value="lf"/>
@Techcable
Techcable / pidgits.py
Last active September 6, 2016 06:31
A _pythonic_ pidigts calculator for The Computer Lanaguage Benchmarks Game, using builtin arbitrary precision integers
# A _pythonic_ pidigts calculator for The Computer Lanaguage Benchmarks Game
# Unlike the other python versions of this program, this uses python's builtin integers.
# I'd argue this is the 'pythonic' way to do this, since it takes advantage of builtin types.
# Derived from the C version and the Chappel version, but with more descriptive names.
from itertools import count, zip_longest, islice, repeat
import sys
class Term(object):
__slots__ = ("accumulator", "numerator", "denominator") # got2gofast!
def __init__(self, accumulator, numerator, denominator):
@Techcable
Techcable / kotlinw.sh
Last active September 1, 2016 21:01
A bash wrapper for kotlin script (similar to gradlew), which will locate the kotlin compiler (downloading if needed), and execute your script
#!/bin/sh
KOTLIN_VERSION="1.0.3"
KOTLIN_COMPILER_URL="https://github.com/JetBrains/kotlin/releases/download/v${KOTLIN_VERSION}/kotlin-compiler-$KOTLIN_VERSION.zip"
KOTLIN_COMPILER_HASH="37615f1d63e8500cd33c7f3e60b715263f65189d6d8f25defba78968c896dc97" # The hash of the compiler's zip-file
KOTLIN_INSTALATION_DIR="$HOME/.kotlin/$KOTLIN_VERSION"
if [ $# -lt 1 ]; then
echo "Insufficient arguments: $#";
exit 1;
@Techcable
Techcable / primes.c
Last active October 8, 2016 17:20
Highly Optimized Prime Finder (ten million primes in under half a minute)
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <errno.h>
#include <string.h>
#include <assert.h>
/**
* When it becomes worthwile to do a binary search for the upper bound.
*
@Techcable
Techcable / main.c
Created November 5, 2016 23:56
Project Euler #27 (Quadratic Primes)
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
ptrdiff_t indexOfPrime(uint64_t num);
const uint64_t *findPrimes(size_t amount);
@Techcable
Techcable / index.html
Created November 14, 2016 15:21
Northminster Church Live Stream
<div data-live="true" data-autoplay="true" class="flowplayer" data-ratio="0.4167">
<video data-title="Live Stream">
<source type="application/x-mpegurl" src="http://ws.nhicdn.net/worshipstream/_definst_/mp4:NorthminsterPresbyterianChurch.stream/playlist.m3u8">
</div>
@Techcable
Techcable / LibraryLoader.java
Created November 18, 2016 21:02
Download dependencies from maven central at runtime, caching in the user's local repository
/*
* The MIT License
* Copyright (c) 2016 Techcable
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
@Techcable
Techcable / varint.py
Last active March 23, 2025 14:46
Command Line Varint Decoder/Encoder Tool
from typing import Iterable
from argparse import ArgumentParser
from sys import exit
parser = ArgumentParser(description="Parses and dencodes protobuf varints")
parser.add_argument("mode", help="Whether to encode or decode")
parser.add_argument("num", help="The number to decode/encode")
args = parser.parse_args()
@Techcable
Techcable / gcd.c
Last active December 7, 2016 16:25
Fast binary GCD using trailing zero count.
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
// Everyone says "oh I know about double evaluation, it's no problem" and a few months down the road, you'll be debugging the silliest problems for hours on end.
#define max(a, b) ({ \
__typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; \