Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View equivalent's full-sized avatar
:octocat:
I'm IDDQD + IDKFA for Ruby on Rails

Tomas Valent equivalent

:octocat:
I'm IDDQD + IDKFA for Ruby on Rails
View GitHub Profile
@equivalent
equivalent / csv_generate.rb
Created January 5, 2023 13:09
how to generare CSV for milion records in sidekiq
Model.pluck(:id, :name, ...).find_in_batches(10_000) do |ary|
CSV.open("tmp.csv", "ab") do |csv|
csv << ary.map{|a| a.join ','}.join("\n")
end
end
@equivalent
equivalent / README.md
Last active September 29, 2022 13:26
Hubspot CRM API Delete a secondary email address

Hubspot CRM API Delete a secondary email address

how to delete secondary email from a Contact in Hubspot CRM via a API

@equivalent
equivalent / README.md
Last active April 8, 2024 03:00
Rails 7 importmaps dropzone.js direct upload ActiveStorage

This is simple implementation of technologies in hobby project of mine built in Rails7 where I need direct upload to S3.

@equivalent
equivalent / index.html
Created September 28, 2020 15:16 — forked from phoebebright/index.html
Materialize AutoComplete with id
<div class="row">
<div class="col s12">
<div class="row">
<div class="input-field col s13">
<i class="material-icons prefix">textsms</i>
<input type="text" id="autocomplete" class="autocomplete" >
<label for="autocomplete">Autocomplete</label>
</div>
</div>
</div>
@equivalent
equivalent / comments_controller.rb
Created August 21, 2020 09:54
Ruby on Rails - Bounded contexts via interface objects - Controllers example 1
class CommentsController < ApplicationController
# POST /works/123/comments
def create
work = Work.find(params[:work_id])
current_user_student = Student.find(session[:id])
if work.public_board.can_post_comment?(current_user: current_user_student)
work.work_interaction.post_comment(student: current_user_student, content: params[:content])
# ...
@equivalent
equivalent / application.rb
Created August 21, 2020 09:46
Ruby on Rails - Bounded contexts via interface objects - Bounded Contexts example 1
# config/application.rb
module MyApplication
class Application < Rails::Application
# ...
# We need to tell Rails to include `app/bounded_contexts` in auto loader
# This step is needed only in older Rails applications.
# Any subdirs you put in `./app` should automatically get picked up as an autoload path in newer Rails
config.autoload_paths << Rails.root.join('app', 'bounded_contexts')
# ...
end
@equivalent
equivalent / comment.rb
Created August 21, 2020 09:37
Ruby on Rails - Bounded contexts via interface objects - Code Example 1
# app/models/comment.rb
class Comment < ActiveRecord::Base
belongs_to :student
belongs_to :work
end
@equivalent
equivalent / interface_objects_example_1.rb
Last active August 21, 2020 10:06
Ruby on Rails - Bounded contexts via interface objects - interface objects example 1
teacher = Teacher.find(567)
student = Student.find(123)
student = Student.find(654)
# Lesson creation
lesson = teacher.classroom.create_lesson(students: [student1, student2], title: "Battle of Kursk")
# Student uploads Work file
some_file = File.open('/tmp/some_file.doc')
lesson.classroom.upload_work(student: student1, file: some_file)
@equivalent
equivalent / html2image.rb
Created July 1, 2020 14:58
wkhtmltoimage / IMGKit gem UTF-8 test of Chinese and Arabic characters
# IMGKit lib is a Ruby wrapper around wkhtmltoimage
#
# * https://github.com/csquared/IMGKit
# * https://wkhtmltopdf.org/
#
class Html2image
def call
head = '<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>'
div = "<div class='ping'>Pong 读写汉字 - 学中文 ... ﺩ ﻁ ﺽ ﻙ ﻕ. ﻑ ﺙ ﺱ ﺹ ﺵ چ ﺥ ﺡ ﻩ. ڤ ﺫ ﺯ ﻅ ﺝ ﻍ ﻉ ﺓ. ﻡ ﻥ. ﻭ ﻝ ﺭ ﻱ ﻯ. ﺀ ﺃ ﺇ ﺅ ﺉ. ـِﻳ ـِ ـٍ. ـُﻭ ـُ ـٌ. ـَﺍ ✅</</div>" # randomly googled Chinese and Arabic characters, I have no idea what they mean