Skip to content

Instantly share code, notes, and snippets.

View ssnickolay's full-sized avatar
💯
Embrace The Suck

Nick S. ssnickolay

💯
Embrace The Suck
View GitHub Profile
@ssnickolay
ssnickolay / ci_functions.sh
Created May 9, 2016 13:44
Gitlab CI build script
SUCCESS_MESSAGE="*<$BUILDS_URL$CI_BUILD_ID|$CI_BUILD_ID>* $CI_BUILD_REF_NAME\nТесты прошли"
ERROR_MESSAGE="*<$BUILDS_URL$CI_BUILD_ID|$CI_BUILD_ID>* $CI_BUILD_REF_NAME\nТесты упали"
function slack_message {
curl -i\
-H "Accept: application/json" \
-X POST --data 'payload={"channel": "'"$CHANNEL"'", "username": "'"$CI_USERNAME"'", "text": "'"$1"'", "icon_emoji": "'"$AVATAR"'"}' $WEBHOOK
}
function notify_success {
@ssnickolay
ssnickolay / ecto form object example.md
Last active September 10, 2017 12:58
Ecto form object example
defmodule InventoryCore.ProductForm do
  import Ecto.Changeset
  use Ecto.Schema

  alias InventoryCore.Product
  alias InventoryCore.SpreeProduct
  alias InventoryCore.EbayProduct

  embedded_schema do
<Item>
<Title>PRODUCTION SHIPPING</Title>
<SubTitle>pidrkoq111</SubTitle>
<Description>xml description</Description>
<HitCounter>BasicStyle</HitCounter>
<PrimaryCategory>
<CategoryID>10970</CategoryID>
</PrimaryCategory>
<StartPrice>312.0</StartPrice>
<CategoryMappingAllowed>true</CategoryMappingAllowed>
## a
```ruby
a = { :a => 1 }
```
## b
```
a = { :a => 1 }
```

Keybase proof

I hereby claim:

  • I am ssnickolay on github.
  • I am ssnickolay (https://keybase.io/ssnickolay) on keybase.
  • I have a public key ASBc6VrA_dnUD5REO-H2g62MLFP_c_U8X5Zk_mKeVvdrRQo

To claim this, I am signing this object:

@ssnickolay
ssnickolay / tree.rb
Created August 23, 2019 08:22
Tree!
require 'pry'
Record = Struct.new(:id, :level_1, :level_2)
class Tree
class Node
def initialize(object, records, behavior)
@object = object
@records = records
@behavior = behavior
@ssnickolay
ssnickolay / example.rb
Last active September 27, 2019 10:25
Query Object with Active Record
class Filters
class Base
attr_reader :scope
def initialize(scope)
@scope = scope
end
end
class ByPrice < Base
@ssnickolay
ssnickolay / build.sh
Last active September 28, 2019 08:16
Build Ruby via gg Framework. https://github.com/StanfordSNR/gg
# Based on https://github.com/StanfordSNR/gg/blob/master/docker/README.md
# install deps
apt-get install -y ruby bison
# clone Ruby
git clone --single-branch --branch ruby_2_6 https://github.com/ruby/ruby.git
cd ruby
# build configuration files
@ssnickolay
ssnickolay / preload_association.rb
Created December 19, 2019 12:03
Preload with Rails 6+
def preload_association(records)
::ActiveRecord::Associations::Preloader.new.preload(
records,
@association_schema,
@preload_scope
).then(&:first).then do |preloader|
next unless @preload_scope
# The result of previous preload is memoized, ActiveRecord won't load this association again.
if preloader.is_a?(::ActiveRecord::Associations::Preloader::AlreadyLoaded)
owner = preloader.send(:owners).first
@ssnickolay
ssnickolay / data.rb
Created June 17, 2020 14:59
jt -u jvm-ce benchmark --time 120 bench/optcarrot/optcarrot.rb
# BEFORE
a = [3.4451130582146683, 2.385918036922338, 3.920855700632015, 3.0578235878124937, 3.271109578119808, 3.519938062594423, 4.305462705034818, 7.640309888410083, 14.50009541439279, 17.851173279258877, 23.13733295712934, 25.399894868389243, 31.89767820906181, 35.66439549792595, 38.34925941530993, 51.29713457630357, 48.615074490851136, 65.08395637220634, 66.71744986808874, 89.05259814856443, 147.8499320606563, 146.41336775698494, 143.08515128540077, 51.96651916208329, 84.22716230396696, 119.62053614458786, 194.3913705238899, 194.07621178387902, 190.16402274184753, 198.08630220621285, 197.17463918236777, 196.4103623421654, 198.29562080680807, 197.91679854857313, 199.1664459648101, 213.9895304973666, 207.77618851733104, 203.31423277162023, 207.1514110171403, 214.15764801111686, 220.5416495102144, 214.79462244510745, 214.47394130181567, 218.4967400419493, 208.95625260737273, 217.40902017791666, 213.76752190032394, 216.33557284412575, 216.8346198710945, 216.29988270075725, 47.35177910367706, 114.431711619746