Skip to content

Instantly share code, notes, and snippets.

View tabishiqbal's full-sized avatar

Tabish Iqbal tabishiqbal

  • Toronto, Ontario
View GitHub Profile
module LoadResources
module ClassMethods
def load_resource(resource_class, options = {})
filter_options = options.slice :only, :except, :if, :unless
resource_options = options.except :only, :except, :if, :unless
send(:before_filter, filter_options) do |controller|
ResourceBuilder.new(controller, resource_class, resource_options)
.send(:load_resource)
end
@RTLer
RTLer / app.js
Last active March 25, 2019 01:59
vueJs flash message component (alert)
Vue.component('child', {
ready(){
// send flash message
this.$root.$broadcast('flashMessage',{
text: 'Better check yourself, you\'re not looking too good.',
type: 'warning',//optional
important: false,//optional
timeout: 5000//optional
});
@apneadiving
apneadiving / migration.rb
Last active May 1, 2020 09:50
incremental invoice numbers without gap in rails + postgresql
class CreateInvoiceNumbers < ActiveRecord::Migration
def up
create_table :invoice_numbers do |t|
t.integer :year, null: false, unique: true
t.integer :next_number_within_year, null: false, default: 1
end
add_index :invoice_numbers, :year, unique: true
(2016..2045).each do |year|
@ivanoats
ivanoats / .railsrc
Last active August 11, 2020 09:33 — forked from gringocl/gist:8480696
# .railsrc
-B #Skip Bundle
-T #Skip Test-Unit
-d postgresql #Use postgres
@pooot
pooot / uppy-vue-example
Created January 2, 2018 15:54
Very basic vuejs usage of uppy
<template>
<div :id="uppyId">
<div class="ThumbnailContainer" v-if="collection === 'thumbnail'">
<button id="open-thumbnail-modal" class="button">Select file</button>
</div>
<div class="DashboardContainer" v-else></div>
</div>
</template>
@eminkel
eminkel / form.html.erb
Last active September 10, 2020 02:17
StimulusJS Tag Component
<div class="mt-6">
<%= f.label :tags, class: 'form-label' %>
<div class="border border-gray-300 rounded-md flex-1 block w-full transition duration-150 ease-in-out pt-1.5 px-2 mt-1" data-controller="tags" data-tags-tag-collection data-tags-autocomplete="true" data-tags-show-dropdown="" data-target="tags.container">
<div class="flex flex-wrap cursor-text" data-action="click->tags#active">
<div class="flex flex-wrap" data-target="tags.tags">
<div class="text-sm p-2 bg-gray-100 rounded-md flex items-center space-x-1.5 mb-1.5 mr-2">
<p>tag</p>
<div class="inline-flex bg-gray-500 text-gray-100 rounded-full p-1 hover:bg-gray-700 cursor-pointer">
<svg class="h-3 w-3" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" stroke="currentColor"><path d="M6 18L18 6M6 6l12 12"></path></
@inopinatus
inopinatus / organisation.rb
Created December 14, 2020 22:57
Value object that replaced an enum
# app/models/organisation.rb
# schema like:
#
# create_table "organisations", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
# t.string "transponder", default: "my_laps", null: false
#
class Organisation < ApplicationRecord
attribute :transponder, TransponderType.new
@julianrubisch
julianrubisch / turbo_frame_history_controller.js
Last active May 8, 2021 02:39
Tabbed navigation with turbo
import { navigator } from "@hotwired/turbo";
import { Controller } from "stimulus";
import { useMutation } from "stimulus-use";
export default class extends Controller {
connect() {
useMutation(this, { attributes: true, childList: true, subtree: true });
}
mutate(entries) {
@jaredcwhite
jaredcwhite / cable_car_example.html
Last active June 9, 2021 17:31
CableCar + web component
<cable-car href="/cc/cable_car" csrf-token="94IkWdvagUHWPGVkD+VeBFVjGoM0zXAf6tgm6BPU+kEpOj2BTtI6bXJQzEDXGAF+R6Dc1ek7oNouatTMrbUy">
<button
onclick="this.closest('cable-car').post(this, {extra: 123})"
data-x="1"
output="#show-the-things"
>
Do a thing!
</button>
<section id="show-the-things"></section>
@rlogwood
rlogwood / application.html.erb
Last active October 20, 2021 14:49
Example Stimulus Page Reloader Controller for Rails 7
<!DOCTYPE html>
<html>
<head>
<title>RefresherDemo</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
</head>