Skip to content

Instantly share code, notes, and snippets.

View phuwanart's full-sized avatar

Phuwanart Larpmark phuwanart

View GitHub Profile
@crashtech
crashtech / RoR, from MVC to GraphQL.md
Last active September 22, 2024 21:59
RoR, from MVC to GraphQL

Ruby on Rails, from MVC to GraphQL

As a Ruby on Rails developer, I'm always looking for the best tools and practices to apply to my day-to-day development. This framework has a fantastic structure where all its inner parts communicate very well. But, as applications start growing, or developers want to start using more modern technologies, several things start getting out of control.

Recent versions of Rails implemented Webpack, facilitating the use of modern JavaScript frameworks, which added another level of robustness to everyone's applications. Not only is this becoming the new standard, but it also enables bigger code-bases without falling into madness.

Facebook, as the creator of ReactJS (one of these modern JS frameworks and the most popular one) introduced to the world another of its technologies, GraphQL. This tool, like any other tool, can be a great asset, as long as it's in the right hands, meaning that you first need to know what role it plays before exploring how to use it in your RoR appli

@leastbad
leastbad / README.md
Created April 16, 2020 08:08
Choices.js Stimulus wrapper preview

Choices.js Stimulus wrapper

https://joshuajohnson.co.uk/Choices/

Soon, this will be published as an NPM package, but there's an absence of documentation right now. It supports almost all functions from the original library; soon it will support 100% of them.

This wrapper adds Ajax pre-fetch search. Happens if controller has a data-search-path attribute.

Stimulus controller targets use new v2 syntax. Controller attaches a reference to itself on the element so that you can access the internal state from external scripts.

@iconifyit
iconifyit / 05-array-to-tree.js
Created February 17, 2020 14:25
30 Days of Algorithms : Day 05 - Create a tree from a flat array.
/**
* Converts a flat array to a tree with runtime O(n)
*
* Big-O : O(n)
*
* This algorithm was taken from Phillip Stanislaus's "Performant Array to Tree"
* which has O(n) complexity. It builds the tree in a single pass.
* @link https://github.com/philipstanislaus
* @link https://www.npmjs.com/package/performant-array-to-tree
* @see https://github.com/iconifyit/30-Days-of-Algorithms
@iconifyit
iconifyit / JsonToModel.js
Created January 25, 2020 17:43
Dynamically create a JavaScript class (POJSO) with getters and setters from a JSON object.
/**
* Creates Javascript Model class with getters and setters for each property in a JSON object.
* For instance, if you call :
*
* var model = JsonToModel({name : 'Scott'});
*
* You will get back:
*
* function() {
* this.instance = 'Model@000-000000';
@kwent
kwent / 20200119064500_add_position_column_to_active_storage_attachments.rb
Last active February 3, 2024 16:25
Rails | Active Storage Attachment + acts_as_list
# db/migrate/20200119064500_add_position_column_to_active_storage_attachments.rb
class AddPositionColumnToActiveStorageAttachments < ActiveRecord::Migration[6.0]
def change
add_column :active_storage_attachments, :position, :integer, default: 0
end
end
@JeremiahChurch
JeremiahChurch / app-lib-subdomain_constraint.rb
Last active November 11, 2022 00:15
Custom Subdomains from Models in Rails & Rspec testing too
class SubdomainConstraint
# used in routes to generate subdomains
# note there is a cache buster in company.rb in case the subdomain is updated - `reload_routes`
# update it if we write any additional cache entries here
RESERVED_SUB_DOMAINS = %w[
www app admin test staging help support wwww cdn owner media intercom mail r _domainkey blog webhooks webhook
hooks api api-test api-staging referral outbound mail webmail w3 mailboxes io heroku inbound google search
].freeze
@julianrubisch
julianrubisch / categories_controller.rb
Last active January 22, 2024 06:44
Dependent Select with StimulusJS
class CategoriesController < ApplicationController
def fields
render json: Field.where(category_id: params[:id]).order(:id)
end
end
@ryenski
ryenski / hello.vue
Last active April 7, 2025 21:28
Stimulus.js + Vue.js
<template>
<div id="app">
<p>{{ message }}</p>
</div>
</template>
<script>
export default {
data: function () {
return {
@mrmartineau
mrmartineau / stimulus.md
Last active April 9, 2025 15:37
Stimulus cheatsheet
@stevenharman
stevenharman / 00_Heroku-Release-Phase-Review-Apps-Rails_README.md
Last active May 23, 2024 04:43
Heroku Release Phase script for managing Rails DB migrations, and playing nice with Review Apps and postdeploy scripts

Heroku Release Phase + Review Apps + Rails

This is a simplified, but fairly thorough, set of scripts and configuration to enable Heroku Release Phase for Rails apps. Further, this particular set up plays nicely with Heroku Review Apps in that the release phase script will:

  1. Fail, loudly, if the DB does not yet exist.
  2. Load the DB schema if the current schema version (as determined by bin/rails db:version) is 0.
  3. Run DB migrations otherwise.

For a "normal" app that usually means it will run the DB migrations.