Skip to content

Instantly share code, notes, and snippets.

@stevenkaras
stevenkaras / disjoint-words.py
Last active August 7, 2022 20:51
Wordle DIsjoint Set
# /usr/bin/env python
# The point of this exercise is to find a list of 5 words with 25 unique letters across them.
# As suggested by https://www.youtube.com/watch?v=_-AfhLQfb6w
#
# This problem is equivalent to searching for a disjoint set in the graph induced on shared letters between words.
# That problem is equivalent to searching for a clique in the inverse graph.
# The approach used here builds the graph as edges first between letters, then between words.
# Each step increases the cliques it found by 1 word.
#
@stevenkaras
stevenkaras / .profile
Last active July 10, 2022 19:52
asdf POSIX bootstrap
case "$SHELL" in
*fish)
[ -f "$HOME/.asdf/asdf.fish" ] && . "$HOME/.asdf/asdf.fish"
;;
*zsh)
[ -f "$HOME/.asdf/asdf.sh" ] && . "$HOME/.asdf/asdf.sh"
;;
*bash)
if [ "${BASH:-no}" != no ]; then
[ -f "$HOME/.asdf/asdf.sh" ] && . "$HOME/.asdf/asdf.sh"
@stevenkaras
stevenkaras / keybase.md
Created October 2, 2015 11:34
Keybase identity proof

Keybase proof

I hereby claim:

  • I am stevenkaras on github.
  • I am stevenkaras (https://keybase.io/stevenkaras) on keybase.
  • I have a public key whose fingerprint is E751 0CE5 AFA6 EC89 3B84 74BE 65A0 9530 C7A4 9BD2

To claim this, I am signing this object:

@stevenkaras
stevenkaras / manacher.rb
Created September 15, 2015 16:09
Manacher's Algorithm for finding palindromic sequences in Ruby
# Detect all the palindromic sequences in a given string
#
# @return [<Range>] a list of all the palindromes in the given string
def all_palindromes(string)
preprocessed = "^#{string.chars.join("#")}$"
palindromes = [0] * preprocessed.length
center = 0
right = 0
for i in 1...preprocessed.length
mirror = center * 2 - i
@stevenkaras
stevenkaras / routing_bug.rb
Last active August 29, 2015 14:27
Rails bug when routing escaped entities
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
# Activate the gem you are reporting the issue against.
@stevenkaras
stevenkaras / run_services.bash
Last active October 12, 2015 10:38
Local service instrumentation
#!/usr/bin/env bash
# This script runs services in the background, logs their output, and spins them down gently
#
# I use it in development, since I don't want to have databases and message brokers running
# all the time on my laptop.
#
# Reads a list of services either from ARGV or from a ".services" file
# Alternatively, can take a list of services (from either source) in label=command format
@stevenkaras
stevenkaras / migrate.rb
Created January 19, 2015 18:05
Rails Migration/Copy/Merge Tool
# migrate.rb Migration/Copying/Merging Tool
# By Steven Karas
# MIT License
require 'csv'
require 'logger'
class Migration
def initialize(path, logger = Logger.new(nil))
@path = path
@stevenkaras
stevenkaras / email_validator.rb
Last active August 29, 2015 14:07
Email Validation class
require 'resolv'
require 'net/smtp'
class EmailValidator
# Note that obsolete syntax support has been stripped
Pattern = %r{
# From RFC 5322 s 3.2.1
(?<quoted-pair> \\ [\x21-\x7e \t]){0}
# From RFC 5322 s 3.2.3
# Copyright Steven Karas 2013 - 2014
# Licensed under MIT terms
# Represents a robots.txt file
class Robots
# Parse the given content as a robots.txt file
#
# @see http://www.robotstxt.org/
def initialize(content)
@stevenkaras
stevenkaras / url_helpers_env.rb
Last active August 29, 2015 14:00
Environment variable based URL helper
class URLHelpers::Env
include ActionController::UrlFor
include Sprockets::Rails::Helper
include Rails.application.routes.url_helpers
def self.config
Rails.application.config
end
def self.app