Skip to content

Instantly share code, notes, and snippets.

View skyporter's full-sized avatar
🏠
Working from home

Vincent Romagnoli skyporter

🏠
Working from home
View GitHub Profile
@skyporter
skyporter / image_color_info.rb
Last active December 14, 2021 12:52
return dominant color on a picture with minimagick
class ImageColorInfo
def initialize(image)
@image = image
end
def dominant_color
dominant_colors.first
end
def dominant_colors
@skyporter
skyporter / render.rb
Created September 8, 2021 07:39
Rails render view outside controller
class FakeController < ActionController::Base
include ApplicationHelper
def current_user
@current_user ||= User.find(params[:user_id])
end
end
renderer = FakeController.renderer.new(
'action_dispatch.request.path_parameters' => {
@skyporter
skyporter / position_title.rb
Last active September 2, 2020 14:26
get recursive position
def position_titles
columns = %w"id parent_item_id title position"
columns_joined = columns.join(",")
sql = <<-SQL.squish
WITH RECURSIVE agenda_item_tree(#{columns_joined}, level)
AS (
SELECT #{columns_joined}, 0
FROM agenda_items
WHERE id = #{id}
UNION
.sortable-position {
&__draggable {
&-handler {
cursor: move;
}
&-ghost {
border: 1px dashed $gray-400;
background: #fffce4;
}
// This example controller works with specially annotated HTML like:
//
// <div data-controller="nested-form">
// <template data-target="nested-form.template">
// <%= form.fields_for :tasks, Task.new, child_index: 'NEW_RECORD' do |ff| %>
// <%= render "task_fields", form: ff %>
// <% end %>
// </template>
// <%= form.fields_for :tasks do |ff| %>
// <%= render "task_fields", form: ff %>
@skyporter
skyporter / file1.rb
Last active February 8, 2019 15:22
Gist with 2 files
name = params[:name]
puts "Hello #{name}"
@skyporter
skyporter / secure_attribute.rb
Last active February 9, 2019 23:08
Bug with version 0.1.1 of secure attribute
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
class User
def self.process
all.each(&:process)
rescue StandardError => ex
# ensure processing other users..
Appsignal.set_error(ex)
end
def process
# ...
@skyporter
skyporter / bug-report.rb
Last active February 9, 2019 23:11
Bug on globalize gem with dirty attributes
# frozen_string_literal: true
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do