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 / Dockerfile
Created September 26, 2017 04:39 — forked from sidwood/Dockerfile
Node.js dockerfile templates
FROM node:7.10-alpine
RUN mkdir -p /opt/app
WORKDIR /opt/app
COPY ./package.json /opt/app
RUN apk add --update --no-cache tini &&\
apk add --virtual .build-dependencies make gcc g++ python &&\
npm install --production &&\
@achmiral
achmiral / rails-singular-or-plural.md
Created July 24, 2018 03:53 — forked from SunDi3yansyah/rails-singular-or-plural.md
Rails Conventions - Singular or Plural?
Name Singular/Plural Use
Controller Plural rails g controller Users index show
Helper Plural rails g helper Users
Mailer Singular rails g mailer UserMailer
Migration Plural rails g migration AddEmailToUsers email:string
Model Singular rails g model User name:string
Observer Singular rails g observer User
Resource Plural* resources :users, :only => [:index, :show]
Scaffold Singular rails g scaffold User name:string
@achmiral
achmiral / missing_num_array.rb
Created October 16, 2018 12:18 — forked from malchak/missing_num_array.rb
Solutions to Find Missing Number in Array.
# Question:
# Suppose you have an array of 99 numbers.
# The array contains the digits 1 to 100 with one digit missing.
# Write four different algorithms to compute the missing number.
# Two of these should optimize for low storage and two of these should optimize for fast processing.
# (Keep in mind, there are no duplicates and the array is not already sorted.)
#######################################################
@achmiral
achmiral / .vimrc
Created October 29, 2018 04:48
My Vim Configuration
" Setup Vim Core
set number "Nomor Baris Statik
set relativenumber "Nomor Baris Dinamik
set nocompatible
set softtabstop=2
set backspace=indent,eol,start
filetype plugin indent on
set laststatus=2
set linespace=3
class Api::RegionsController < ApplicationController
def provinces
prompt = [
{
id: "",
name: core_model_lang("province")
}
]
@provinces = prompt + Province.all
render json: @provinces.to_json(only: [:id, :name])
@achmiral
achmiral / .gitlab-ci.yml
Created November 9, 2018 16:50 — forked from SunDi3yansyah/.gitlab-ci.yml
Example Gitlab CI Config for a Rails + Nginx application using Docker Compose
# See how variables work, and a list of predefined ones:
# - https://docs.gitlab.com/ce/ci/variables/
variables:
RAILS_IMAGE: registry.gitlab.com/bryanbraun/gridmaster.io/railsapp:$CI_COMMIT_SHA
NGINX_IMAGE: registry.gitlab.com/bryanbraun/gridmaster.io/nginx:$CI_COMMIT_SHA
DEPLOY_TAG: $CI_COMMIT_SHA
cache:
paths:
- vendor/ruby
@achmiral
achmiral / README.md
Created November 9, 2018 16:50 — forked from SunDi3yansyah/README.md
Make /robots.txt aware of the Rails environment

Make /robots.txt aware of the Rails environment

You probably don't want Google crawling your development staging app. Here's how to fix that.

$ mv public/robots.txt config/robots.production.txt
$ cp config/robots.production.txt config/robots.development.txt

Now edit config/routes.rb to add a route for /robots.txt, and add the controller code.

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

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

@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