Skip to content

Instantly share code, notes, and snippets.

View sahidursuman's full-sized avatar

Sahidur Rahman Suman sahidursuman

View GitHub Profile
@sahidursuman
sahidursuman / cache.yml
Created April 5, 2019 18:44 — forked from ssaunier/cache.yml
Speed up the AWS Elastic Beanstalk of your Rails deployment with bundle/assets caching
# .ebextensions/cache.config
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/02a_set_cache.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash
set -xe
@sahidursuman
sahidursuman / 1_brand.rb
Created April 2, 2019 17:12 — forked from KamilLelonek/1_brand.rb
Repository pattern example in Ruby for Rails developers
module Storage
module Models
class Brand < ActiveRecord::Base; end
end
end
@sahidursuman
sahidursuman / 1. Setup.bash
Created March 22, 2019 04:03 — forked from Integralist/1. Setup.bash
DynamoDB (using Spurious)
# http://boot2docker.io/
# https://github.com/stevenjack/spurious
boot2docker init
boot2docker up
spurious-server start
spurious init
spurious start
@sahidursuman
sahidursuman / customize_error.rb
Created March 14, 2019 12:40 — forked from telwell/customize_error.rb
Customize Field Errors with Rails 5 and Bootstrap
# Adapted from https://rubyplus.com/articles/3401-Customize-Field-Error-in-Rails-5
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
html = ''
form_fields = [
'textarea',
'input',
'select'
]
@sahidursuman
sahidursuman / app.DockerFile
Created March 11, 2019 11:08 — forked from satendra02/app.DockerFile
docker+rails+puma+nginx+postgres (Production ready)
FROM ruby:2.3.1
# Install dependencies
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
# Set an environment variable where the Rails app is installed to inside of Docker image:
ENV RAILS_ROOT /var/www/app_name
RUN mkdir -p $RAILS_ROOT
# Set working directory, where the commands will be ran:
@sahidursuman
sahidursuman / Hash Keys to Symbols.rb
Created March 8, 2019 09:21 — forked from Integralist/Hash Keys to Symbols.rb
Convert Ruby Hash keys into symbols
hash = { 'foo' => 'bar' }
# Version 1
hash = Hash[hash.map { |k, v| [k.to_sym, v] }]
# Version 2
hash = hash.reduce({}) do |memo, (k, v)|
memo.tap { |m| m[k.to_sym] = v }
end
@sahidursuman
sahidursuman / User.rb
Created February 18, 2019 13:35 — forked from sukima/User.rb
Parse a persons name into parts. Ruby on Rails
class Instructor < ActiveRecord::Base
# code graciously copied and pasted from
# http://mysmallidea.com/articles/2009/5/31/parse-full-names-with-ruby/index.html
def self.parse_name(name)
return false unless name.is_a?(String)
# First, split the name into an array
parts = name.split
@sahidursuman
sahidursuman / 1_initial_migration.rb
Created February 18, 2019 10:30 — forked from wrburgess/1_initial_migration.rb
Setting up UUID columns for Rails 5+ models utilizing Postgres 9.4+
class InitialMigration < ActiveRecord::Migration[5.0]
def change
enable_extension "pgcrypto" unless extension_enabled?("pgcrypto")
end
end
@sahidursuman
sahidursuman / routes.rb
Created February 12, 2019 17:53 — forked from zporter/routes.rb
OfficeGames Root Path Constraint
class AuthConstraint
def matches?(request)
request.session['user_id'].present?
end
end
Officegames::Application.routes.draw do
constraints(AuthConstraint.new) do
root :to => 'games#index'
end
@sahidursuman
sahidursuman / README
Created November 23, 2018 17:52 — forked from michaelaguiar/README
JS - Calculate BMI
BMI Calculator