Skip to content

Instantly share code, notes, and snippets.

@exegeteio
exegeteio / anagram.rb
Created July 31, 2023 17:30
Cassidoo Anagram Detector
#!/usr/bin/env ruby
def anagram?(subject, test)
(test.downcase.chars - subject.downcase.chars).none?
end
tests = {
'evil' => 'vile',
'a gentleman' => 'elegant man',
'Santa' => 'Satan',
@exegeteio
exegeteio / format.rb
Created May 4, 2023 22:41
SRT Formatter for Matty Twoshoes on twitch.
#!/usr/bin/env ruby
require "csv"
# Going to store each line into an array.
output = []
# Loop over input from STDIN
ARGF.each do |line|
# Removes newlines and such.
line.chomp!
@exegeteio
exegeteio / cass.rb
Created January 2, 2023 12:22
Cassidoo newsletter - 2023 - Week 0
# frozen_string_literal: true
def max_subarray(haystack, target_length)
cons = haystack.each_cons(target_length).to_a
sums = cons.collect(&:sum)
cons[sums.index(sums.max)]
end
puts max_subarray([-4, 2, -5, 1, 2, 3, 6, -5, 1], 4).inspect
puts max_subarray([1, 2, 0, 5], 2).inspect
@exegeteio
exegeteio / tailwind.js
Created October 18, 2022 01:45
Show all classes in Tailwind.
let els = document.querySelectorAll("body *[class]"); els.forEach((el) => { let el2 = document.createElement("span"); el2.innerText = el.classList.toString(); el2.style = "color: red;"; el.parentNode.prepend(el2); });
@exegeteio
exegeteio / example.rb
Created July 14, 2022 16:11
Eager loading after Active Record create?
user = User.create(email: 'whatever@nowhere', team_id: 123)
# ??? eager loading ???
# user.eager_load(team: {memberships: :admins}) # Maybe?
# user.reload(includes: {team: {memberships: :admins}}) # Adds an extra fetch.
# N+1 on `memberships` and `admins`.
notify_emails = user.team.memberships.admins.collect(:email)
@exegeteio
exegeteio / whatever.js
Last active February 4, 2022 20:57
Extract Emotes from twitch chat.
// type the part of the emote you want into your chat in Twitch.
// For example: :hype
// Then paste this into your browser's developer console.
// Will yield all of the hype emotes you've gotten on Twitch.
// Beware pasting them that there is a 500 character limit per chat.
a = []; document.querySelectorAll('.chat-input-tray__open .jrwvz').forEach((i, idx, array) => {a.push(i.title)}); console.log(a.join(' '));
@exegeteio
exegeteio / .dockerignore
Created July 24, 2021 14:36
Personal Rails Docker Setup
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'
# Ignore bundler config.
/.bundle
# Ignore the default SQLite database.
@exegeteio
exegeteio / Dockerfile
Last active April 11, 2021 20:31
rwxrob
FROM rwxrob/base
RUN touch ~/found
@exegeteio
exegeteio / number-two.css
Last active March 1, 2021 03:02
Custom CSS for 2.exegete.io.
body {
background-color: green;
color: white;
}
@exegeteio
exegeteio / Dockerfile
Created December 1, 2020 17:56
Jekyll Dockerfile with intermediate containers, deploying with nginx.
FROM ruby:2.6 AS jekyll
WORKDIR /usr/src/app
COPY Gemfile Gemfile.lock /usr/src/app/
RUN bundle install --quiet -j 4
COPY . /usr/src/app/
EXPOSE 3000
CMD jekyll server -P 3000 -H 0.0.0.0 -w --force_polling --incremental
FROM jekyll AS website
ENV JEKYLL_ENV=production