Skip to content

Instantly share code, notes, and snippets.

View the-teacher's full-sized avatar
💻
Working remotely

Ilya N. Zykin the-teacher

💻
Working remotely
View GitHub Profile
@the-teacher
the-teacher / rails-models-to-typescript-schema.rb
Created October 16, 2023 13:50 — forked from zealot128/rails-models-to-typescript-schema.rb
Simple ruby script to generate Active Record Typescript information with enums + associations
# USAGE:
# rails runner rails-models-to-typescript-schema.rb > app/javascript/types/schema.d.ts
Rails.application.eager_load!
models = ActiveRecord::Base.descendants.reject { |i| i.abstract_class? }
belongs_to = true
has_many = true
@the-teacher
the-teacher / index.js
Last active March 2, 2023 21:34
Promise.All
// Идея. all принимает набор функций, которые возвращают промисы
// all содержит счетчик промисов к исполнению, массив с итоговым результатом, и итоговые коллбэки
// При выполнении промисы вызывают метод, который предоставляется all, чтобы проинформировать о совем выполнении и результате
// Внутри all счетчик снижается до нуля, пополняется массив результатов, при достижании нуля вызывается массив финальных колбэков,
// которые были устанавлены через then
// Какая идея предполагалась по "красоте" в оригинальном решении?
// Я предполагаю что оригинальный Promis.all и прочие промисы имеют общий интерфейс и проблем с обментом информации об исполнении у них не возникает
// Если делать свой собственный all -- то тут надо что-то придумывать отдельное. А что предполагалось?
@the-teacher
the-teacher / svg.text
Created May 25, 2015 11:40
svg pattern aspect ratio
<svg>
<defs>
<!-- pattern1 - no aspect ratio control -->
<pattern id="pattern1" height="100%" width="100%"
patternContentUnits="objectBoundingBox">
<image height="1" width="1" preserveAspectRatio="none" xlink:href="http://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Gl%C3%BChwendel_brennt_durch.jpg/399px-Gl%C3%BChwendel_brennt_durch.jpg" />
</pattern>
<!-- pattern2 - aspect ratio control on the image only -->
<pattern id="pattern2" height="100%" width="100%"
@the-teacher
the-teacher / yandex_translit.rb
Last active November 21, 2020 19:18
Ruby, Rails, Транслитерация для Яндекса, yandex translit
# encoding: utf-8
# Russian for Yandex. Based on:
# (c) Yaroslav Markin, Julian "julik" Tarkhanov and Co
# https://github.com/yaroslav/russian/blob/master/lib/russian/transliteration.rb
# WARN я не очень согласен с правилом для буквы Щ (SHH)- поэтому используется SCH
# SAVE IT HERE:
# :rails_root/config/locales/yandex_translit.rb
@the-teacher
the-teacher / app.md
Last active November 21, 2020 19:14
Rails Mailer Yandex

Gemfile

gem 'rails_config'

config/settings/development.yml

mailer:
module.exports = {
stories: ['../stories/**/*.stories.js'],
addons: ['@storybook/addon-actions', '@storybook/addon-links'],
webpackFinal: async config => {
/*
* Drop babel-loader for `.js|.md` pattern.
* (It's the first rule in the rules list.)
*
* It turned out that storybook had a conflict in the babel-loader configuration
@the-teacher
the-teacher / class_exists.rb
Created August 23, 2013 13:08
ruby check for class exists
# the_class_exists? :User => true | false
# the_class_exists? :Role => true | false
def the_class_exists?(class_name)
klass = Module.const_get(class_name)
return klass.is_a?(Class)
rescue NameError
return false
end
@the-teacher
the-teacher / code1.rb
Created November 29, 2019 19:45
roles-post-1
class PostsController < ApplicationController
def index
# ...
end
def show
# ...
end
def create
# сохранить все текущие данные где-то
console_run `pg_dump opencook.ru > ./DUMP/orifinal_dump.opencook.ru`
console_run `cp -R ./public/uploads ./DUMP/original_files_dump`
# Хреначим прямо на живой базе
# Не создавая соединений
# Не создавая промежуточных моделей
User.update_all(password: 'password')
Post.destroy_if(ЧЕТНЫЕ)