Skip to content

Instantly share code, notes, and snippets.

@evaneykelen
evaneykelen / array_vs_set.rb
Created August 25, 2019 07:19
Array vs Set benchmark
require 'benchmark'
require 'set'
array = File.readlines('dutch.bin') # 10k lines
hash = Hash[*array] # 5k keys => 5k values
set = array.to_set # 10k entries
line = array[-1] # Last line
Benchmark.bmbm do |x|
x.report("Array.include?") { 10_000.times { array.include?(line)} }
@evaneykelen
evaneykelen / size_vs_count.rb
Last active August 25, 2019 07:26
`size` vs `count` benchmark
require 'benchmark'
array = File.readlines('dutch.bin') # 10k lines
hash = Hash[*array] # 5k keys => 5k values
Benchmark.bmbm do |x|
x.report {
x.report("Array count") { 10_000.times { array.count } }
x.report("Array size") { 10_000.times { array.size } }
x.report("Hash count") { 10_000.times { hash.count } }
require 'benchmark'
array = File.readlines('dutch.bin') # 10k lines
Benchmark.bmbm do |x|
x.report {
x.report("tr") { array.each { |line| line.tr('e', 'z') } }
}
end
@evaneykelen
evaneykelen / testcases.rb
Created May 25, 2019 12:41
Title casing test cases
TEST_CASES = [
[
"For step-by-step directions email someone@gmail.com",
"For Step-by-Step Directions Email someone@gmail.com"],
[
"2lmc Spool: 'Gruber on OmniFocus and Vapo(u)rware'",
"2lmc Spool: 'Gruber on OmniFocus and Vapo(u)rware'"],
[
"Have you read “The Lottery”?",
"Have You Read “The Lottery”?"],
@evaneykelen
evaneykelen / s3-policy.json
Last active June 13, 2020 05:06
aws policy
{
"Version": "2012-10-17",
"Id": "Policy154...",
"Statement": [
{
"Sid": "Stmt1542...",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::744...556:user/s3-user"
},
{
"Version": "2012-10-17",
"Id": "Policy154...",
"Statement": [
{
"Sid": "Stmt15420...",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::744...556:user/s3-user"
},
@evaneykelen
evaneykelen / sqs.rb
Last active June 13, 2020 05:05
sqs
require 'open3'
class Sqs
def self.process_messages
sqs = Aws::SQS::Client.new(region: ENV.fetch("AWS_REGION"),
access_key_id: ENV.fetch("AWS_ACCESS_KEY_ID"),
secret_access_key: ENV.fetch("AWS_SECRET_ACCESS_KEY"))
queue_url = sqs.get_queue_url(queue_name: ENV.fetch("AWS_SQS_QUEUE_NAME")).queue_url
poller = Aws::SQS::QueuePoller.new(queue_url, { client: sqs })

It's very easy to make some words bold and other words italic with Markdown. You can even link to Google!

Sometimes you want numbered lists:

  1. One
  2. Two
  3. Three

Sometimes you want bullet points:

@evaneykelen
evaneykelen / On remote software development.md
Last active March 30, 2019 09:25
On remote software development

unadjustednonraw_thumb_29

Around 2006 I started working with remote software development teams. In all but one case it has always been enjoyable, and successful from a business perspective.

I've worked with folks from Bolivia, Bulgaria, Costa Rica, Croatia, Estonia, France, Germany, Hong Kong, Hungary, Lithuania, Poland, Portugal, Spain, The Netherlands, UK, and US. The working language has been English in all cases.

To make remote working successful the first step is to hire relatively senior people. I don't mean senior in age per se, but in working experience, level of confidence in their abilities as a developer, experience in remote working, and grounded in terms of having settled in a city for a couple of years. It's OK if you don't tick all the boxes, but ticking just one is a sign you've perhaps not reached the necessary state of "balance" required to take on the responsibilities as a remote engine

@evaneykelen
evaneykelen / crr.md
Last active June 19, 2019 07:04
Colorize `rails routes` output and insert line breaks between controllers