Skip to content

Instantly share code, notes, and snippets.

wisq / fix-filenames.exs
Last active Apr 9, 2020
Quick and dirty Elixir script to fix filenames with invalid unicode
View fix-filenames.exs
#! /usr/bin/env elixir
defmodule Fixer do
def parse_args(["-n" | args]), do: {false, args}
def parse_args(["-f" | args]), do: {true, args}
def parse_args(args), do: {false, args}
def fix_all({rename, files}) do
{:ok, stdout} ="/dev/stdout", [:write])
Process.register(stdout, :stdout_binary)
wisq /
Last active Jan 1, 2019
Fetch the winning game titles from the RPS Advent Calendar 2018
wget -nc -r --accept-regex='[0-9]+/the-rps-advent-calendar-2018-dec-[^/]+/$|[0-9]+/$'
echo "===================================="
find -name 'index.html' -print0 | sort -z | xargs -0 grep "</a>!</p>" | cut -d/ -f2-4,8- | sed "s#/www#>#g" | cut -d'>' -f1,3 | cut -d'<' -f1 | sed -e "s/>/: /" -e "s#/#-#g" -e "s/&#8217;/'/g"
echo "===================================="
View next.exs
defmodule StrNext do
@character_ranges [
{'A', 'Z'},
{'a', 'z'},
{'0', '9'}
@characters, fn {a, z} ->
|> Enum.to_list()
View test.exs
defmodule Benchmark do
defmacro __using__(_) do
quote do
import Benchmark
def measure(name, function) do
{usecs, retval} = function |>
IO.puts("#{name} took #{usecs} µs")
wisq / .git-hooks-pre-commit
Created Oct 4, 2017
Quick and dirty Elixir git pre-commit hook that ensures tests pass
View .git-hooks-pre-commit
exec 1>&2
MIX_ENV=test exec mix git.test
wisq / Rakefile
Created Oct 27, 2016
Basic Ruby+git test-before-commit workflow, testing only the changes being committed
View Rakefile
task(default: [:link_hooks, :test])
task :link_hooks do
sh 'ln', '-nsf', '../../hooks/pre-commit', '.git/hooks/pre-commit'
task :pre_commit do
require 'open3'
Dir.mktmpdir do |tmpdir|
View gist:394921c8f9f513a9e508a4a42f5ae17d
% ruby -rbcrypt -e '(1..100).each { |len| abort "max len is #{len}" if BCrypt::Password.create("a" * len) == "a" * (len+1) }'
max len is 72
zsh: exit 1 ruby -rbcrypt -e
ruby -rbcrypt -e 9.12s user 0.06s system 99% cpu 9.192 total
% ruby -rbcrypt -rpp -e 'pp (1..100).map { |len| goodpass = "a" * len; badpass = "a" * (len+1); pass = BCrypt::Password.create(goodpass); [len, pass == goodpass, pass == badpass] }'
[[1, true, false],
[2, true, false],
[3, true, false],
[4, true, false],

MGSV's online system

Why does online suck?

  • Whenever you connect online, it redistributes your resources between offline and online.
    • Generally, a small amount will remain offline and all the rest will go online.
  • If you spend stuff for online stuff, it comes out of your online resources.
  • If you spend stuff for regular (offline) stuff, it typically comes out of your offline resources.
    • This can leave you deeply in the negative if you're ever offline.
    • Being negative is very bad and can lead to staff leaving.
View rps-img-https.js
// ==UserScript==
// @name RPS mixed-content defuckifier
// @namespace rps-img-https
// @include*
// @version 1
// @grant none
// ==/UserScript==
var images = document.getElementsByTagName('img');
var length = images.length;
View drop-ssh-key.rb
#!/usr/bin/env ruby
require 'tempfile'
KNOWN_HOSTS = ENV['HOME'] + '/.ssh/known_hosts'
read_fh, write_fh = IO.pipe
command = ['ssh', '-oStrictHostKeyChecking=yes'] + ARGV + ['echo', 'Successful connection.']