Skip to content

Instantly share code, notes, and snippets.

View majedbojan's full-sized avatar
We turn coffee into code

MaJeD BoJaN majedbojan

We turn coffee into code
View GitHub Profile
@majedbojan
majedbojan / install.sh
Last active July 16, 2020 08:20 — forked from mhmdAljefri/install.sh
Setup Ubuntu Server with Ngnix + MySQL + Redis + Git + RVM + Ruby 2.4.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
# mysql
# sudo apt-get install libmysqlclient-dev mysql-server
@majedbojan
majedbojan / ShellCommands.sh
Last active July 23, 2020 08:22
Daily Shell Commands
# Rotate logs
1) vim or nano /etc/logrotate.conf
2) Add these lines to the bottom of the file
/home/deploy/APPNAME/current/log/*.log {
daily
missingok
rotate 7
compress
delaycompress
notifempty
# config/initializers/string.rb
class String
##---------------bg Color-----------------##
def black; "\e[30m#{self}\e[0m" end
def red; "\e[31m#{self}\e[0m" end
def green; "\e[32m#{self}\e[0m" end
def brown; "\e[33m#{self}\e[0m" end
def blue; "\e[34m#{self}\e[0m" end
def csv(data)
arr = Array.wrap(data)
CSV.open(csv_filename, 'wb') do |csv|
keys = arr.first.keys
# header_row
csv << keys
arr.each do |hash|
csv << hash.values_at(*keys)
end
end
@majedbojan
majedbojan / _alerts.html.erb
Created February 24, 2020 14:21 — forked from ali-sheiba/_alerts.html.erb
Setup Rails 6 with bootstrap
# app/views/shared/_alerts.html.erb
<% flash.each do |key, value| %>
<div class="alert alert-<%= alert_style(key) %>"><%= value %></div>
<% end %>
@majedbojan
majedbojan / sample_encryption_decryption_with_aes_for_ruby.rb
Last active June 10, 2020 09:30
sample encryption and decryption data with Advanced Encryption Standard (AES) for ruby
# Encrypts and Decrypts block of data given an encryption key and an
# initialization vector (iv). Keys, iv's, and the data returned
# are all binary strings. Cipher algorithm should be array [256, CBC],
# or any of the cipher types supported by OpenSSL otherwise default will be used.
# Pass nil if the encryption type doesn't use iv's (like ECB) or ignore it if you using.
# USAGE:
# encrypt_to_hex_format(
# 'ThisPasswordIsReallyHardToGuess', 'initializervector', 'Hey! please encrypt me'
# )
module Attachable
extend ActiveSupport::Concern
included do
## -------------------- Associations -------------------- ##
if const_defined?('STORAGE_TYPES')
self::STORAGE_TYPES.each do |k, v|
v == :one ? has_one_attached(k.to_sym) : has_many_attached(k.to_sym)
end
end
@majedbojan
majedbojan / zsh_corrupt_history.sh
Created September 15, 2020 06:54
Occasionally you may find you have a corrupt zsh history file preventing you from using the `fc` command or searching the history. Here's how to fix it.
1) cd ~
2) mv .zsh_history .zsh_history_bad
3) strings .zsh_history_bad > .zsh_history
4) fc -R .zsh_history # reload history
@majedbojan
majedbojan / RubyOnRailsSetup.sh
Last active February 8, 2021 07:46
Install Ruby On Rails on ubuntu & macOS
# This document will help you setting up a Ruby on Rails development environment on Ubuntu and macOS.
# ---------------------------------------- Ubuntu ------------------------------------------------------ #
# To make sure we have everything necessary for Webpacker support in Rails,
# we're first going to start by adding the Node.js and Yarn repositories to our system before installing them.
- sudo apt-get update
- sudo apt-get install git-core zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn
# Next we're going to be installing Ruby using one of RVM.
# Create a proxy server that forwards requests to thirdparty
# 1) Create a file in `/etc/nginx/sites-available` and name it any name
# 2) Copy the script replace `server_name` with your server domain and `proxy_pass` with third party domain.
server {
listen 80;
server_name YourDomain.com;
location / {
proxy_pass https://ThirdPartyDomain.com;
#proxy_ssl_certificate /etc/nginx/ssl;