Skip to content

Instantly share code, notes, and snippets.

View JeffCohen's full-sized avatar

Jeff Cohen JeffCohen

View GitHub Profile
@JeffCohen
JeffCohen / pluck.rb
Created March 24, 2019 16:47
Pluck values from a Ruby array of hashes, like ActiveRecord#pluck
class Array
def pluck(*args)
self.map { |item| args.map { |arg| item[arg] || item[arg.to_sym] || item[arg.to_s]}.flatten }
end
end
# Example:
# data = [ { "name" => "Cookie Monster", "color" => "blue", "id" => "1" },
# { "name" => "Kermit the Frog", "color" => "green", "id" => "2" }
# { "name" => "Big Bird", "color" => "blue", "id" => "3" }
@JeffCohen
JeffCohen / ruby-build.20220923165340.2544.log
Created September 24, 2022 21:14
Ubuntu 22.04.1 rbenv failure log when installing 3.1.2
/tmp/ruby-build.20220923165340.2544.hqIt35 ~
/tmp/ruby-build.20220923165340.2544.hqIt35/ruby-3.1.2 /tmp/ruby-build.20220923165340.2544.hqIt35 ~
checking for ruby... /home/deploy/.rbenv/shims/ruby
tool/config.guess already exists
tool/config.sub already exists
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for gcc... gcc
checking for ld... ld
@JeffCohen
JeffCohen / gist:3958673
Created October 26, 2012 13:03
reset.css
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
@JeffCohen
JeffCohen / gist:2790389
Created May 25, 2012 20:26
Vending Machine Script
# Vending Project
# Task 1 - Write a vending machine script that will dispence cokes until inventory is 0.
# Task 2 - Try adding the ability to keep track of capacity per brand
class VendingMachine
def initialize(total_inventory)
@coke, @sprite, @root_beer = [total_inventory/3,total_inventory/3,total_inventory/3]
@money = 0
@total_inventory = total_inventory * 50
@JeffCohen
JeffCohen / mkmf.log
Created October 4, 2022 15:11
openssl log
$ cat /tmp/ruby-build.20220923165340.2544.hqIt35/ruby-3.1.2/ext/openssl/mkmf.log
=== OpenSSL for Ruby configurator ===
have_func: checking for rb_io_maybe_wait()... -------------------- yes
LD_LIBRARY_PATH=.:../.. "gcc -o conftest -I../../.ext/include/x86_64-linux -I../.././include -I../.././ext/openssl -I/home/deploy/.rbenv/versions/3.1.2/include -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Wundef -fPIC conftest.c -L. -L../.. -L. -L/home/deploy/.rbenv/versions/3.1.2/lib -fstack-protector
@JeffCohen
JeffCohen / env
Created September 24, 2022 21:36
Jeff's env vars on Ubuntu 22.04.1
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1001/bus
HOME=/home/deploy
HOMEBREW_CELLAR=/home/linuxbrew/.linuxbrew/Cellar
HOMEBREW_PREFIX=/home/linuxbrew/.linuxbrew
HOMEBREW_REPOSITORY=/home/linuxbrew/.linuxbrew/Homebrew
INFOPATH=/home/linuxbrew/.linuxbrew/share/info:
LANG=C.UTF-8
LC_TERMINAL=iTerm2
LC_TERMINAL_VERSION=3.4.16
LESSCLOSE=/usr/bin/lesspipe %s %s
@JeffCohen
JeffCohen / coins.rb
Created August 6, 2012 01:38
Coin Change Machine
require 'test/unit'
class ChangeMachine
# Returns an array indicating the quantity of
# each denomination required.
# [pennies, nickels, dimes, quarters]
def issue_coins(amount)
end
end
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My Page</title>
</head>
<body>
<h1>Hello!</h1>
<p>
@JeffCohen
JeffCohen / rails_changes.rb
Last active November 30, 2018 06:02
Generates a unified CHANGELOG.md for Rails releases.
# This script generates unified CHANGELOG output in Markdown
# of all Rails changes between two versions of Rails.
#
# By default, it shows the latest changes in the specified version only.
#
# You can also pass the "since earlier" version you're interested in.
#
# Usage: ruby rails_changes.rb {latest_version} [since_version]
#
# Examples:
# This is pseudocode. Adapted from https://en.wikipedia.org/wiki/Producer%E2%80%93consumer_problem
#
# Currrent design:
#
# A producer places items into a queue.
# A consumer removes items from the queue.
#
# 1. If the queue becomes empty, the consumer sleeps; until woken up later.
# 2. If the queue becomes one-more-than-empty, the producer wakes up the consumer.
# 3. If the queue becomes full, the producer sleeps; until woken up later.