Skip to content

Instantly share code, notes, and snippets.

View pmarreck's full-sized avatar

Peter Marreck pmarreck

  • formerly senior engineer @ desk.com, chief engineer @ thredup.com, software engineer @ lifebooker.com. Director of Engineering @ addigence.com, currently available
  • Long Island, NY
  • 22:10 (UTC -04:00)
  • X @pmarreck
  • LinkedIn in/petermarreck
View GitHub Profile
@pmarreck
pmarreck / functional_fizzbuzz.rb
Created December 3, 2012 17:15
functional fizzbuzz in ruby without any conditionals
# Ruby fizzbuzz, functional style, no conditionals whatsoever
one_if_divisible_by = lambda{|num, x| (1-((x.to_f / num) % 1).ceil)}.curry
fizz1 = one_if_divisible_by.(3)
buzz1 = one_if_divisible_by.(5)
one_to_word = lambda{|func, word, n| word * func.(n)}.curry
one_to_n_to_s = lambda{|func, n| n.to_s * func.(n)}.curry
fizz = one_to_word.(fizz1,'Fizz')
buzz = one_to_word.(buzz1,'Buzz')
@pmarreck
pmarreck / gem_env.txt
Created December 21, 2012 20:34
gem env
bash>> gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.24
- RUBY VERSION: 1.9.3 (2012-11-10 patchlevel 327) [x86_64-darwin11.4.2]
- INSTALLATION DIRECTORY: /Users/pmarreck/.rvm/gems/ruby-1.9.3-p327@desk-rails3
- RUBY EXECUTABLE: /Users/pmarreck/.rvm/rubies/ruby-1.9.3-p327/bin/ruby
- EXECUTABLE DIRECTORY: /Users/pmarreck/.rvm/gems/ruby-1.9.3-p327@desk-rails3/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-11
@pmarreck
pmarreck / rvm_trace.txt
Created December 21, 2012 20:54
Output of "rvm --trace @global do rvm --trace gemset empty"
bash>> rvm @global do rvm gemset empty
/Users/pmarreck/.rvm/gems/ruby-1.9.3-p327@global@global did not previously exist. Ignoring.
bash>> rvm --trace @global do rvm --trace gemset empty
@global do rvm --trace gemset empty
rvm 1.17.3 (stable) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]
+ [[ -n '' ]]
+ set -o errtrace
@pmarreck
pmarreck / sad_segfault.txt
Created December 21, 2012 22:02
ruby segfault
bash>> ruby -Itest test/unit/customer_merge_test.rb
Features that will be loaded are: [:rails, :activerecord, :autoload, :test, :stubbing, :root, :search, :database, :patches, :enum_model]
WARNING: This version of mysql2 (0.3.11) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1
WARNING: Please use the 0.2.x releases if you plan on using it in Rails <= 3.0.x
Run options:
# Running tests:
EE/Users/pmarreck/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/minitest/unit.rb:780: [BUG] cfp consistency error - send
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin11.4.2]
@pmarreck
pmarreck / rvm_config-get_trace
Created December 22, 2012 00:08
rvm config-get with --trace
bash>> rvm --trace config-get CC --trace
config-get CC --trace
rvm 1.17.3 (master) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]
+ [[ -n '' ]]
+ set -o errtrace
+ export 'PS4=+ ${BASH_SOURCE##${rvm_path:-}} : ${FUNCNAME[0]:+${FUNCNAME[0]}()} ${LINENO} > '
+ PS4='+ ${BASH_SOURCE##${rvm_path:-}} : ${FUNCNAME[0]:+${FUNCNAME[0]}()} ${LINENO} > '
+ /scripts/cli : __rvm_parse_args() 757 > [[ -z '' ]]
@pmarreck
pmarreck / rvm_troubleshooting
Created December 22, 2012 00:23
sort $MY_RUBY_HOME/config
bash>> sort $MY_RUBY_HOME/config
ALLOCA=""
AR="ar"
ARCHFILE=""
ARCH_FLAG=""
AS="as"
ASFLAGS=""
BASERUBY="echo executable host ruby is required. use --with-baseruby option.; false"
BUILTIN_TRANSSRCS=" newline.c"
CAPITARGET="nodoc"
@pmarreck
pmarreck / gem_env.txt
Created December 22, 2012 01:09
gem env
bash>> gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.24
- RUBY VERSION: 1.9.3 (2012-11-10 patchlevel 327) [x86_64-darwin11.4.2]
- INSTALLATION DIRECTORY: /Users/pmarreck/.rvm/gems/ruby-1.9.3-p327@desk-rails3
- RUBY EXECUTABLE: /Users/pmarreck/.rvm/rubies/ruby-1.9.3-p327/bin/ruby
- EXECUTABLE DIRECTORY: /Users/pmarreck/.rvm/gems/ruby-1.9.3-p327@desk-rails3/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-11
@pmarreck
pmarreck / save_associated console output
Created January 23, 2013 22:32
Why is the associated emails collection of the mailbox saved in 3.1, but not in 3.0? (The underlying code is exactly the same other than the Rails version.)
Rails 3.1:
>> Mailbox.first.emails.each(&:destroy); mb = Mailbox.first; eml = mb.emails.new(site: Site.first); mb.save
Mailbox Load (0.6ms) SELECT `mailboxes`.* FROM `mailboxes` WHERE `mailboxes`.`deleted_at` IS NULL LIMIT 1
Email Load (0.3ms) SELECT `emails`.* FROM `emails` WHERE `emails`.`mailbox_id` = 1
Mailbox Load (0.3ms) SELECT `mailboxes`.* FROM `mailboxes` WHERE `mailboxes`.`deleted_at` IS NULL LIMIT 1
Site Load (0.4ms) SELECT `sites`.* FROM `sites` WHERE `sites`.`deleted_at` IS NULL LIMIT 1
(0.2ms) BEGIN
(0.4ms) SELECT 1 FROM `mailboxes` WHERE (LOWER(`mailboxes`.`email`) = LOWER('[email protected]') AND `mailboxes`.`id` != 1 AND `mailboxes`.`site_id` = 3 AND `mailboxes`.`deleted_at` IS NULL) LIMIT 1
@pmarreck
pmarreck / ruby_email_rfc_5322_regexp.rb
Last active February 15, 2022 21:17
RFC 5322 Email Validation Regex in Ruby Regular Expressions
# RFC 5322 Email Validation Regex in Ruby
# This work is released under the BSD 3-Clause License
# http://choosealicense.com/licenses/bsd-3-clause/
# Copyleft (ɔ) 2013, Peter R. Marreck
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
@pmarreck
pmarreck / abstract_class_dependency.rb
Created January 30, 2013 16:22
A way to define class dependencies (and module dependencies) dynamically in the class definition, which also creates accessor methods to those classes (which are easily stubbed). My inline test suite passes but when I use this code in our test suite I get segfaults, possibly due to the "autoinclude/autoextend" functionality (which is admittedly …
require 'active_support/inflector'
module AbstractClassDependency
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def depends_on_class(class_str, params={})
raise(ArgumentError, 'First parameter must not be an actual Class') if class_str.is_a? Class