Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Pro

Amir Hassan Azimi hassanazimi

:octocat:
Pro
View GitHub Profile
@hassanazimi
hassanazimi / forge.sh
Created Aug 9, 2018
Laravel Forge Setup Script
View forge.sh
#
# REQUIRES:
# - 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
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
<?php
/**
* Calculate how much a profile is completed
*
* @param $profile
* @return float|int
*/
function calculate_profile($profile)
{
if ( ! $profile) {
View _Laravel_Queue_Supervisor_Instruction.md

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/run_queue.sh, so create that file there. Give this execute permissions, too: chmod +x run_queue.sh.

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
0815.ru
0815.ru0clickemail.com
0815.ry
0815.su
0845.ru
0clickemail.com
0-mail.com
0wnd.net
0wnd.org
10mail.com
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
<?php
/**
* @param $items
* @param $perPage
* @return \Illuminate\Pagination\LengthAwarePaginator
*/
function custom_paginate($items, $perPage)
{
$pageStart = request('page', 1);
$offSet = ($pageStart * $perPage) - $perPage;
@hassanazimi
hassanazimi / find_and_replace.md
Last active Jun 2, 2021
FInd and replace Unix
View find_and_replace.md
  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
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
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
@hassanazimi
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" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>0.319563 0.371489 0.414287 1</string>
<key>DVTConsoleDebuggerInputTextFont</key>
<string>FiraCode-Regular - 12.0</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>0.319563 0.371489 0.414287 1</string>