Skip to content

Instantly share code, notes, and snippets.

View afsardo's full-sized avatar

André Sardo afsardo

View GitHub Profile
@afsardo
afsardo / $_POST-In-Laravel-Test-Suite.md
Last active June 29, 2017 21:58
Wondering why the $_POST global variable has no values when running tests?

Wondering why the $_POST global variable has no values when running tests?

Today, someone asked my help when using an external package that needed to access the $_POST variable, it wasn't being set when running the test suite while working when getting a real request. It got me investigating.

Turns out Laravel instantiates the Requests and have them through the framework, so it basicly fakes an incoming native request.

Use the gist bellow to get the trick working, unless you are using an external package you should rethink when using $_POST nowadays, but hey, I'm not judging.

@afsardo
afsardo / AppServiceProvider.php
Last active June 30, 2017 01:23
Laravel 5.4: Specified key was too long error
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
@afsardo
afsardo / KILL8000.sh
Created June 30, 2017 15:24
Port in USE, KILL Infinite loop server
# Command to find the process running on port 8000
$ lsof -i tcp:8000
# CAREFULL, command to kill the process make sure you are absolutely right
$ kill [PID]
@afsardo
afsardo / Laravel Folder Permissions.md
Created July 1, 2017 03:57
Laravel Folder Permissions

Define User Group

$ sudo chgrp -R www-data bootstrap/cache storage [public]

Define Read, Write and Execute permissions to the user and group

$ sudo chmod -R ug+rwx bootstrap/cache storage [public]
@afsardo
afsardo / DontTrackCHMODinGit.md
Last active July 2, 2017 15:37
Don't Track CHMOD in Git

In my case when I develop an application I use homestead, so I never have to bother about file permissions, then in production (e.g. AWS) I clone my project and I do have to setup them up.

What happens is this:

        modified:   bootstrap/cache/.gitignore
	modified:   storage/app/.gitignore
	modified:   storage/app/public/.gitignore
	modified:   storage/framework/.gitignore
	modified: storage/framework/cache/.gitignore
@afsardo
afsardo / Loop.sh
Created July 5, 2017 19:50
Terminal Bash Loop
$ for i in {1..10} ; do
echo "Loop ${i}"
done
@afsardo
afsardo / UntrackFilesInGitWithoutDeleting.md
Created July 6, 2017 15:44
Untrack Files In Git Repos Without Deleting Them

Sometimes we f**k up, generally when working with git ^^

If you for some reason happen to add a file in a commit that you shouldn't have and you want to remove it, it might not be that simple.

If you do: $ git rm FILE_NAME, it will remove from git but also actually delete the file.

So for this types of situations that rarely happen :P I have this snippet that adds it to .gitignore and removes it from git:

$ echo "FILE_NAME" &gt;&gt; .gitignore
@afsardo
afsardo / str_pad.php
Created July 8, 2017 15:54
String always constant number of characters
// Append 0 to the left of the number if needed so the number always has 4 digits
$number = 10;
echo str_pad($number, 4, "0", STR_PAD_LEFT);
// Output: 0010
@afsardo
afsardo / mysqldump.sh
Last active July 9, 2017 14:14
MySQL Backup w/ mysqldump
# If for some reason you need to make a backup of your database here's how you dump and restore it.
# Backup
$ mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
# Restore
$ mysql -u root -p[root_password] [database_name] < dumpfilename.sql
@afsardo
afsardo / UsedSpace.md
Last active July 29, 2017 11:42
This will give you the used space for all child folders.

Check used space dirs Ubuntu

Last week there was a disk space problem on an AWS instance, we couldn't figure out where space was being used.

The good old ls / ll wasn't going to cut it, had to search a way to discover what folder was taking up so much space.

Starting from the root $ cd / I used the command below:

$ du -hcsx .[!.]* * | sort -rh | head