Skip to content

Instantly share code, notes, and snippets.

View amir-daneshkar-dev's full-sized avatar

Amir Daneshkar amir-daneshkar-dev

View GitHub Profile
@amir-daneshkar-dev
amir-daneshkar-dev / strong-password-regex.md
Created September 23, 2022 10:40 — forked from arielweinberger/strong-password-regex.md
Strong password Regular Expression - NestJS Course
  • Passwords will contain at least 1 upper case letter
  • Passwords will contain at least 1 lower case letter
  • Passwords will contain at least 1 number or special character
  • There is no length validation (min, max) in this regex!

Regular expression for JavaScript:

/((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/
@amir-daneshkar-dev
amir-daneshkar-dev / Convert Persian & English digits together
Created August 1, 2022 11:22 — forked from MeTe-30/Convert Persian & English digits together
Convert Persian & English digits together | Javascript
String.prototype.toPersianDigits = function () {
var id = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
return this.replace(/[0-9]/g, function (w) {
return id[+w];
});
};
String.prototype.toEnglishDigits = function () {
var id = { '۰': '0', '۱': '1', '۲': '2', '۳': '3', '۴': '4', '۵': '5', '۶': '6', '۷': '7', '۸': '8', '۹': '9' };
function list_to_tree(list) {
var map = {}, node, roots = [], i;
for (i = 0; i < list.length; i += 1) {
map[list[i].id] = i; // initialize the map
list[i].children = []; // initialize the children
}
for (i = 0; i < list.length; i += 1) {
node = list[i];
<?php
/**
* Return the common parts from 2 strings.
*
* @param string $str1
* @param string $str2
* @param bool $from_end
* return string
*/
@amir-daneshkar-dev
amir-daneshkar-dev / list.php
Created June 15, 2021 21:23 — forked from simonhamp/list.php
Using list() in foreach in PHP
<?php
$items = [
['field' => 'field1', 'values' => [0, 1, 2, 3, 4]],
['field' => 'field2', 'values' => ['cat', 'dog', 'horse']]
];
foreach ($items as list('field' => $field, 'values' => $values)) {
// can use $field and $values here now!
}
@amir-daneshkar-dev
amir-daneshkar-dev / AppServiceProvider.php
Created June 2, 2021 10:07 — forked from simonhamp/AppServiceProvider.php
A pageable Collection implementation for Laravel
<?php
namespace App\Providers;
use Illuminate\Support\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
class AppServiceProvider extends ServiceProvider
{
public function boot()

MongoDB Cheat Sheet

Show All Databases

show dbs

Show Current Database

MySQL Cheat Sheet

Help with SQL commands to interact with a MySQL database

MySQL Locations

  • Mac /usr/local/mysql/bin
  • Windows /Program Files/MySQL/MySQL version/bin
  • Xampp /xampp/mysql/bin

Add mysql to your PATH

@amir-daneshkar-dev
amir-daneshkar-dev / php-webscraping.md
Created December 26, 2019 23:32 — forked from BaCoNL/php-webscraping.md
web scraping in php

Have you ever wanted to get a specific data from another website but there's no API available for it? That's where Web Scraping comes in, if the data is not made available by the website we can just scrape it from the website itself.

But before we dive in let us first define what web scraping is. According to Wikipedia:

{% blockquote %} Web scraping (web harvesting or web data extraction) is a computer software technique of extracting information from websites. Usually, such software programs simulate human exploration of the World Wide Web by either implementing low-level Hypertext Transfer Protocol (HTTP), or embedding a fully-fledged web browser, such as Internet Explorer or Mozilla Firefox. {% endblockquote %}

@amir-daneshkar-dev
amir-daneshkar-dev / AppServiceProvider.php
Created December 26, 2019 23:25
When You deploy a laravel app to a server thats using ssl and the css and js wont load because of the http instead of https error.
namespace App\Providers;
...
use Illuminate\Support\Facades\URL;
...
public function boot()
{
URL::forceScheme('https');
}