Skip to content

Instantly share code, notes, and snippets.

@Kasvit
Kasvit / setup.txt
Last active March 17, 2025 11:43
new mac setup
chrome
warp
https://www.warp.dev/
brew
https://brew.sh/
dbngin (to install mysql, postgres)
https://dbngin.com/download
@Kasvit
Kasvit / main.rb
Last active November 28, 2024 12:23
New Rails app hints
rails new my_app_name -d postgresql --skip-test
# Gemfile
gem 'slim'
gem "rubocop", require: false
gem "devise"
group :development, :test do
gem "debug", platforms: %i[ mri windows ], require: "debug/prelude"
gem "brakeman", require: false
************** Mapbox
1. Controller
def find_us
@geojson = build_geojson
end
private
def build_geojson
{
Normal: http://prntscr.com/lqkpkg
application.html.slim
doctype html
html
head
= yield(:header)
= display_meta_tags site: 'Project management tool', reverse: true
New(only on this page): http://prntscr.com/lqkpzk
app/views/account/workspaces/list.html.slim
cat.rb
require 'singleton'
class Cat
include Singleton
end
p Cat.instance
@Kasvit
Kasvit / ssl_puma.sh
Created September 26, 2018 09:45 — forked from tadast/ssl_puma.sh
localhost SSL with puma
# 1) Create your private key (any password will do, we remove it below)
$ cd ~/.ssh
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@Kasvit
Kasvit / most_used.rd
Last active August 10, 2018 10:09
top methods for strings, etc
http://www.cheat-sheets.org/saved-copy/RubyCheat.pdf
http://www.peachpit.com/articles/article.aspx?p=1278994&seqNum=2
https://quickleft.com/blog/five-ruby-methods-you-should-be-using/
https://callahan.io/blog/2014/07/17/five-useful-ruby-array-methods
https://launchschool.com/books/ruby/read/arrays#nestedarrays
# String
.concat OR + OR <<
5 прикладів belongs_to з різними опціями
https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-belongs_to
10 методів ajax
5 прикладів has many з різними опціями
# to generate random password
http://ruby-doc.org/stdlib-1.9.2/libdoc/securerandom/rdoc/SecureRandom.html
(0...8).map { (65 + rand(26)).chr }.join
(0...50).map { ('a'..'z').to_a[rand(26)] }.join
# rails caching
https://guides.rubyonrails.org/caching_with_rails.html
<% @products.each do |product| %>
<% cache product do %>
<%= render product %>
<% end %>
<% end %>
<%= render partial: 'products/product', collection: @products, cached: true %>
class Product < ApplicationRecord
has_many :games