Skip to content

Instantly share code, notes, and snippets.

View mkhairi's full-sized avatar
🤜
Hello, Nice to meet you

Khairi Adnan mkhairi

🤜
Hello, Nice to meet you
View GitHub Profile
@mkhairi
mkhairi / apache_cors_example
Created August 29, 2019 11:49 — forked from brianlmoon/apache_cors_example
CORS example for Apache with multiple domains
# Sets CORS headers for request from example1.com and example2.com pages
# for both SSL and non-SSL
SetEnvIf Origin "^https?://[^/]*(example1|example2)\.com$" ORIGIN=$0
Header set Access-Control-Allow-Origin %{ORIGIN}e env=ORIGIN
Header set Access-Control-Allow-Credentials "true" env=ORIGIN
# Always set Vary: Origin when it's possible you may send CORS headers
Header merge Vary Origin
@mkhairi
mkhairi / gist:4e2f276c7071e91aa8f7cc82d0b1254c
Created November 20, 2017 14:59 — forked from giannisp/gist:ebaca117ac9e44231421f04e7796d5ca
Upgrade PostgreSQL 9.6.5 to 10.0 using Homebrew (macOS)
After automatically updating Postgres to 10.0 via Homebrew, the pg_ctl start command didn't work.
The error was "The data directory was initialized by PostgreSQL version 9.6, which is not compatible with this version 10.0."
Database files have to be updated before starting the server, here are the steps that had to be followed:
# need to have both 9.6.x and latest 10.0 installed, and keep 10.0 as default
brew unlink postgresql
brew install postgresql@9.6
brew unlink postgresql@9.6
brew link postgresql
@mkhairi
mkhairi / gitcheats.txt
Created June 13, 2017 05:10 — forked from chrismccoy/gitcheats.txt
git cheats
# shortform git commands
alias g='git'
# push changes to an empty git repository for the first time
git push --set-upstream origin master
# Remove + and - from start of diff lines
git diff --color | sed "s/^\([^-+ ]*\)[-+ ]/\\1/" | less -r
# clear out git hooks
@mkhairi
mkhairi / dnsmasq OS X.md
Created July 18, 2016 07:10 — forked from ogrrd/dnsmasq OS X.md
Setup dnsmasq on OS X

Never touch your local /etc/hosts file in OS X again

To setup your computer to work with *.dev domains, e.g. project.dev, awesome.dev and so on, without having to add to your hosts file each time.

Requirements

Install

@mkhairi
mkhairi / activerecord_without_rails.rb
Created November 21, 2015 22:07 — forked from jimmynguyc/activerecord_without_rails.rb
ActiveRecord without Rails
require 'active_record'
require 'sqlite3'
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:database => "teachers.db"
)
# Migration
ActiveRecord::Schema.define do
@mkhairi
mkhairi / server.md
Last active August 29, 2015 14:17 — forked from jtadeulopes/server.md

Update and upgrade the system

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get autoremove
sudo reboot
# Permissions cheatsheet
`chmod [a]bcd`
* bit a — sticky:1/setgid:2/setuid:4 (optional, default: 0)
* bit b — owner | x:1/w:2/r:4 - xw:3/xr:5/wr:6/xwr:7
* bit c — group | x:1/w:2/r:4 - xw:3/xr:5/wr:6/xwr:7
* bit d — everyone | x:1/w:2/r:4 - xw:3/xr:5/wr:6/xwr:7
note: only file/dir owner can chmod it
class ApplicationController < ActionController::Base
include Pundit
# Verify that controller actions are authorized. Optional, but good.
after_filter :verify_authorized, except: :index
after_filter :verify_policy_scoped, only: :index
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
private
@mkhairi
mkhairi / index.md
Last active August 29, 2015 14:13 — forked from rstacruz/index.md

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

Commands examples

If the namespace is not used then the commands will perform on top of the default database. bundle exec rake db:create bundle exec rake db:migrate

By using the namespace we are going to use all the configuration for our alternate DB. bundle exec rake store:db:create bundle exec rake store:db:migrate