Skip to content

Instantly share code, notes, and snippets.

View achmiral's full-sized avatar
🏠
WFH

Miral Achmed achmiral

🏠
WFH
View GitHub Profile
@achmiral
achmiral / dropzone_controller.js
Created March 24, 2023 05:21 — forked from lazaronixon/dropzone_controller.js
Dropzone.js + Stimulus + Active Storage
import { Controller } from "stimulus"
import { DirectUpload } from "@rails/activestorage"
import Dropzone from "dropzone"
import { getMetaValue, findElement, removeElement, insertAfter } from "helpers"
Dropzone.autoDiscover = false
export default class extends Controller {
static targets = [ "input" ]
@achmiral
achmiral / creative-cloud-disable.md
Created February 12, 2022 08:04 — forked from andreibosco/creative-cloud-disable.md
disable creative cloud startup on mac
@achmiral
achmiral / Gemfile
Created June 25, 2020 06:21 — forked from dhh/Gemfile
HEY's Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers

The JSON API Standard

What is the JSON API Standard

The Specification

  • The History
  • Why does it exist?
    • Bike Shedding/LookingFor
  • Do we have to use it?
@achmiral
achmiral / manu-active-with.js
Created November 10, 2018 06:02 — forked from SunDi3yansyah/manu-active-with.js
Menu Active with JS
var url = window.location;
var element = $(".ui.vertical.menu a.item").filter(function() {
return this.href == url || url.href.indexOf(this.href) == 0;
}).addClass("active").parent().parent().parent();
if (element.is("li")) {
element.addClass("active");
}
@achmiral
achmiral / application.html.erb
Created November 9, 2018 16:59 — forked from SunDi3yansyah/application.html.erb
Each :notice :error :alert helper
<% [:notice, :error, :alert].each do |level| %>
<% unless flash[level].blank? %>
<div data-alert="alert" class="alert alert-<%= flash_class(level) %> fade in">
<a class="close" data-dismiss="alert" href="#">&times;</a>
<%= content_tag :p, flash[level] %>
</div>
<% end %>
<% end %>
@achmiral
achmiral / shell.md
Created November 9, 2018 16:59 — forked from SunDi3yansyah/shell.md
MySQL / MariaDB login without SUDO
$ > sudo mysql -uroot
mysql > SELECT User, Host FROM mysql.user;
mysql > DROP USER 'root'@'localhost';
@achmiral
achmiral / subdomain-localhost-rails-5.md
Created November 9, 2018 16:52 — forked from SunDi3yansyah/subdomain-localhost-rails-5.md
how to access subdomains locally with Rails 5

Subdomaining Localhost with Rails 5

I've been following this blog post on how to set up an api-only Rails 5 application. One of the sections talks about creating a subdomain for your api

Rails.application.routes.draw do
  constraints subdomain: "api" do
    scope module: "api" do

Setup

Replace IRB with Pry (in your Gemfile) and Byebug with pry-byebug.

gem 'pry-rails', group: [:development, :test]
gem 'pry-byebug', group: [:development, :test]

Using PRY

Realtime Notifications with ActionCable

In this episode we're going to be adding realtime notifications into your app using ActionCable. We've talked about notifications a few times in the past and we used AJAX polling for that. 95% of the time, polling is the solution that would be recommended for it.

But if you're looking for a good introduction into ActionCable then this is a decent one because we're only really using it for one way from the server side to the client side.

Getting started

So to get started we're starting with an app that has Bootstrap installed and then we created a Main controller with an index view which is where we will list our Notifications as for this example.

Before we generate our channels let's install a few things