Skip to content

Instantly share code, notes, and snippets.

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

Eric Azimi azimidev

:octocat:
Pro
View GitHub Profile
@azimidev
azimidev / find_and_replace.md
Last active June 2, 2021 21:16
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' ./* 
@azimidev
azimidev / regex.md
Created May 13, 2019 14:38 — forked from jacurtis/regex.md
Most Useful Regex's

Useful Regular Expressions

These are the most useful Regular Expressions that I find myself using on a regular basis


URLs

Test to see if a string is a valid website address or not.

All URLs
@azimidev
azimidev / no-right-click-on-images.js
Created May 13, 2019 14:35 — forked from jacurtis/no-right-click-on-images.js
Removes right-click on images
/*
* This script will look for all images on a page and prevent right clicking on an image.
*/
const images = document.getElementsByTagName('img');
for(var i = 0; i < images.length; i++) {
images[i].addEventListener('contextmenu', event => event.preventDefault());
}
// Note: I threw this script together as requested by a subscriber. I personally don't recommend doing
@azimidev
azimidev / .vimrc
Last active September 24, 2019 16:27
Personal .vimrc file with ~/.vim/plugins.vim file and Vundle installed (https://github.com/VundleVim/Vundle.vim)
so ~/.vim/plugins.vim " Source from plugins
set nocompatible " Disable vi-compatibility
syntax on " Enable syntax highlighting
" Pathogen plugin specific
execute pathogen#infect()
filetype plugin indent on " Pathogen
set background=dark " Set bg to dark
@azimidev
azimidev / forge.sh
Created August 9, 2018 00:05
Laravel Forge Setup Script
#
# 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)
#
@azimidev
azimidev / GIT-ALIAS.MD
Last active July 31, 2018 12:00
GIT ALIASES
  • g = git
  • ga = git add
  • gaa = git add --all
  • gap = git apply
  • gapa = git add --patch
  • gau = git add --update
  • gb = git branch
  • gba = git branch -a
  • gbd = git branch -d
  • gbl = git blame -b -w
@azimidev
azimidev / chunk.js
Created December 8, 2017 01:05 — forked from jperler/chunk.js
Array chunking function for Underscore.js. Usage: _.chunks([1,2,3,4,5,6,7], 2) => [[1,2],[2,3],[4,5],[5,6],[7]]
_.mixin({
chunks: function(arr, size) {
var len = arr.length,
chunk_len = Math.ceil(len/size),
chunks = [];
for (var i = 0; i < chunk_len; i++) {
chunks.push(arr.slice(i*size, (i+1)*size));
}
return chunks;
}
@azimidev
azimidev / Sluggable.php
Created November 30, 2017 20:49
Laravel Slug Attribute Simple and Best
<?php
public function setSlugAttribute($value)
{
$slug = str_slug($value);
$original = $slug;
$count = 2;
while (static::whereSlug($slug)->exists()) {
$slug = "{$original}-" . $count++;
@azimidev
azimidev / Sluggable.php
Last active November 30, 2017 20:14
Laravel Sluggable Trait Version 1
<?php
/**
* For this to work you don't need to do anything,
* just add this Sluggable Trait inside your Model
*/
namespace App\Traits;
@azimidev
azimidev / Sluggable.php
Last active November 30, 2017 20:15
Laravel Sluggable Trait Version 2
<?php
/**
* PHP v7+
* Remember for this to work, in your controller you need to do:
* $model->slug = request('title')
* columns name are: title and slug
*/
namespace App\Traits;