Skip to content

Instantly share code, notes, and snippets.

almokhtar almokhtarbr

View GitHub Profile
View puma dev server
brew install puma/puma/puma-dev
sudo puma-dev -setup
puma-dev -install
puma-dev link .
If you change configuration files or gem dependencies and you do need to restart a particular app server, you can cd to that app’s directory and:
touch tmp/restart.txt
View Running a Phoenix 1.3 project with docker-compose
FROM elixir:1.5
MAINTAINER YOUR_NAME_HERE
RUN apt-get update && apt-get install --yes postgresql-client
ADD . /app
RUN mix local.hex --force
RUN mix archive.install --force https://github.com/phoenixframework/archives/raw/master/phx_new.ez
WORKDIR /app
EXPOSE 4000
CMD ["./run.sh"]
View docker and rails 5
Dockerfile
```
FROM ruby:2.5
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
View bootstrap rails 6
yarn add bootstrap jquery popper.js
javascripts/packs/application.js
require('bootstrap')
assets/stylesheets/application.css
*= require bootstrap
*= require_tree .
@almokhtarbr
almokhtarbr / update.rb
Created Jun 4, 2020
updating rails app
View update.rb
Upgrade Rails and gems
Update your Gemfile. Temporarily, set an exact Rails version, (e.g. gem 'rails', '= 5.2.1').
Run bundle update.
Relax the Rails version in your Gemfile again (e.g. gem 'rails', '~> 5.2.1').
Run bundle install.
Update your Rails config
Run rails app:update. This will try to write all configuration like it would for a new Rails app, and show you the diff to your current code.
Check the official Rails upgrade guide
@almokhtarbr
almokhtarbr / .rubocop.yml
Last active May 29, 2020
rubocop config [rails rubocop
View .rubocop.yml
AllCops:
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
# to ignore them, so only the ones explicitly set in this file are enabled.
DisabledByDefault: true
TargetRubyVersion: 2.6
Exclude:
- 'vendor/**/*'
- 'Gemfile'
- 'db/**/*'
- 'config/**/*'
@almokhtarbr
almokhtarbr / Hot Live Reload webpacker rails
Created May 19, 2020
Hot Live Reload webpacker rails
View Hot Live Reload webpacker rails
By default, Webpacker enables Hot Live Reload, that reloads pages when the resources change.
Just run bin/webpack-dev-server and at every javascript or stylesheet change, the page will be reloaded.
Change the development configuration of webpacker as follows and restart bin/webpack-dev-server:
# config/webpack/development.rb
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
const environment = require('./environment');
if (!module.hot) {
@almokhtarbr
almokhtarbr / chartkick.rb
Last active May 29, 2020
chartkick rails
View chartkick.rb
gem 'chartkick'
yarn add jquery chartkick highcharts
require('jquery')
require("chartkick")
import Highcharts from 'highcharts';
window.Highcharts = Highcharts;
@almokhtarbr
almokhtarbr / PHP Fatal error Allowed memory
Last active May 11, 2020
PHP Fatal error: Allowed memory #composer
View PHP Fatal error Allowed memory
>To locate your php.ini configuration file you can use the following command: php --ini
```
After running this command you should see an output like the following:
Configuration File (php.ini) Path: /usr/local/etc/php/7.3
Loaded Configuration File: /usr/local/etc/php/7.3/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.3/conf.d
Additional .ini files parsed: /usr/local/etc/php/7.3/conf.d/ext-opcache.ini```
@almokhtarbr
almokhtarbr / validates image with active storage
Created May 10, 2020
validates image with active storage
View validates image with active storage
validate :acceptable_image
def acceptable_image
return unless main_image.attached?
end
def acceptable_image
return unless main_image.attached?
unless main_image.byte_size <= 1.megabyte
You can’t perform that action at this time.