Skip to content

Instantly share code, notes, and snippets.

View awolfson's full-sized avatar

Aaron Wolfson awolfson

View GitHub Profile
@carlzulauf
carlzulauf / console_saver.rb
Created March 22, 2022 19:59
A pry session that remembers
#!/usr/bin/env ruby
# Console script with saved data serialized into script body at bottom
#
# `Console#db` is serialized via YAML whenever the `save` method is called
# * YAML is placed after special `__END__` keyword
# * Script can access data after `__END__` via `DATA` constant
# Useful as a skeleton for one-off console scripts needing limited data storage

When giving a block to a method, I think of it as sending a special proc argument.

You can send regular positional arguments, or kwargs, and you can also send 1 special proc argument.

When you use the literal syntax:

some_method { |x| x.to_s }

it's called a block, though it's really just a special syntax for a proc (special syntax in that it ends up having an elevated status in the method body (see yield)).

@JoshCheek
JoshCheek / abandon_all_hope_ye_who_enter_here.md
Last active May 30, 2019 06:20
Evil Ruby: Turning procs into first class functions
  • To read the original tweet and comments, click here.
  • For my followup abomination, click here
  • If you're thinking about treating this as anything other than art, read there 👇

DISCLAIMER:

THIS IS ART, DON'T ACTUALLY DO THIS IN ANY CODE THAT YOU CARE ABOUT!

☠️ This is not a place of honor ☠️ >

@nateberkopec
nateberkopec / correction.md
Last active June 6, 2025 19:24
A Simple Correction

In yesterday's post I said, in relation to "how does .present? work on ActiveRecord::Relation", I said that present? performs an existence check SELECT 1 AS one FROM ... LIMIT 1 because it calls exists? underneath. This is actually wrong - it loads the relation.

Jonathan Mast corrected me on Twitter. It turns out, I should have paid closer attention! Here is the actual implementation of blank? on ActiveRecord::Relation on Rails master:

# Returns true if relation is blank.
def blank?
  records.blank?
end
@carlzulauf
carlzulauf / .tmux.conf
Last active May 19, 2017 16:09
Tmux Config and Startup Script
# definitely DON'T use Ctrl+b. lame.
unbind C-b
# I never use the Insert key on the console, but it is a bit of a stretch
# set -g prefix IC
# ` is a cool prefix
set -g prefix `
set -g default-terminal "screen-256color"
@baweaver
baweaver / rails_booklist.md
Last active September 15, 2022 17:53
Rails Booklist

Rails Book List

A list of Rails books and their applications. Free books are tagged with (F)

Have a suggestion? Leave a comment. There are still books I need to read on the subject so some may not show up in this list yet.

Learning Rails

Your first steps into Rails

@sunny
sunny / enumerator_lazy_compact_extension.rb
Last active September 7, 2019 16:16
Adds #compact to Lazy Enumerators in Ruby
class Enumerator::Lazy
def compact
reject(&:nil?)
end
end
@alassek
alassek / 01_Annotated_Source.md
Last active November 19, 2023 11:53
Extending Arel to support @> operator

I've been doing some work lately with JSON documents in PostgreSQL using jsonb columns. You can query these documents using a GIN index in PG, but the syntax can be a little cumbersome

SELECT "events".* FROM "events" WHERE "events"."body" @> '{"shift":{"user_id":2}}'

You have to construct the right side of the query as a JSON string, which is a bit annoying. So I wondered if I could adapt Arel to do the tedious stuff for me.

@wesbos
wesbos / tab-trigger.js
Created November 16, 2015 19:33
How to properly get a TAB trigger working with Emmet inside of JSX
{
"keys": ["tab"],
"command": "expand_abbreviation_by_tab",
// put comma-separated syntax selectors for which
// you want to expandEmmet abbreviations into "operand" key
// instead of SCOPE_SELECTOR.
// Examples: source.js, text.html - source
"context": [
{
@jhannah
jhannah / git_flux.md
Last active December 15, 2022 18:35
git flux