Skip to content

Instantly share code, notes, and snippets.

View azimidev's full-sized avatar
:octocat:
Pro

Azimi azimidev

:octocat:
Pro
View GitHub Profile
@azimidev
azimidev / Laravel_Custom_Paginate.php
Last active August 9, 2021 18:22
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;
@azimidev
azimidev / google_distance_matrix.php
Last active August 8, 2017 18:59
FInd if an $origin includes $destination withing a specific $distance or default to 50 KM
<?php
/*{
"destination_addresses" : [ "" ],
"origin_addresses" : [ "" ],
"rows" : [
{
"elements" : [{
"distance" : {
"text" : "1.9 mi",
"value" : 3000
@azimidev
azimidev / calculate_profile_percentage.php
Last active July 11, 2022 01:51
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
<?php
/**
* Calculate how much a profile is completed
*
* @param $profile
* @return float|int
*/
function calculate_profile($profile)
{
if ( ! $profile) {
@azimidev
azimidev / get_enum_values.php
Last active August 8, 2017 19:00
Return the possible enum values from the table and column from MySQL. The values returned can be implemented when using something like HTML comboboxes or checkboxes
<?php
/**
* Return the possible enum values from the table and column
*
* @param $table
* @param $field
* @return array
*/
function get_enum_values($table, $field)
{
@azimidev
azimidev / sort_column_by.php
Last active August 8, 2017 19:01
Laravel most generic sorting tabulate data. It works for every column in database
<?php
/**
* Sorting tabulate data
*
* @param $column
* @param $body
* @return string
*/
function sort_column_by($column, $body)
{
@azimidev
azimidev / Amir - Material.icls
Created May 18, 2017 12:50
PHPStorm Amir Theme
<scheme name="Amir - Material" version="142" parent_scheme="Default">
<option name="FONT_SCALE" value="1.0" />
<option name="LINE_SPACING" value="1.5" />
<option name="EDITOR_FONT_SIZE" value="12" />
<option name="EDITOR_LIGATURES" value="true" />
<option name="EDITOR_FONT_NAME" value="Fira Code" />
<colors>
<option name="ADDED_LINES_COLOR" value="212c32" />
<option name="ANNOTATIONS_COLOR" value="8b999f" />
<option name="BORDER_LINES_COLOR" value="" />
<?php
/* PHP */ /* JavaScript */
mb_strpos($myEmail, '@'); myEmail.indexOf('@');
str_replace('@', '[at]', $myEmail); myEmail.replace('@', '[at]');
mb_substr($myEmail, 0, 5); myEmail.substr(0, 5);
mb_strlen($myEmail); myEmail.length;
(int) '10'; parseInt('10');
array_key_exists('name', $user); 'name' in user;
in_array('Book 1', $userBooks); userBooks.includes('Book 1');
time(); Date.now();
@azimidev
azimidev / Form.js
Last active April 26, 2020 07:00
Axios Form Class for use with Vue.js
class Errors {
/**
* Create a new Errors instance.
*/
constructor() {
this.errors = {};
}
/**
* Determine if an errors exists for the given field.
@azimidev
azimidev / MaterialTheme.xccolortheme
Created June 2, 2017 14:07
Material Theme for Xcode
<?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>
@azimidev
azimidev / _spacing-helpers.scss
Last active February 5, 2020 08:59 — forked from jacurtis/_spacing-helpers.scss
SASS Margin and Padding Helpers Loop.
/*
This .scss loop will create "margin helpers" and "padding helpers" for use in your web projects.
It will generate several classes such as:
.mr-10 which gives margin 10 pixels.
.pb-5 gives PADDING 5 pixels
The first letter is "m" or "p" for MARGIN or PADDING
Second letter is "t", "b", "l", or "r" for TOP, BOTTOM, LEFT, or RIGHT
Third letter is the number of spacing in pixels. Adjust the amounts generated by editing the $spaceamounts variable below.