This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rb_hash = {hello: 123} | |
system("curl -H 'Content-Type: application/json' -d '#{JSON.dump(rb_hash)}' '#{URL}'") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyParameter::Base < OpenStruct | |
def initialize(name:, description:, validations: proc {}) | |
@validator = Class.new(Struct.new(:value)) do | |
include ActiveModel::Validations | |
instance_eval(&validations) | |
def self.model_name() | |
ActiveModel::Name.new(self, nil, "temp") | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p = ->() { validates_presence_of :foo } | |
B = Class.new() do | |
include ActiveModel::Validations | |
p.call | |
end | |
# => NoMethodError: undefined method `validates_presence_of' for main:Object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# bundle help list | |
Usage: | |
bundle show GEM [OPTIONS] | |
Options: | |
[--paths=List the paths of all gems that are required by your Gemfile.], [--no-paths] | |
[--outdated=Show verbose output including whether gems are outdated.], [--no-outdated] | |
[--no-color] # Disable colorization in output | |
-r, [--retry=NUM] # Specify the number of times you wish to attempt network commands | |
-V, [--verbose], [--no-verbose] # Enable verbose output mode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP VIEW IF EXISTS index_usage; | |
CREATE OR REPLACE TEMP VIEW index_usage AS | |
SELECT pg_stat_user_tables.relname::TEXT AS table_name | |
, psui.idx_scan | |
, pg_size_pretty(pg_relation_size(indexrelid::REGCLASS::TEXT)) AS idx_size | |
, pg_relation_size(indexrelid::REGCLASS::TEXT) AS idx_bytes | |
, indkey AS idx_columns | |
, indisunique | |
, indexrelid::REGCLASS AS index | |
-- , relname::TEXT AS table_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
ruby '1.9.3' | |
gem 'rails', '3.2.18' # Locked for compatibility | |
gem 'rake', '0.9.2.2' | |
gem "audited-activerecord", "3.0.0" # last version that supports rails 3 | |
gem 'composite_primary_keys', '~> 5' | |
gem 'pg' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://play.golang.org/p/v5jbAvnHvL | |
package main | |
import ( | |
"fmt" | |
) | |
type classBuild struct { | |
baseMin, baseMax int64 | |
multipliers map[string]float64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// is there a more idiomatic way to check if the client is asking for JSON? | |
func isJson(r *http.Request) bool { | |
contentType, hasContentType := r.Header["Content-Type"] | |
return strings.HasSuffix(r.URL.Path, ".json") || | |
(hasContentType && (contentType[0] == "application/json")) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I can stub a method like this with rspec-mocks | |
allow(Math).to receive(:double) { |x| x * 2 } | |
expect(Math.double(3)).to eq(6) | |
# Is there an equivalent for Mocha? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# There are 7 cards strictly numbered from 1 to 7. There are 3 individuals: A, | |
# B, and C. A and B each have 3 of these cards, and C has just the final 1 | |
# card. The problem is this... A wants to convey to B what his 3 cards are | |
# (with 100% certainty) in such a way that C is *never* 100% certain of them. | |
# There is no private pre-strategizing talk between A and B (in other words, C | |
# can know full well the algorithm/process and still not be able to figure out | |
# A's holdings). | |
# | |
# How can A accomplish this information transmission as described above? | |
# |
NewerOlder