Skip to content

Instantly share code, notes, and snippets.


Amir Hassan Azimi hassanazimi

View GitHub Profile
hassanazimi /
Created Aug 9, 2018
Laravel Forge Setup Script
# - server (the forge server instance)
# - event (the forge event instance)
# - sudo_password (random password for sudo)
# - db_password (random password for database user)
# - callback (the callback URL)
hassanazimi / calculate_profile_percentage.php
Last active Jun 16, 2022
Calculates how much percentage of a profile is completed. It stripes off timestamps like created_at updated_at and primary keys like ids. Usually beneficial when using Laravel
View calculate_profile_percentage.php
* Calculate how much a profile is completed
* @param $profile
* @return float|int
function calculate_profile($profile)
if ( ! $profile) {

Install Supervisor with sudo apt-get install supervisor in Unix or brew install supervisor in Mac OSX. Ensure it's started with sudo service supervisor restart in Unix or brew services start supervisor in Mac OSX.

In Unix in /etc/supervisord/conf.d/ create a .conf file. In this example, laravel_queue.conf (contents below). Give it execute permissions: chmod +x laravel_queue.conf.

In Mac OSX first run supervisord -c /usr/local/etc/supervisord.ini and in /usr/local/etc/supervisor.d/ create a .conf file. In this example, laravel_queue.conf (contents below). Give it execute permissions: chmod +x laravel_queue.conf.

This file points at /usr/local/bin/, so create that file there. Give this execute permissions, too: chmod +x

Now update Supervisor with: sudo supervisorctl reread in Unix and with: brew services restart supervisor in MAc OSX . And start using those changes with: sudo supervisorctl update.

View disposable_email_addresses
View CleanObject.js
* Goes deep recursive through JSON object,
* if the children is only object and has less than 50 children {node},
* adds it to the new result otherwise return the child.
* @param obj
* @param node 50
* @returns {{}|*}
function cleanObject(obj, node = 50) {
View Laravel_Custom_Paginate.php
* @param $items
* @param $perPage
* @return \Illuminate\Pagination\LengthAwarePaginator
function custom_paginate($items, $perPage)
$pageStart = request('page', 1);
$offSet = ($pageStart * $perPage) - $perPage;
hassanazimi /
Last active Jun 2, 2021
FInd and replace Unix
  1. Replacing all occurrences of one string with another in all files in the current directory: These are for cases where you know that the directory contains only regular files and that you want to process all non-hidden files. If that is not the case, use the approaches in 2.

All sed solutions in this answer assume GNU sed. If using FreeBSD or OS/X, replace -i with -i ''. Also note that the use of the -i switch with any version of sed has certain filesystem security implications and is inadvisable in any script which you plan to distribute in any way.

Non recursive, files in this directory only:

sed -i -- 's/old/new/g' *
perl -i -pe 's/old/new/g' ./* 
hassanazimi / .htaccess
Last active Mar 8, 2021
The Best .htaccess with browser caching and gzip
View .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
hassanazimi / NewObjectValueUpdated.js
Created Nov 17, 2020
This lodash function will find the key value in any object and it will add/update [title] key/value
View NewObjectValueUpdated.js
_.set(_.find(events, { id: 1 }), 'title', 'New title');
View MaterialTheme.xccolortheme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
<string>0.319563 0.371489 0.414287 1</string>
<string>FiraCode-Regular - 12.0</string>
<string>0.319563 0.371489 0.414287 1</string>