Skip to content

Instantly share code, notes, and snippets.

Avatar

Thomas Hurst Freaky

View GitHub Profile
@Freaky
Freaky / nzbsplit.rb
Created Mar 13, 2020
Split an NZB into multiple smaller NZBs
View nzbsplit.rb
#!/usr/bin/env ruby
def usage() abort("#{$0} [base nzb] [number of new nzbs]") end
file = ARGV.shift
nzb = File.read(file)
num = Integer(ARGV.shift) rescue usage
header, nzb = nzb.split(/(?=<file)/, 2)
files = nzb.scan(/<file.*?<\/file>/m)
View sort-timings.rb
#!/usr/bin/env ruby
times = ARGF
.each_line
.map { |line| /^.*\+([0-9]{10})\.([0-9]{6})[0-9]* (.{1,77})/.match(line) }
.select(&:itself)
.map { |md| [Integer(md[1] + md[2]), md[3]] }
.each_cons(2)
.map { |a, b| [b[0] - a[0], a[1]]}
.sort_by(&:first)
@Freaky
Freaky / Dockerfile
Last active Apr 7, 2019
tarssh Dockerfile
View Dockerfile
FROM rust:1.33-stretch as build
WORKDIR /usr/src/tarssh
# Make a blank project with our deps for Docker to cache.
# We skip rusty-sandbox because it does nothing useful on Linux.
COPY Cargo.toml Cargo.lock .
RUN mkdir -p src \
&& echo 'fn main() { }' >src/main.rs \
&& cargo build --release --no-default-features --features drop_privs
@Freaky
Freaky / tarssh.rs
Last active Mar 26, 2019
Rust ssh tarpit
View tarssh.rs
use std::env;
use std::net::SocketAddr;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::{Duration, Instant};
use exitcode;
use env_logger;
use log::{error, info, warn};
View fast-memchr.c
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#define MIN(a,b) (((a)<(b))?(a):(b))
#define LO ((uint64_t)0x0101010101010101L)
#define HI ((uint64_t)0x8080808080808080L)
#define LOOP_SIZE (2 * sizeof(uint64_t))
@Freaky
Freaky / readline-prefixed-junk.rb
Created Jan 2, 2019
Print crap before readline
View readline-prefixed-junk.rb
#!/usr/bin/env ruby
require 'readline'
run = true
puts
worker = Thread.new do
i = 0
while run
STDOUT.print("\e[s\r\e[A\e[KMoo moo baa #{i += 1}\n\e[u");
@Freaky
Freaky / vm_superhub.rb
Created Dec 28, 2018
Munin plugin for Virgin Media Superhub
View vm_superhub.rb
#!/usr/local/bin/ruby
Host = '192.168.100.1'
require 'net/http'
require 'timeout'
def get(page)
Timeout.timeout(5) { Net::HTTP.get(Host, page) }
rescue => e
STDERR.puts "GET http://#{Host}/#{page} failure: #{e.class}: #{e.message}"
@Freaky
Freaky / freebsd-update-progress.patch
Last active Dec 13, 2018
Patch to CURRENT freebsd-update to replace the 10....20....30.... progress indicator
View freebsd-update-progress.patch
--- freebsd-update.sh.orig 2018-12-13 16:28:44.343075728 +0000
+++ freebsd-update.sh 2018-12-13 16:44:41.440009430 +0000
@@ -1059,6 +1059,30 @@
# Print user-friendly progress statistics
fetch_progress () {
+ if [ "$1" -gt 0 -a -t 1 ]; then
+ fetch_progress_tty $1
+ else
+ fetch_progress_classic
@Freaky
Freaky / divebar.rb
Last active Dec 6, 2018
Start of yet another progress bar library?
View divebar.rb
# require "divebar/version"
module Divebar
Style = Struct.new(:name, :tick_chars, :progress_chars, :template)
module Styles
Default = Style.new(
"default",
"⠁⠁⠉⠙⠚⠒⠂⠂⠒⠲⠴⠤⠄⠄⠤⠠⠠⠤⠦⠖⠒⠐⠐⠒⠓⠋⠉⠈⠈ ".chars,
"█░".chars,
" %<bar>s %<spinner>s %<pos>d/%<len>d %<msg>s"
View iptest.rb
module IpTest
module V4
MAX_LEN = '255.255.255.255'.size
SEGMENT = /(?:25[0-5]|(?:2[0-4]|1?[0-9])?[0-9])/
PATTERN = /#{SEGMENT}\.#{SEGMENT}\.#{SEGMENT}\.#{SEGMENT}/
PATTERN_ANCHORED = /\A#{PATTERN}\z/
def self.contains?(str)
PATTERN.match?(str)
end
You can’t perform that action at this time.