Skip to content

Instantly share code, notes, and snippets.

View jaynetics's full-sized avatar

Janosch Müller jaynetics

View GitHub Profile
@jaynetics
jaynetics / progress.rb
Created September 29, 2016 13:16
print a progress animation in the style of the heroku cli
a = %w(⣾ ⣽ ⣻ ⢿ ⡿ ⣟ ⣯ ⣷)
loop { print a.rotate!.first; sleep 0.08; print "\b" }
@jaynetics
jaynetics / tarnum.rb
Created March 26, 2018 07:40
script to switch out heroes chronicles data (tarnum graphics) in a homm 3 installation
#!/usr/bin/env ruby
FILES = %w[
HPL003sh.pcx
HPL004sh.pcx
HPL006kn.pcx
hpl007sh.pcx
HPL102br.pcx
hpl112bs.pcx
HPS003sh.pcx

Changes to regexp_parser unicode property token names

old pattern new pattern old example new example
*_any * number_any number
*_cp *_code_point non_character_cp noncharacter_code_point
age_*_* age=*.* age_6_0 age=6.0
ascii_hex ascii_hex_digit ascii_hex ascii_hex_digit
block_in* in_* block_inadlam in_adlam
ids_*_op ids_*_operator ids_binary_op ids_binary_operator
@jaynetics
jaynetics / build_step.sh
Created May 29, 2018 11:02
use new / custom ruby version on semaphore
export RUBY_VERSION=2.5.1; cd ~/.rbenv/plugins/ruby-build && git pull && cd $SEMAPHORE_PROJECT_DIR; rbenv install $RUBY_VERSION; rbenv local $RUBY_VERSION; gem install bundler --no-ri --no-rdoc
@jaynetics
jaynetics / debug_googlebot.js
Created March 6, 2019 10:49
debug googlebot
<script>
if (window && window.navigator && /googlebot/i.test(window.navigator.userAgent)) {
var debug = function(key, value) {
var writeToBody = function() { document.body.setAttribute('data-' + key, value); };
if (document.body) writeToBody();
else window.addEventListener('DOMContentLoaded', writeToBody, false);
};
debug('googlebot', '1');
require 'stringex'
require 'sexy_slug'
require 'benchmark'
string = (0..0xD799).map { |cp| cp.chr('utf-8') }.join
Benchmark.bmbm do |x|
x.report { string.to_url }
x.report { SexySlug.from(string) }
end
@jaynetics
jaynetics / subarray_combinations.rb
Created April 29, 2019 09:59
subarray / 2d-array / cross-array combinations in ruby
# subarray_combinations([['a', 'b'], [1, 2]])
# # => [['a', 1], ['a', 2], ['b', 1], ['b', 2]]
def subarray_combinations(array_of_arrays, index = 0)
return [] if index == array_of_arrays.size
subarray = array_of_arrays[index]
tails = subarray_combinations(array_of_arrays, index + 1)
if tails.empty?
@jaynetics
jaynetics / scanner.rb
Created December 25, 2020 20:24
regexp_parser scanner.rb example (compiled from scanner.rl)
# -*- warn-indent:false; -*-
# line 1 "~/code/regexp_parser/lib/regexp_parser/scanner/scanner.rl"
# line 700 "~/code/regexp_parser/lib/regexp_parser/scanner/scanner.rl"
# THIS IS A GENERATED FILE, DO NOT EDIT DIRECTLY
# This file was generated from lib/regexp_parser/scanner/scanner.rl
@jaynetics
jaynetics / swap_credentials
Created November 29, 2021 11:06
Script to swap between two rubygems credentials files
#!/usr/bin/env ruby
# put in credentials dir, e.g. ~/.local/share/gem/swap_credentials
require 'fileutils'
active_path = "#{__dir__}/credentials"
memo_path = "#{__dir__}/memo"
current = File.exist?(memo_path) && File.read(memo_path)
Dir["#{__dir__}/credentials_*"].each do |cred_path|