Skip to content

Instantly share code, notes, and snippets.

kddnewton / json.rb
Last active August 7, 2023 19:54
Faster JSON parser in Ruby
View json.rb
# frozen_string_literal: true
require "bundler/inline"
gemfile do
source ""
gem "json_pure"
gem "benchmark-ips"
ssrihari /
Last active February 23, 2024 22:39
An opinionated list of excellent Clojure learning materials

An opinionated list of excellent Clojure learning materials

These resources (articles, books, and videos) are useful when you're starting to learn the language, or when you're learning a specific part of the language. This an opinionated list, no doubt. I've compiled this list from writing and teaching Clojure over the last 10 years.

  • 🔴 Mandatory (for both beginners and intermediates)
  • 🟩 For beginners
  • 🟨 For intermediates

Table of contents

  1. Getting into the language
View globals-debugger.js
* GlobalsDebugger
* Inspect the stack when a global variable is being set on the window object.
* Given a global variable name, it proxies the variable name in the window
* object adding some custom code that will be invoked whenever the variable
* is set. The custom code will log the current stack trace and halt the code
* execution to allow inspecting the stack and context in your browser DevTools.
* You can use the "globalsToInspect" query-parameter to set a comma-separated
* list of names of the variables you want to inspect.

Cheat sheet: modules

Named exports, named imports, namespace imports

If we put export in front of a named entity inside a module, it becomes a named export of that module. All other entities are private to the module.

//===== lib1.mjs =====
// Named exports
Kukunin / ractors.rb
Last active December 28, 2023 12:53
Ruby Ractors vs Threads benchmark
View ractors.rb
require 'benchmark'
require 'etc' { :warmup } if defined?(Ractor)
def fibonacci(n)
return n if (0..1).include? n
fibonacci(n - 1) + fibonacci(n - 2)
swanson / .irbrc
Last active January 18, 2024 12:24
.irbrc color coding Rails console by environment
View .irbrc
# Add color coding based on Rails environment for safety
if defined? Rails
banner = if Rails.env.production?
"\e[41;97;1m #{Rails.env} \e[0m "
"\e[42;97;1m #{Rails.env} \e[0m "
# Build a custom prompt

for-of, early termination, iterators, and generators

If we terminate a loop early, for-of invokes method .return() of the iterator. Generators return generator objects (that implement both the Iterable interface and the Iterator interface). If we invoke .return() on such an object, the generator is terminated. We can prevent that by overriding .return().

More information:


function logIter(iter) {
dhh / Gemfile
Created June 24, 2020 22:23
HEY's Gemfile
View Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
View .eslintrc.json
"env": {
"browser": true,
"es6": true
"extends": [
dmshvetsov / worker_and_queue_perfect_pair.rb
Created February 5, 2019 05:33
Example of how we may use queue with threads to make efficient background worker.
View worker_and_queue_perfect_pair.rb
class Worker
def self.start(num_threads:, queue_size:)
queue =
worker = new(num_threads: num_threads, queue: queue)
def initialize(num_threads:, queue:)
@num_threads = num_threads