Skip to content

Instantly share code, notes, and snippets.

@bestie
bestie / racknroll.ru
Created Jul 5, 2021
A Rack app for rick rollin'
View racknroll.ru
body = <<~HTML
<html>
<body>
<div class="tenor-gif-embed" data-postid="12136175" data-share-method="host" data-width="100%" data-aspect-ratio="1.4777448071216617"><a href="https://tenor.com/view/rick-ashley-dance-80s-music-gif-12136175">Rick Ashley Dance GIF</a> from <a href="https://tenor.com/search/rickashley-gifs">Rickashley GIFs</a></div><script type="text/javascript" async src="https://tenor.com/embed.js"></script>
</body>
</html>
HTML
app = ->(env) {
[
@bestie
bestie / 1_udp_listener.rb
Last active Sep 25, 2019
Help me fix this Rust UDP problem :)
View 1_udp_listener.rb
require "socket"
rx_port = 2222
tx_port = 2223
host = "localhost"
socket = UDPSocket.new
socket.bind(host, rx_port)
socket.connect(host, tx_port)
View prison_break.rb
# Run this script with the ENV var payload.
# Payload will be executed as part of your request to visit a prisoner.
# The goal is to free a prison in as few characters as possible.
module PrisonBreak
class Visit
attr_accessor :free_prisoner
attr_reader :prison, :payload
View keybase.md

Keybase proof

I hereby claim:

  • I am bestie on github.
  • I am bestie (https://keybase.io/bestie) on keybase.
  • I have a public key ASAU_62OgyyQ6IpGAlmQkLNK-JwXmslWMiOAueQy95ieOgo

To claim this, I am signing this object:

@bestie
bestie / password_gen.rb
Last active Jan 19, 2018
Memorable, secure password generator in one file. XKCD style, includes 1765 common words.
View password_gen.rb
#!/usr/bin/env ruby
require "optparse"
options = {
:n_passwords => 1,
:password_length => 4,
:separator => " ",
}
@bestie
bestie / wat_gems.rb
Created Nov 28, 2017
Parse the Gemfile.lock file and print the list of Gems that Bundler would install
View wat_gems.rb
require "bundler"
bundle = Bundler::LockfileParser.new(Bundler.read_file(Bundler.default_lockfile))
gem_name_version_map = bundle.specs.map { |spec|
[
spec.name,
spec.version.to_s,
]
}
@bestie
bestie / count_colors.rb
Created Jun 15, 2016
Imperative `Hash.new` vs functional
View count_colors.rb
# Task: Count how many users have each favorite color
User = Struct.new(:id, :favorite_color)
colors = [:red, :green, :blue, :hot_pink]
users = 10.times.map { |n| User.new(n, colors.sample) }
# The follow two example print the same result
@bestie
bestie / tsort_spec.rb
Last active Mar 29, 2016
A topological sort head scratcher
View tsort_spec.rb
# Ah it's OK I got this one myself. It's pretty late at night but I get it now!
# I'll leave this here in case anyone is interested. I've added the
# explaination below
# This is some code I wrote as excercise after watching
# https://youtu.be/QnWDU1wcsPA?t=470
#
# The first example mimics the result from the video and is there just to
# verify my use of the TSort module is correct.
View date_range_filter.rb
class DateRangeFilter
def self.to_proc
->(constraint, events) { new(constraint, events).call }.to_proc
end
def initialize(constraint, events)
@constraint = constraint
@events = events
end
View refactor_towards_hexagonal_rails.rb
class ApplicationController
private
def core_application
CoreApplication.new
end
def adapter
RailsAdapter.new(self)
end