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 / string_ops.py
Last active October 3, 2022 21:39
Python implementation of five string operations
from typing import Generator
def clean_up(s: str) -> str:
return next(split_into_sentences(fix_hyphenation(fix_whitespace(s))))
def fix_whitespace(s: str) -> str:
return s.replace("\n", " ")
def fix_hyphenation(s: str) -> str:
@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 "- " ""))
@dogweather
dogweather / string_ops.ex
Last active August 30, 2022 06:21
Elixir implementation of five string operations
import String
defmodule StringOps do
def clean_up(title) do
title
|> fixWhitespace
|> fixHyphenation
|> splitIntoSentences
|> List.first
end
@dogweather
dogweather / string_ops.rb
Last active August 30, 2022 06:20
Ruby implementation of five string operations
module StringOps
module_function
def clean_up(summary:)
split_into_sentences(fix_hyphenation(fix_whitespace(summary))).first
end
def fix_whitespace(a_string)
a_string.gsub "\n", " "
end
@dogweather
dogweather / string_ops.swift
Last active August 30, 2022 06:19
Swift implementation of five string operations
func cleanUp(s: String) -> String {
return splitIntoSentences(summary: fixHyphenation(s: fixWhitespace(s: s)))[0]
}
func fixHyphenation(s: String) -> String {
return s.replacingOccurrences(of: "- ", with: "")
}
func fixWhitespace(s: String) -> String {
return s.replacingOccurrences(of: "\n", with: " ")
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;
@dogweather
dogweather / Dockerfile
Last active June 6, 2022 11:56
Elixir/Phoenix Docker-based Development Environment
# Elixir + Phoenix
FROM elixir:1.6.1
# Install debian packages
RUN apt-get update
RUN apt-get install --yes build-essential inotify-tools postgresql-client
# Install Phoenix packages
RUN mix local.hex --force