Skip to content

Instantly share code, notes, and snippets.

@towfiqpiash
Last active November 18, 2019 07:01
Show Gist options
  • Save towfiqpiash/40d686f710adfac17db2 to your computer and use it in GitHub Desktop.
Save towfiqpiash/40d686f710adfac17db2 to your computer and use it in GitHub Desktop.
Handy Tips & Tricks

Tips & Tricks!

Snippets of all helpful commands

Ionic Framework

Run this after clone to restore state

ionic state restore

SQL

Import large database

mysql> SET GLOBAL FOREIGN_KEY_CHECKS=0;
mysql -h yourhostname -u username -p databasename < yoursqlfile.sql
mysql> SET GLOBAL FOREIGN_KEY_CHECKS=1;

(with progress bar)

pv yoursqlfile.sql | mysql -uxxx -pxxxx databasename

Export/dump database

mysqldump -u username -p dbname > dbexport.sql

Update MySQL server version to 5.6

sudo apt-get purge mysql-server*
sudo apt-get install mysql-server-5.6

Dump specific table

mysqldump -u root -p dbname tablename > db_table.sql

Dump specific table with limited rows

mysqldump -u root -p dbname tablename --where="true limit 100" > db_table.sql

Dump database skipping specific table

mysqldump -u USERNAME -p PASSWORD DATABASE --ignore-table=DATABASE.table1 > database.sql

Export the entire database structure, but exclude certain tables data from export

mysqldump -u USERNAME -p PASSWORD DATABASE --ignore-table=DATABASE.table1 > table1_exluded_database.sql
mysqldump -u USERNAME -p PASSWORD DATABASE table1 --no-data > table1_only_no_data.sql

Just for reference: https://gabi.dev/2016/05/17/fast-data-import-trick/

Laravel

Install Specific Version (e.g 5.2)

// Create a Laravel project
composer create-project laravel/laravel projectName "5.2.*"

// Create a Lumen project
composer create-project laravel/lumen projectName "5.2.*"

Generate Key

php artisan key:generate

Disable CSRF token for a specific url Go app/Http/Middleware, Open VerifyCsrfToken.php. Add the url in the following block for which token verification will be disabled.

protected $except = [
‘api/*’,
‘task/saveTask’,
];

To access project from other device, run this within your project root

php -S 192.168.0.104:8000 -t public

Token mismatch with AJAX post In head section that is common to every page, add the following line:

<meta name=”_token” content=”{!! csrf_token() !!}”/>

Call ajax in the following way.

$.ajax({
type: “POST”,
headers: {‘X-CSRF-Token’: $(‘meta[name=_token]).attr(‘content’)},
url : “url where you want to submit”,
data : dataString,
success : function(status) {
}
});

Create Model from existing database

composer require reliese/laravel

Add the service provider to your config/app.php file Reliese\Coders\CodersServiceProvider::class . Publish the config file with php artisan vendor:publish --tag=reliese-models . Make sure your database is correctly configured in config/database.php and .env files. And finally issue the command: php artisan code:models. This package will scan your database and create all models for you.

500 Internal Server Error

For solving the problem run following commands through terminal.

sudo chmod 755 -R laravel_blog

and then type below command to allow laravel to write file to storage folder

chmod -R o+w laravel_blog/storage

This two commands solves the problem. :D

Terminal

Create tar.gz

tar czf new-tar-file-name.tar.gz file-or-folder-to-archive

Extract tar.gz

tar -xzf tar-file-name.tar.gz

Run command from history

history
!800  //use number of command you want to run

Search from history Use Ctrl+R in terminal & search for expected command

Clear cache

sync && echo 3 | sudo tee /proc/sys/vm/drop_caches

Install deb file using terminal

sudo dpkg -i app_to_install.deb && sudo apt-get install -f

List Wifi hotspot connected devices

arp -a

**ssh into host

ssh user@sitename.com -p portNo

**Delete numbered files in a given range

rm filename.php.{100..200}

Check available language syntax for md (https://support.codebasehq.com/articles/tips-tricks/syntax-highlighting-in-markdown)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment