Skip to content

Instantly share code, notes, and snippets.

@pch
pch / base32.rb
Last active October 28, 2024 14:01
Base32 encoding in Ruby (RFC 4648)
# Base32 (RFC 4648) implemented in Ruby
#
# Source: https://ptrchm.com/posts/base32-explained/
class Base32
ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567".split("")
PADDING_CHAR = "="
BITS_PER_BYTE = 8 # 1 byte = 8 bits
BITS_PER_CHAR = Math.log2(ALPHABET.length).round # 5 = 32 chars = 2^5 number of bits encoded into a single character in the ALPHABET
BITS_PER_CHUNK = BITS_PER_CHAR.lcm(BITS_PER_BYTE) # 40 (least common mutliple of 5 and 8)
@picandocodigo
picandocodigo / ruby-advent-calendar-enterprise-search.md
Last active December 2, 2020 12:49
Ruby Advent Calendar - elastic-enterprise-search

elastic-enterprise-search

This gem is the official Elastic Enterprise Search client and it's currently out as a beta release. Enterprise Search is an Elastic solution for search in the enterprise. It's powered by the Elastic Stack and Elasticsearch, so you get all the great things you already know in one package for your team. It's the umbrella solution which contains Workplace Search, App Search and Site Search. The client focuses on App Search and Workplace Search.

What is Elastic Workplace Search?

Workplace Search is a unified search solution for teams. One of the interesting things about Workplace Search to me is at previous jobs I wished I had a product like this. We had different documents and manuals on so many different services: wikis, Jira, email, Dropbox, Basecamp. Whenever you needed to find a specific document you had to find out where to look for it, and then search. Workplace gives you a single search experien

@inopinatus
inopinatus / uu58.rb
Last active October 11, 2023 20:21
Convert UUIDs to/from base58
module Uu58
# Convert a string UUID to a base58 string representation.
#
# Output will be padded up to 22 digits if necessary.
#
# Behaviour is undefined if passing something other than a 128-bit
# hex string in network order with optional interstitial hyphens.
def self.uuid_to_base58(uuid, alphabet = SecureRandom::BASE58_ALPHABET)
ary = uuid.delete("-").to_i(16).digits(58).reverse
ary.unshift(0) while ary.length < 22
require 'json'
COLORS = {
'#' => '#216e39',
'+' => '#30a14e',
':' => '#40c463',
'-' => '#9be9a8',
'.' => '#ebedf0',
' ' => nil,
}
@thedavecarroll
thedavecarroll / markdown.json
Created May 11, 2020 19:16
Markdown Snippet for Visual Studio Code
{
// insert markdown links
"Insert Link" : {
"prefix": "link",
"body": [
"[text][text]{:target=\"_blank\"}"
]
},
"Insert Reference" : {
"prefix": "ref",
@eugeneotto
eugeneotto / dapper.rb
Created May 31, 2019 23:09
Dapper / ERC-1271 wallet signature validation in Ruby
require 'web3/eth'
ERC_1271_MAGIC_VALUE = '1626ba7e'
ERC_1271_ABI = <<~JSON
[
{
"constant": true,
"inputs": [
{
"name": "hash",
@ww9
ww9 / public_domain_software.md
Last active February 6, 2024 03:42
Public Domain Software #blog

TLDR

Public Domain is not a license and isn't legally accepted in some countries. So if you want to give stuff for free, it's better to just license it under MIT or BSD.

Public Domain Software

The term “public domain” refers to creative materials that are not protected by intellectual property laws such as copyright, trademark, or patent laws. The public owns these works, not an individual author or artist. Anyone can use a public domain work without obtaining permission, but no one can ever own it. - Stanford University definition

Can Cannot
@thbar
thbar / _readme.md
Last active July 17, 2024 18:54
Using minitest to regression test your Jekyll static site

Using minitest to regression-test your Jekyll static site

I recently had to upgrade my blog, which involved changes such as:

  • Replacing a sitemap plugin
  • Upgrading from jekyll 2.5.3 to 3.8.4
  • Upgrading from jekyll-assets 0.7.8 to 3.0.11
  • (etc)

The upgrading process was not trivial, and some parts (e.g. RSS, sitemap, or twitter cards tags) are not immediately visible, so I decided to add unit tests on the generated content.

@muziejus
muziejus / Rakefile
Last active May 1, 2018 23:15
Jekyll Rakefile to generate tag pages without plugins for use in gh-pages sites.
# This is a ruby port of Long Qian's:
#
# https://github.com/qian256/qian256.github.io/blob/master/tag_generator.py
#
# which is a python script that accompanies this useful webpage on creating
# tags for Jekyll without plugins:
#
# http://longqian.me/2017/02/09/github-jekyll-tag/
#
# This Rakefile uses Jekyll's internals to generate the list, as opposed to