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 / 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 / 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 / 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 / base_mutation.rb
Created April 10, 2020 20:32
Ensuring Policies are Used in Graphql Mutation
class BaseMutation < GraphQL::Schema::RelayClassicMutation
include Graphql::ResolverCallbacks
include ActionPolicy::GraphQL::Behaviour
def current_user
context[:current_user]
end
# Enforce mutation authorization.
# This callbacks verifies that `authorize!` method has been