Skip to content

Instantly share code, notes, and snippets.

View ali-sheiba's full-sized avatar

Ali Al-Sheiba ali-sheiba

View GitHub Profile
@ali-sheiba
ali-sheiba / _form.html.erb
Last active August 12, 2023 15:22
Rails scaffold with Bootstrap 4
<div class="page-header">
<div class="row">
<div class="col">
<%%= link_to "All <%= plural_table_name.capitalize %>", <%= index_helper %>_path, class: 'btn btn-default' %>
</div>
<div class="col text-right">
<%%= link_to "Edit", edit_<%= singular_table_name %>_path(@<%= singular_table_name %>), class: 'btn btn-primary' %>
</div>
</div>
<h1>Show <%= singular_table_name %></h1>
@ali-sheiba
ali-sheiba / _alerts.html.erb
Last active July 30, 2020 21:02
Setup Rails 6 with bootstrap
# app/views/shared/_alerts.html.erb
<% if flash.any? %>
<% flash.each do |key, message| %>
<div id="flash-<%= key %>" class="alert alert-<%= alert_style(key) %> alert-dismissible fade show" role="alert">
<%= message %>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
@ali-sheiba
ali-sheiba / force_pull
Created March 25, 2017 10:07
ForcePull : copy yml files from config, remove project, clone and recover config
#!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
include FileUtils
# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
@ali-sheiba
ali-sheiba / solr-deploy.rb
Last active July 22, 2016 04:53
Reindex Solr Sunspot while deploying ROR Application using Capistrano
# add those lines to deploy.rb
# inspired from : https://gist.github.com/doitian/1795439
# solr tasks
namespace :solr do
desc "start solr sunspot server"
task :start do
on roles(:app) do
within release_path do
@ali-sheiba
ali-sheiba / get_timezone.rb
Created July 21, 2016 07:59
Get timezone name from timezone offset like "GMT+03:00" => "Baghdad"
# example get_timezone("GMT+03:00")
def get_timezone(offset)
# return false if timezone not valid
return false unless ActiveSupport::TimeZone.all.map(&:formatted_offset).include?(offset.gsub("GMT",""))
# find zone name
zone_name = ActiveSupport::TimeZone.all.map(&:to_s).select { |x| x.include?(offset) }.first.gsub("(#{offset}) ", "")
# return false if zone_name not found
@ali-sheiba
ali-sheiba / install.sh
Last active March 14, 2020 11:22
Setup Ubuntu Server with Ngnix + MySQL + Redis + Git + RVM + Ruby 2.5.0 + Ruby On Rails
#!/bin/sh
# ngix + required packages
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install curl git-core nginx build-essential tcl8.5 -y
# Install ImageMagick
sudo apt-get install imagemagick libmagickcore-dev libmagickwand-dev libmagic-dev
@ali-sheiba
ali-sheiba / bashrc
Created June 29, 2016 05:59
bashrc with git and rvm version in terminal
# Returns "*" if the current git branch is dirty.
function parse_git_dirty {
[[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]] && echo "✘"
}
# print rvm version
function rvm_version {
[[ -z "${PWD//*\/var\/www\/*/}" ]] && echo "($(~/.rvm/bin/rvm-prompt v g))"
}