Skip to content

Instantly share code, notes, and snippets.

View shqear93's full-sized avatar

Khaled AbuShqear shqear93

View GitHub Profile
@shqear93
shqear93 / create_geocoder_data.rb
Last active February 26, 2023 21:19
Use geocoder gem with database
# db/migrate/xxxxxxxxx_create_geocoder_data.rb
class CreateGeocoderData < ActiveRecord::Migration[6.0]
def change
create_table :geocoder_data, id: false do |t|
t.string :url, null: false, primary_key: true
t.jsonb :data
t.timestamps
end
end
@shqear93
shqear93 / pagination.rb
Created August 19, 2021 19:34
Pagination list algorithm for ruby
def pagination_list
range = (0..maximum_pages_number).to_a
adjacent = (@pages_in_bar / 2).floor * 2 + 1
range[[0, [range.size - 1 - adjacent, page_number.to_i - (adjacent / 2).ceil].min].max, adjacent] if adjacent >= 1
end
@shqear93
shqear93 / angluar-amplify.yml
Created June 30, 2020 21:45
AWS Amplify cloudformation
version: 1
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- ENV=staging
- if [ "${AWS_BRANCH}" = "master" ]; then ENV=production; fi
@shqear93
shqear93 / aws-amplify-Jenkinsfile
Last active October 5, 2020 13:47
Jenkins trigger for amplify with logs streaming
pipeline {
agent any
options { skipDefaultCheckout() }
environment {
AWS_DEFAULT_REGION = 'eu-west-1'
}
stages {
stage('Deploy') {
agent {
@shqear93
shqear93 / disable-apparmor
Last active April 7, 2024 11:30
Disable AppArmor completely without breaking snapd
#!/usr/bin/env bash
# It was a nightmare when! aftrer installing docker i couldn't expose any port
# so far because apparmor was preventing docker from controlling the network
# I spent days looking for the solution till I found this documentation <3 :
# https://wiki.debian.org/AppArmor/HowToUse
sudo mkdir -p /etc/default/grub.d
echo 'GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT apparmor=0"' \
| sudo tee /etc/default/grub.d/apparmor.cfg
sudo update-grub
@shqear93
shqear93 / Dockerfiles-ruby-2.4.4-slim-jessie.txt
Created November 27, 2019 11:06
Ruby 2.4.4 slim-jessie Dockerfile
FROM ruby:2.4.4-slim-jessie
RUN apt-get update && apt-get install -y wget && rm -rf /var/lib/apt/lists/*
RUN wget --no-check-certificate --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main" > /etc/apt/sources.list.d/PostgreSQL.list
RUN apt-get update && \
apt-get install -y build-essential libpq-dev git nodejs \
file postgresql-client-10 locales imagemagick --no-install-recommends \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*