Skip to content

Instantly share code, notes, and snippets.

View suhovius's full-sized avatar
🤘
Metal

Suhovius suhovius

🤘
Metal
View GitHub Profile
@suhovius
suhovius / rails-jsonb-queries
Created August 31, 2023 14:49 — forked from mankind/rails-jsonb-queries
Ruby on Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
@suhovius
suhovius / 1. Success.rb
Created January 3, 2023 23:22 — forked from Integralist/1. Success.rb
How to clone a Hash (in Ruby) and modify the cloned hash without affecting the original object
# This is the ONLY way I've found that works
# All other suggested solutions (see below examples) don't actually work
# And as an extra bonus: this deep copies as well!
def deep_copy(o)
Marshal.load(Marshal.dump(o))
end

So I built a dummy Rails-plugin gem...

rails plugin new foo --skip-bundle -O --full

and filled in my .gemspec as below, including the line

s.add_dependency "rails-assets-sugar"

and added

@suhovius
suhovius / extconfig.rb
Created October 16, 2021 17:45 — forked from ForeverZer0/extconfig.rb
Automatically include/compile all Ruby C extension source files (including subdirectories) using mkmf
require "mkmf"
ext_name = 'my_extension'
excluded = ['x86', 'x64']
dir_config(ext_name)
$srcs = Dir.glob("#{$srcdir}/**/*.c").map { |path| File.basename(path) }
Dir.glob("#{$srcdir}/*/") do |path|
dir = File.basename(path)
@suhovius
suhovius / create-ruby-gem-that-adds-rake-tasks.md
Created October 15, 2021 23:23 — forked from ntamvl/create-ruby-gem-that-adds-rake-tasks.md
How to create a Ruby gem that adds Rake tasks

How to create a Ruby gem that adds Rake tasks

Create a gem

One way to do this is to use bundler to scaffold our gem:

bundler gem my_gem

Add rake tasks to our gem

I prefer to put tasks meant to manage the gem itself in lib/tasks, and tasks the gem is meant to provide to gem users in lib/my_gem/tasks.

@suhovius
suhovius / rails_setup.md
Created July 21, 2021 16:45 — forked from ryanflach/rails_setup.md
Common setup for a new Rails project
  1. rails new <project_name> -d postgresql --skip-turbolinks --skip-spring -T
  • -d postgresql sets up the project to use PostgreSQL
  • --skip-turbolinks & --skip-spring creates a project that does not use turbolinks or spring
  • -T skips the creation of the test directory and use of Test::Unit
  1. In the Gemfile:
  • Available to all environments:
    • gem 'figaro' - store environment variables securely across your app (docs)
    • Uncomment gem 'bcrypt', '~> 3.1.7' if you will be hosting your own user accounts with passwords (docs)
  • Inside of group :test:
    • gem 'rspec-rails' - user rspec in place of minitest (docs)
@suhovius
suhovius / main.rb
Created June 23, 2021 21:07 — forked from thlinux1107/main.rb
Paya Connect - AccountForm - CC. ACH Works the same way.
# /*----------------------------------------------
# Author: SDK Support Group
# Company: Paya
# Contact: sdksupport@paya.com
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# !!! Samples intended for educational use only!!!
# !!! Not intended for production !!!
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# -----------------------------------------------*/
@suhovius
suhovius / Big List of Real Estate APIs.md
Created June 27, 2019 01:07 — forked from patpohler/Big List of Real Estate APIs.md
Evolving list of Real Estate APIs by Category

Big List of Real Estate APIs

Listings / Property Data

####Rets Rabbit http://www.retsrabbit.com

Rets Rabbit removes the nightmare of importing thousands of real estate listings and photos from RETS or ListHub and gives you an easy to use import and Web API server so you can focus on building your listing search powered website or app.

@suhovius
suhovius / golang_books_sites.md
Created March 14, 2019 18:07 — forked from region23/golang_books_sites.md
Полезные ресурсы для изучающих Go

На русском языке

Русскоязычные сайты и сообщества

English resources

@suhovius
suhovius / metrials-go.md
Created March 14, 2019 18:07 — forked from egorsmkv/metrials-go.md
Материалы по Go (golang): мануалы, статьи, книги и ссылки на сообщества

Материалы по Go (golang)

На русском языке

Мануалы и туториалы

  • [Введение в программирование на Go][1]
  • [Маленькая книга о Go][3]
  • [Эффективный Go][2]
  • Есть еще [Краткий пересказ Effective Go на русском языке][4], но 2009 года