Skip to content

Instantly share code, notes, and snippets.

View dexterous's full-sized avatar

Saager Mhatre dexterous

View GitHub Profile
@dexterous
dexterous / procs.rb
Last active January 13, 2024 09:20
Ruby Procs, return & yield semantics
require 'rubygems'
require 'expectations'
Expectations do
expect(1){ proc { |a| a }.call(1) }
expect([1, 2]){ proc { |a| a }.call(1, 2) } #fails
expect(1){ proc { |a, b| a }.call(1, 2) }
expect(1){ Proc.new { |a| a }.call(1) }
@dexterous
dexterous / move_from_dead_letter.py
Last active January 13, 2024 09:14
Some people just don't get how to do concurrency/parallelism right. (sigh!)
import boto3
import sys
import Queue
import threading
work_queue = Queue.Queue()
sqs = boto3.resource('sqs')
from_q_name = sys.argv[1]
# CLOSURES IN RUBY Paul Cantrell https://innig.net
# Email: username "paul", domain name "innig.net"
# I recommend executing this file, then reading it alongside its output.
#
# Alteratively, you can give yourself an unreasonable Ruby test by deleting all
# the comments, then trying to guess the output of the code!
#
# (Naive HR departments, please do not use that idea as a hiring quiz.)
@dexterous
dexterous / vimium-options.json
Last active May 9, 2023 21:21
Tool Settings
{
"settingsVersion": "1.67.4",
"exclusionRules": [
{
"pattern": "https?://(mail|calendar|keep|photos|groups|drive|meet|chat|messages).google.com/*",
"passKeys": ""
},
{
"pattern": "https?://(mobile.)?twitter.com/*",
"passKeys": ""
(defn how-not-to-factorial [x]
(condp #(< %2 %1) x
1 (throw (IllegalArgumentException.))
3 x
(loop [acc (bigint x) prev (dec x)]
(if (= prev 2) (* acc 2) (recur (* acc prev) (dec prev))))))
;; when you want to factorial...
(defn just-factorial [n] (apply * (range 1N (inc n))))

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@dexterous
dexterous / original-rant.md
Last active September 23, 2022 01:37 — forked from kaiwren/gist:1283905
Steve Yegge's SOA post

Stevey's Google Platforms Rant

I was at Amazon for about six and a half years, and now I've been at Google for that long. One thing that struck me immediately about the two companies -- an impression that has been reinforced almost daily -- is that Amazon does everything wrong, and Google does everything right. Sure, it's a sweeping generalization, but a surprisingly accurate one. It's pretty crazy. There are probably a hundred or even two hundred different ways you can compare the two companies, and Google is superior in all but three of them, if I recall correctly. I actually did a spreadsheet at one point but Legal wouldn't let me show it to anyone, even though recruiting loved it.

I mean, just to give you a very brief taste: Amazon's recruiting process is fundamentally flawed by having teams hire for themselves, so their hiring bar is incredibly inconsistent across teams, despite various efforts they've made to level it out. And their operations are a mess; they don't really have SREs and they make en

@dexterous
dexterous / fight
Last active September 6, 2022 07:48
aws vs sed
#!/bin/bash
echo "Here's what we're parsing"
cat -T input
echo ''
echo "First, we try awk and then cut"
echo ''
set -o xtrace
@dexterous
dexterous / rotate.clj
Created August 31, 2022 06:21
Rotate a vector in Clojure
(defn rotate [v n]
(cond
(zero? n) v
(pos? n) (vec (concat (nthrest v n) (take n v)))
(neg? n) (rotate v (+ (count v) n))))
@dexterous
dexterous / concurrent_http.groovy
Last active January 20, 2022 00:27
Scriptlets to hit a URL n times, with upto m concurrent connections at a time.
import groovyx.gpars.GParsExecutorsPool
GParsExecutorsPool.withPool(3) {
(0..<10).eachParallel { worker ->
try {
println "attempting $worker"
def connection = 'http://httpbin.org/delay/2'.toURL().openConnection().tap { it.requestMethod = 'HEAD' }
println "$worker $connection.responseCode"
} catch(IOException x) {
println x