Skip to content

Instantly share code, notes, and snippets.

View rtweeks's full-sized avatar

Richard T. Weeks rtweeks

View GitHub Profile
@rtweeks
rtweeks / js_parser_generator.rb
Created May 1, 2022 14:36
FairCG JS character classification helper
class CharClassData
def initialize(char_classes)
@switch_points = []
@result_ccs = []
prev_cc = nil
max_ch = char_classes.flatten.max + 1
(0..max_ch).each do |ch|
next if prev_cc && char_classes[prev_cc].include?(ch)
@rtweeks
rtweeks / gist:26f36f4667fdd40d33852c672971dcad
Created October 20, 2021 04:34
Get a Python iterator that tests as false if empty
# This work is dedicated to the public domain or, in any case where copyright may not be relinquished, offered under an MIT License
def _falsey_on_empty(iterable: Iterable[T]) -> Iterable[T]:
"""Return an iterable that is falsey if empty, but always yields the same elements
:returns:
``()`` if *iterable* is empty, otherwise an iterable over the same
values
Iterable values cannot be generally relied on to return ``False`` when
( echo '--- |'; uptime; sensors; echo '--- |'; ps axjf ) | tee hw-report.txt
@rtweeks
rtweeks / yaml_testing.rb
Created January 20, 2018 21:59
Testing YAML Scalar Literal Roundtrips in Ruby
require 'psych'
# Construct one of these, use #find_problem!; if not nil, then use #apply_fix and repeat
class ScalarLiteralTester
class MethodInvocation
def initialize(name, args, block)
@name = name
@args = args
@block = block
end
@rtweeks
rtweeks / gist:8249ba86594ba13b63852d2d2a39622e
Last active September 27, 2020 01:03
Timestamp Proofs
The Oro Programming Language (commit 537b5df): sha256 211667824c1f60b1c9353c1dcea666cefb7786da3c834ab1db680d19176884c5
The Cadmus compiler: sha1 f6e4d6ebdca5cd03adc590f7ebb25b0e92c678a8
xscreensaver: sha1 b2ce7b8a96752a5eae88d2a4dba7df2ffd81dc2f
@rtweeks
rtweeks / build-setup.bat
Created August 3, 2015 22:01
Build setup using Ruby 2.2, 7-Zip, and Visual Studio
@echo off
echo Adding Ruby and 7-Zip to PATH...
set PATH=%PATH%;C:\Ruby22-x64\bin;C:\Program Files\7-Zip
echo Setting up Visual Studio 12.0 (2013) Command Prompt...
call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\vsvars32.bat"
echo Changing to user home directory...
%HOMEDRIVE%
@rtweeks
rtweeks / mssql-eyewkas.sql
Last active February 26, 2018 07:29
MSSQL Database structure extractor
-- Everything You Ever Wanted to Know About the Structure (returned as XML)
SET NOCOUNT ON;
DECLARE @VersionString AS NVARCHAR(100);
DECLARE @ver AS tinyint;
SET @VersionString = CAST(SERVERPROPERTY('productversion') AS NVARCHAR(100));
SET @ver = CAST(LEFT(@VersionString, CHARINDEX(N'.', @VersionString) - 1) AS tinyint);
DECLARE @EventGroups AS TABLE (
@rtweeks
rtweeks / vb6-sanity.rb
Last active December 4, 2015 18:46
Reformat Visual Basic 6 (VB6) code to use consistent indentation and line widths.
#!/usr/bin/env ruby
# The MIT License (MIT)
#
# Copyright (c) 2014 Richard T. Weeks
#
# 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