Skip to content

Instantly share code, notes, and snippets.

View pama's full-sized avatar

Paulo Abreu pama

View GitHub Profile
<%= turbo_stream.update "panel" do %>
<% if params[:position].to_i <= 5 %>
<p>Less or equal to 5</p>
<% else %>
<p>more than 5</p>
<% end %>
<% end %>
@pama
pama / controller.rb
Last active March 16, 2022 12:18
Search example using query chain
# build a form that posts a document (or whatever) and the form must have the starts_at and ends_at attributes
# you might need to adjust the attributes
@documents = Document.all
# if we have the params
@documents = @document.where(referenced_at: params[:document][:starts_at]..params[:document][:ends_at]) if .....
@pama
pama / controller.rb
Last active March 16, 2022 12:20
Search model example
class Cligest::DocumentsController < ApplicationController
# ...
def index
@document_search = DocumentSearch.new(document_search_params)
@documents = @document_search.perform
# perhaps a few more initializations
respond_to do |format|
@pama
pama / .rubocop.yml
Last active October 12, 2018 08:50
#
# Some rubocop offenses are an insult to programmers
AllCops:
TargetRubyVersion: 2.5
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
# to ignore them, so only the ones explicitly set in this file are enabled.
DisabledByDefault: true
Exclude:
- 'db/**/*'
@pama
pama / app.js
Last active March 16, 2022 12:17
Show data in a table using Express.JS
const express = require('express')
const app = express()
app.set('view engine', 'pug');
app.set('views','./views');
app.get('/', function (req, res) {
var users = [];
var mysql = require('mysql')
@pama
pama / index.html.erb
Last active February 18, 2017 12:21
Example downloading a csv file preserving ransack search
<h1>Users</h1>
<%= search_form_for @q, url: dashboard_index_path do |f| %>
<%= f.label :name_cont %>
<%= f.search_field :name_cont %>
<%= f.submit %>
<% end %>
<ul>
@pama
pama / check_box_filter.rb
Last active January 9, 2017 18:13
Check box filters
scope :category_query, ->(query) do
if query.count == 1
joins(:article_categories).where('article_categories.category_id': query.first)
else
joins(:article_categories).
where('article_categories.article_id': ArticleCategory.select('article_categories.article_id')
.where(category_id: query)
.group('article_categories.article_id')
.having("COUNT(article_categories.article_id) > #{query.count - 1}"))
.uniq
@pama
pama / sublime.txt
Created January 5, 2017 12:51
Sublime text configuration
{
"ensure_newline_at_eof_on_save": true,
"font_size": 12,
"ignored_packages":
[
"Vintage"
],
"save_on_focus_lost": true,
"tab_size": 2,
"translate_tabs_to_spaces": true
@pama
pama / Gemfile
Created June 14, 2016 01:33
Carrier wave for multiple Uploads
# ...
gem 'carrierwave', github: 'carrierwaveuploader/carrierwave'
class SessionsController < ApplicationController
def create
auth = request.env["omniauth.auth"]
session[:omniauth] = auth.except('extra')
user = User.sign_in_from_omniauth(auth)
session[:user_id] = user.id
redirect_to root_url, notice: "Signed In"
end