Skip to content

Instantly share code, notes, and snippets.

View masukomi's full-sized avatar

masukomi (a.k.a. Kay Rhodes) masukomi

View GitHub Profile
@masukomi
masukomi / recursive_zip_example.rb
Last active August 30, 2023 16:21
[ruby] how to recursively process a zip file containing zip files in memory
#!/usr/bin/env ruby
# Note this doesn't deal with directories in zip files.
# That's documented elsewhere. The recursive processing of
# zip files in zip files was the tricky bit.
require 'zip'
def recursive_zip_reader(input)
if input.is_a? String
zip_file = Zip::File.open(input)
@masukomi
masukomi / readable_ruby_docs_tampermonkey.js
Last active August 24, 2023 13:50
tampermonkey script to make ruby docs more readable. The min-width of documentation may be a bit too much, but it's a good starting point for you to tweak. ;)
// ==UserScript==
// @name Readable Ruby Docs
// @namespace https://masukomi.org/
// @version 0.1
// @description make the core description text wider
// @author You
// @match https://ruby-doc.org/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=ruby-doc.org
// @grant GM_addStyle
// @sandbox raw

Apple distributes their "add to wallet" images as SVGs which is great, but if you want to add it to an email or anything else that has issues with SVG files you're going to need a PNG (to maintain transparency around the rounded corners). Unfortunately there are a LOT of these images needed to support the various languages.

Converting these to PNGs is not as easy as you'd hope. Problems encountered:

  1. imagemagic produces unusably bad images (mostly just black) even though it's theoretically calling rsvg-convert under the covers and calling that directly works fine.
@masukomi
masukomi / elk_right_sidebar_userscript.js
Created January 31, 2023 16:12
remove the right sidebar and enbiggen body text in elk
/*
Elk.zone (v0.6.2) has a wide empty right sidebar which serves no purpose.
In addition to being a useless waste of space, it's an accessibility
issue for folks who need larger fonts, because it gives us less area
for the real content.
This gets rid of that sidebar, and expands the main content.
*/
// ==UserScript==
@masukomi
masukomi / example_activejob.rb
Created January 11, 2023 15:12 — forked from ChuckJHardy/example_activejob.rb
Example ActiveJob with RSpec Tests
class MyJob < ActiveJob::Base
queue_as :urgent
rescue_from(NoResultsError) do
retry_job wait: 5.minutes, queue: :default
end
def perform(*args)
MyService.call(*args)
end
@masukomi
masukomi / ssl_puma.sh
Last active November 12, 2021 22:08 — forked from defong/ssl_puma.sh
[RoR] localhost SSL with puma
# 1) Create your private key (any password will do, we remove it below)
$ cd ~/.ssh
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@masukomi
masukomi / doom.md
Created September 21, 2020 16:07 — forked from anhedonix/doom.md
Doom Emacs Cheatsheet

Doom Emacs Default keybindings cheetsheet

SPC

  • SPC find file
  • , switch bufferA
  • . browse files
  • : MX
  • ; EX
  • &lt; switch buffer
#lang sicp
; A collection of functions
; that can be added to your functions
; to have them produce graphviz dot notation
; as they're run.
;
; ;-------------
; ; Usage inside functions to be graphed
;
@masukomi
masukomi / fizzbuzz.py
Last active May 23, 2022 23:55 — forked from Gorcenski/fizzbuzz.py
The most obnoxious solution to FizzBuzz I can imagine.
# Emily Gorcensky's "obnoxious" fizz-buzz (less-compact version) annotated for non-python geeks.
# Explanation via Twitter: https://twitter.com/EmilyGorcenski/status/1228407309656903680?s=20
# If you want to dive into the meanings of how it works: it models fizzbuzz by
# computing the isomorphism of the finite cyclic groups of the values of the
# fizzes and buzzes and whatnot.
#
# These abelian groups are mapped to the unit circle in the complex plane and
# Represented as roots of unity. Such a interpetation has a polynomial
# representation. Therefore, the cartesian product in the isomorphism is
# represented as polynomial multiplication. The coefficients of a Polynomial
@masukomi
masukomi / array.rb
Last active May 10, 2019 15:49
an implementation of ruby's Flatten ... in ruby
class Array
# Performs the same function as
# flatten, only slower (because it's in Ruby
# and .flatten is implemented in C)
def slow_flatten(arr = self, result = [])
if arr.size > 0
first = arr.first
if ! arr.first.is_a? Array
result.push(first)
else