This file contains hidden or 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
func parallelMap[T any, V any](input []T, f func(T) (V, error)) ([]V, error) { | |
outChan := make(chan V, len(input)) | |
errChan := make(chan error, len(input)) | |
for i, val := range input { | |
go func(i int, val T) { | |
out, err := f(val) | |
if err != nil { | |
errChan <- err | |
} else { |
This file contains hidden or 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
import { h, ChildNode, FunctionalComponent, FunctionalUtilities } from "@stencil/core"; | |
function vnodeToSource(elem: ChildNode, utils: FunctionalUtilities, output = "", level = 0): string { | |
if (elem.vchildren) { | |
let childOutput: string[] = []; | |
utils.forEach(elem.vchildren, (child) => { | |
childOutput.push(vnodeToSource(child, utils, output, level + 1)); | |
}); |
This file contains hidden or 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
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c | |
--- a/ext/openssl/ossl_ssl.c | |
+++ b/ext/openssl/ossl_ssl.c | |
@@ -107,6 +107,18 @@ | |
OSSL_SSL_METHOD_ENTRY(TLSv1), | |
OSSL_SSL_METHOD_ENTRY(TLSv1_server), | |
OSSL_SSL_METHOD_ENTRY(TLSv1_client), | |
+#if defined(HAVE_TLSV1_2_METHOD) && defined(HAVE_TLSV1_2_SERVER_METHOD) && \ | |
+ defined(HAVE_TLSV1_2_CLIENT_METHOD) | |
+ OSSL_SSL_METHOD_ENTRY(TLSv1_2), |
This file contains hidden or 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
# Put this in config/initializers | |
module ActiveRecord | |
class Base | |
def self.removed_columns(*names) | |
@@removed_columns = Set.new(names.map(&:to_s)) | |
instance_eval do | |
def columns | |
cols = super | |
cols.reject { |col| @@removed_columns.include?(col.name) } |
This file contains hidden or 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
require 'benchmark/ips' | |
carts = 10.times.map { Cart.create! account: Account.first } | |
carts.each { |cart| | |
items = Account.first.product_options.sample(5) | |
items.each { |item| cart.line_items.create product_option_id: item.id, quantity: 1 } | |
} | |
def all_at_once(carts, &blk) |
This file contains hidden or 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 Array | |
def ranked_sample(count) | |
slice_size = length / count | |
count.times.reduce([]) do |a, i| | |
i += 1 | |
to_take = i == count ? length : slice_size * i | |
v = (take(to_take) - a).sample | |
a << v if v | |
a | |
end |
This file contains hidden or 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
Calculating ------------------------------------- | |
ruby version 369 i/100ms | |
c version 3413 i/100ms | |
------------------------------------------------- | |
ruby version 3977.2 (±4.5%) i/s - 19926 in 5.020612s | |
c version 450675.5 (±9.4%) i/s - 2221863 in 4.986029s | |
~/dev/theclymb$ ./bin/rails runner bench.rb | |
Calculating ------------------------------------- | |
ruby version 360 i/100ms | |
c version 3385 i/100ms |
This file contains hidden or 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
# Rspec fire can only mock methods that are defined on a class. | |
# The way active record defines accessors is incompatible with rspec-fire's | |
# implementation so this works around that by defining an accessor for every | |
# attribute as soon as each model class is loaded for the first time | |
# | |
# TODO: See if this is needed with Rails 4 | |
class ActiveRecord::Base | |
class << self | |
alias :__ar_original_inherited__ :inherited |
This file contains hidden or 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
-- Implements the algorithm described here http://www.quuxlabs.com/blog/2010/09/matrix-factorization-a-simple-tutorial-and-implementation-in-python/ | |
-- by translating http://www.quuxlabs.com/wp-content/uploads/2010/09/mf.py_.txt into the equivalent lua code (I hope) | |
-- | |
-- INPUT: | |
-- R : a matrix to be factorized, dimension N x M | |
-- P : an initial matrix of dimension N x K | |
-- Q : an initial matrix of dimension M x K | |
-- K : the number of latent features | |
-- steps : the maximum number of steps to perform the optimisation | |
-- alpha : the learning rate |
This file contains hidden or 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 CreateResumeDesigns < ActiveRecord::Migration | |
def up | |
change_table :resume_designs do |t| | |
t.string :purpose | |
end | |
end | |
def down | |
end | |
end |