Skip to content

Instantly share code, notes, and snippets.

View Freaky's full-sized avatar

Thomas Hurst Freaky

View GitHub Profile
@Freaky
Freaky / freebsd-update-progress.patch
Last active December 13, 2018 16:46
Patch to CURRENT freebsd-update to replace the 10....20....30.... progress indicator
--- 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 December 6, 2018 16:32
Start of yet another progress bar library?
# 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"
@Freaky
Freaky / iptest.rb
Last active November 6, 2018 23:57
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
@Freaky
Freaky / email_sucks_completely.rs
Created September 3, 2018 01:37
Quick and dirty email search index test thing that sucks completely
/// Email Sucks Completely / Email Search Command
extern crate mailparse;
extern crate tantivy;
extern crate walkdir;
use mailparse::*;
use tantivy::collector::TopCollector;
use tantivy::query::QueryParser;
#!/usr/bin/env ruby
# frozen_string_literal: true
require_relative 'ragios'
Listener = Struct.new(:user, :command, :pid, :fd, :proto, :local_addr, :foreign_addr) do
def to_s
"#{user}/#{command} (#{pid}) on #{local_addr}"
end
end
@Freaky
Freaky / result.rb
Created August 25, 2018 20:36
Rust-style Result in Ruby
module Rustish
module Result
ResultMisuse = Class.new(StandardError)
FailedUnwrap = Class.new(ResultMisuse)
ExpectationFailed = Class.new(ResultMisuse)
Empty = Object.new
module InstanceMethods
@Freaky
Freaky / patch-stat.c.diff
Last active August 10, 2018 00:51
22 seconds -> 8.5 seconds running stat on /usr/src, 24 -> 5.6 seconds on a large Maildir
Index: stat.c
===================================================================
--- stat.c (revision 336221)
+++ stat.c (working copy)
@@ -202,6 +202,30 @@
(*nl) = ((c) == '\n'); \
} while (0/*CONSTCOND*/)
+static struct passwd *
+cached_getpwuid(uid_t uid)
# unmodfile.rb: Unpack a Starshatter data file
require 'zlib'
require 'ftools'
Header = Struct.new(:magic, :file_count, :index_size, :super_secret_drm_key, :index_offset)
Entry = Struct.new(:filename, :size_unpacked, :size, :offset)
File.open(ARGV[0] || 'shatter.dat', 'rb') do |f|
hdr = Header.new(*f.read(20).unpack("i5"))
f.pos = 20 + hdr.index_offset
#!/usr/bin/env ruby
# pv -cN Input pwned-passwords-2.0.txt | cut -b 1-32 | sort -S 8G | xxd -r -p | pv -cN Output >pwned-passwords-2.0.trunc.bin
require 'digest/sha1'
def interposearch(io, key)
rs = key.size
lo = 0
hi = (io.size / rs) - 1
#!/usr/bin/env ruby
require 'digest/sha1'
# search a file of "<sha1><crlf>"
def sha1_binsearch(io, target, linesize = 42, hashsize=40)
low, high = 0, (io.size / linesize) - 1
while low <= high
mid = (low + high) / 2