Skip to content

Instantly share code, notes, and snippets.

View sajaddp's full-sized avatar

Sajad Dehshiri sajaddp

View GitHub Profile
@sajaddp
sajaddp / unique.js
Created March 14, 2018 15:22
Removing Array Duplicates in ES6
let array = [1,2,3,3,5,4,8,9,5,2,3,1,2,2,1,1,3,6,4,8,9,1,2,5,3,4,6,9,7,8,9];
let unique_array = [...new Set(array)]; // [1, 2, 3, 5, 4, 8, 9, 6, 7]
@sajaddp
sajaddp / Clear git cache
Last active May 1, 2018 12:45
Clear git cache
git rm -r --cached .
git add .
@sajaddp
sajaddp / Git: Remove all local branches that are not on remote.md
Last active September 6, 2022 07:29
Git: Remove all local branches that are not on remote

Git: Remove all local branches that are not on remote

Method 1:

git fetch -p && for branch in $(git branch -vv | grep ': gone]' | awk '{print $1}'); do git branch -D $branch; done

Method 2 (safer):

git fetch -p && for branch in $(git for-each-ref --format '%(refname) %(upstream:track)' refs/heads | awk '$2 == "[gone]" {sub("refs/heads/", "", $1); print $1}'); do git branch -D $branch; done
@sajaddp
sajaddp / converter.js
Last active August 12, 2022 12:08
Convert Persian and Arabic digits of a string to English using JavaScript
const converter = (text) => text.replace(/[٠-٩۰-۹]/g,a=>a.charCodeAt(0)&15);
console.log(converter("۳٣۶٦۵any٥۵٤۶32٠۰"));
// Output: "33665any55453200"
//[Reference](https://stackoverflow.com/a/63133882/6390834)
@sajaddp
sajaddp / CollectionPaginate.md
Last active November 15, 2022 10:11
Laravel Collection Paginate

In new versions of Laravel, you can create your own paginate. Source: https://laravel.com/docs/9.x/pagination

use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;

/**
* @param  Collection  $collection
* @param int $perPage
@sajaddp
sajaddp / shecan.md
Last active May 7, 2023 09:32
Bash function for automatic DNS activation of shecan.ir site

Bash function for automatic DNS activation of shecan.ir site

shecan() {
  local current_dns_state=$(scutil --dns | grep "178.22.122.100" | awk '{print $3}')
  if [ "$current_dns_state" != "" ]; then
    echo "YOUR_PASSWORD" | sudo -S networksetup -setdnsservers Wi-Fi Empty
    echo "DNS has been disabled."
  else
    echo "YOUR_PASSWORD" | sudo -S networksetup -setdnsservers Wi-Fi 178.22.122.100 185.51.200.2
 echo "DNS has been enabled."
@sajaddp
sajaddp / 403.md
Created May 7, 2023 09:32
Bash function for automatic DNS activation of 403.online site

Bash function for automatic DNS activation of 403.online site

403() {
  local current_dns_state=$(scutil --dns | grep "10.202.10.102" | awk '{print $3}')
  if [ "$current_dns_state" != "" ]; then
    echo "YOUR_PASSWORD" | sudo -S networksetup -setdnsservers Wi-Fi Empty
    echo "DNS has been disabled."
  else
    echo "YOUR_PASSWORD" | sudo -S networksetup -setdnsservers Wi-Fi 10.202.10.102 10.202.10.202
 echo "DNS has been enabled."