Skip to content

Instantly share code, notes, and snippets.

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 / index.html
Created Sep 28, 2020 — forked from phoebebright/index.html
Materialize AutoComplete with id
View index.html
<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 Aug 21, 2020
Ruby on Rails - Bounded contexts via interface objects - Controllers example 1
View comments_controller.rb
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 Aug 21, 2020
Ruby on Rails - Bounded contexts via interface objects - Bounded Contexts example 1
View application.rb
# 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 Aug 21, 2020
Ruby on Rails - Bounded contexts via interface objects - Code Example 1
View comment.rb
# app/models/comment.rb
class Comment < ActiveRecord::Base
belongs_to :student
belongs_to :work
end
@equivalent
equivalent / interface_objects_example_1.rb
Last active Aug 21, 2020
Ruby on Rails - Bounded contexts via interface objects - interface objects example 1
View interface_objects_example_1.rb
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 Jul 1, 2020
wkhtmltoimage / IMGKit gem UTF-8 test of Chinese and Arabic characters
View html2image.rb
# 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
@equivalent
equivalent / try-out-htmlcsstoimage.com.rb
Last active Jul 6, 2020
trying out htmlcsstoimage.com
View try-out-htmlcsstoimage.com.rb
def x
user_id = Rails.application.credentials.dig(:htmlcsstoimage, :user_id) #this will return my Htmlcsstoimage user_id
key = Rails.application.credentials.dig(:htmlcsstoimage, :key) #this will return my Htmlcsstoimage key
auth = { username: user_id, password: key }
html = '<body>'
html += '<h1>Rose Tattoo</h1>'
html += '<h2>Dropkick Murphys</h2>'
@equivalent
equivalent / devise.rb
Created Mar 30, 2020
Custom failure app for devise responding to JS
View devise.rb
# config/initializers/devise.rb
class CustomFailureApp < Devise::FailureApp
def http_auth_body
case request_format
when :js, 'js'
'alert(" not authorized !");'
when :json, 'json'
{ error: i18n_message }
else
i18n_message