Skip to content

Instantly share code, notes, and snippets.

View rcook's full-sized avatar

Richard Cook rcook

View GitHub Profile
@rcook
rcook / encrypted_attribute_helper.rb
Last active December 19, 2015 17:38
Enable multiparameter attribute form submission for encrypted fields in Ruby on Rails http://stackoverflow.com/questions/17482507/correct-way-to-handle-multiparameter-attributes-corresponding-to-virtual-attribu Simply drop this into config/initializers and use attr_encrypted_default instead of attr_encrypted. I'm working on an update to attr_enc…
if defined?(ActiveRecord::Base)
class ActiveRecord::Base
protected
class EncryptedAttributeClassWrapper
attr_reader :klass
def initialize(klass); @klass = klass; end
end
def self.encrypted_attribute_class_wrappers
The MIT License (MIT)
Copyright (c) 2013 Richard Cook
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The MIT License (MIT)
Copyright (c) 2013 Richard Cook
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
@rcook
rcook / option_parser_test.rb
Created July 26, 2013 18:50
Illustrates some of the shortcomings of Ruby's OptionParser class: it doesn't support required arguments out of the box and the design of the code that invokes the code block on "on" and "on_tail" methods requires binding to a variable to save options value, when this is really something that would be better achieved by passing the object into t…
#!/usr/bin/env ruby
# See http://stackoverflow.com/questions/1541294/how-do-you-specify-a-required-switch-not-argument-with-ruby-optionparser
require 'optparse'
require 'ostruct'
require 'pathname'
THIS_PATH = Pathname.new(__FILE__).realpath
THIS_DIR = THIS_PATH.dirname
@rcook
rcook / active_record_test.rb
Last active December 29, 2015 12:19
Test case for Rails/Active Record bug 13044 (https://github.com/rails/rails/issues/13044) Note that this only reproduces using the "postgresql" database adapter. Prerequisites: local instance of PostgreSQL with database name "bug", user name "bug" and password "bug".
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', '=3.2.14'
gem 'pg'
GEMFILE
system 'bundle'
end
@rcook
rcook / lorem-ipsum.Phabricator.diff
Created December 2, 2013 18:27
Reproducer for invalid raw diff output in Phabricator
Index: lorem-ipsum.txt
===================================================================
--- lorem-ipsum.txt
+++ lorem-ipsum.txt
@@ -1,9 +1,13 @@
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed lobortis mattis odio eget iaculis. Curabitur in diam vehicula nisi tempus condimentum. Phasellus non dolor arcu. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus pharetra ipsum nec metus semper egestas. Vestibulum mattis aliquet justo non tincidunt. Etiam a bibendum augue. Nulla cursus, dolor sit amet luctus lobortis, eros mauris imperdiet quam, id vestibulum lacus nisl id ante. Fusce ut ipsum congue, condimentum sapien quis, sagittis nisi.
+FIRST NEW HUNK
+
Quisque tempor malesuada dapibus. Vivamus convallis semper nisi, sit amet mollis ipsum posuere id. Nam pulvinar elit non justo hendrerit, eu semper eros tempor. Nunc eu scelerisque tellus. Proin nec arcu at urna dapibus iaculis vel vel velit. Pellentesque ut nisi diam. Donec sit amet tortor ac ante sodales lobortis. Ut ornare iacu
The MIT License (MIT)
Copyright (c) 2013 Richard Cook
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The MIT License (MIT)
Copyright (c) 2011 Richard Cook
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The MIT License (MIT)
Copyright (c) 2010 Richard Cook
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
public struct DHCPCAPI_IP_ADDRESS
{
public byte Value0;
public byte Value1;
public byte Value2;
public byte Value3;
}