Skip to content

Instantly share code, notes, and snippets.

from enum import Enum
from typing import NoReturn
class Color(Enum):
RED = "RED"
GREEN = "GREEN"
BLUE = "BLUE" # I just added this
@dogweather
dogweather / memoization-example.rb
Created October 2, 2022 07:06
Example of memoization in Ruby on Rails
class Jurisdiction < ApplicationRecord
# ...
class << self
memoize def find_via(slug:)
Jurisdiction.find_by(slug: slug)
end
end
end
@dogweather
dogweather / string_ops.rkt
Last active September 1, 2022 01:59
Racket implementation of string operations
#lang racket
(define (clean-up s)
(first (split-into-sentences (fix-hyphenation (fix-whitespace s)))))
(define (fix-whitespace s)
(string-replace s "\n" " "))
(define (fix-hyphenation s)
(string-replace s "- " ""))
return (1..5)
.map{|n| "car-#{n}"}
.select{|m| car_is_empty(m)}
let car_ids = [];
for (let i = 1; i <= 5; i++) {
const car_id = `car-${i}`;
if (car_is_empty(car_id)) {
car_ids.push(car_id);
}
}
return car_ids;
class AttributeWriter {
constructor(cf_object) {
this.cf_object = cf_object;
}
async element(element) {
const data = this.cf_object;
// Is the visitor in the VIP list?
const visitor_asn = data.asn
################################################
# Each Article has a title and a number.
# But three of them are very difficult to parse.
################################################
# Map Article titles to corrected numbers.
EXCEPTIONS = {
"Elements of Crimes": "9",
"Ne bis in idem": "20",
"Individual criminal responsibility": "25"
@dogweather
dogweather / .gitignore
Created March 29, 2022 03:49 — forked from SunDi3yansyah/.gitignore
Generate Static HTML Website Using Ruby on Rails
# Ignore static version of the site (used to upload error pages to S3 for Heroku errors)
/out
@dogweather
dogweather / apple-annoyances.md
Last active January 10, 2022 08:38
Apple Annoyances (MacOS, iOS, iCloud)

Apple Annoyances

Last updated: 2021-02-10

MacOS

  • The bottom right corner of apps are no longer accessible because a new Notes feature uses it.
@dogweather
dogweather / breadcrumbs.rb
Created September 4, 2020 01:44
Breadcrumbs, OO version
# typed: false
# frozen_string_literal: true
require 'json'
module PublicLaw
# Represents a breadcrumb trail on a page.
class Breadcrumbs
include ActionView::Helpers
extend T::Sig