Skip to content

Instantly share code, notes, and snippets.

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

Kivanio Barbosa kivanio

🏠
Working from home
View GitHub Profile
@kivanio
kivanio / all-indexes.sql
Created June 9, 2021 13:41 — forked from robertrossmann/all-indexes.sql
Postgres diagnostics
-- List all existing indexes and include some useful info about them (incl. the index's definition)
SELECT
schemaname AS schemaname,
t.relname AS tablename,
ix.relname AS indexname,
regexp_replace(pg_get_indexdef(i.indexrelid), '^[^\(]*\((.*)\)$', '\1') AS columns,
regexp_replace(pg_get_indexdef(i.indexrelid), '.* USING ([^ ]*) \(.*', '\1') AS algorithm,
indisunique AS UNIQUE,
indisprimary AS PRIMARY,
import { Controller } from "stimulus"
import Inputmask from 'inputmask';
export default class extends Controller {
static targets = ['employees', 'amount', 'fullresult', 'result', 'economy', 'resultContent', 'calculator', 'id', 'emailBtn', 'leadBtn']
connect(){
this.params = ['employees', 'amount', 'fullresult', 'result', 'economy', 'id']
var _component = this
this.state = 'valid'
var im = new Inputmask('999,99')
@kivanio
kivanio / base_validator.js
Created July 12, 2020 00:33 — forked from mariochavez/base_validator.js
Stimulus validations
export default class BaseValidator {
constructor(value, options, errorMessages) {
this.value = value
this.options = options
this.errorMessages = errorMessages
}
validate() {
return { valid: false, message: 'Implement me!'}
}
@kivanio
kivanio / index.html.slim
Created July 12, 2020 00:31 — forked from ryenski/index.html.slim
Tabbed interface with Stimulus.js
div data-controller='tabs' data-tabs-index='1'
.tabs.is-boxed.is-marginless
ul
li data-target='tabs.tab'
a data={action: "tabs#change"} Tab 1
li data-target='tabs.tab'
a data={action: "tabs#change"} Tab 2
.tab.box data={target: 'tabs.tabPanel'} Tab panel 1
.tab.box data={target: 'tabs.tabPanel'} Tab panel 2
@kivanio
kivanio / currency_controller.js
Created July 12, 2020 00:31 — forked from psergi/currency_controller.js
Stimulus controller to handle dollar based user input when the backend is expecting cents
import { Controller } from 'stimulus';
export default class extends Controller {
onInput = (e) => this.updateHiddenInput(e.target.value);
connect() {
this.element.addEventListener('input', this.onInput);
this.initializeHiddenInput();
this.initializeInput();
}
# This module defines a class method called "descendants" that will return a
# list of all classes that inherit from the current class.
#
# Array.descendants
# Hash.descendants
# ActiveRecord::Base.descendants
#
module Descendants
def descendants
ary = []
/*
Jquery and Rails powered default application.js
Easy Ajax replacement for remote_functions and ajax_form based on class name
All actions will reply to the .js format
Unostrusive, will only works if Javascript enabled, if not, respond to an HTML as a normal link
respond_to do |format|
format.html
format.js {render :layout => false}
end
*/
@kivanio
kivanio / template_handlers.rb
Created September 5, 2012 13:03 — forked from jamesbebbington/template_handlers.rb
Rails 3 Textile Template Handler with ERB
# config/initializers/template_handlers.rb
require 'action_view/template/handlers/textile'
ActionView::Template.register_template_handler :textile, ActionView::Template::Handlers::Textile.new
@kivanio
kivanio / gcal_chk.rb
Created December 22, 2016 18:05 — forked from vivahiraj/gcal_chk.rb
LINE BOT APIを利用してGoogle Calendarの情報を送る
# coding: utf-8
require 'rest-client'
require 'json'
require 'date'
require 'gmail'
require 'yaml'
#google-api-clientはv0.6.4が必要です
require "google/api_client"
@kivanio
kivanio / ruby-mixins.rb
Created November 10, 2011 11:29 — forked from wycats/ruby-mixins.rb
Shows how Ruby mixins work together with `super`
##
## with raw object
##
# create a new object
o = Object.new
# define methods on the object (precisely, the object's singleton)
class << o
def hello(thing)