diff --git a/README.md b/README.md index 896e4cb..6e2aabd 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ## ๐Ÿค” Why Awesome-Cheatsheets? -I usually make a cheatsheet when I want to improve my skills on a programming language, a framework or a development tool. [I started doing these kind of things a long time ago on Gist](https://gist.github.com/LeCoupa). To better keep track of the history and to let people contribute, I reorganized all of them into this single repository. Most of the content is coming from official documentations and some books I have read. +I usually make a cheat sheet when I want to improve my skills in a programming language, a framework or a development tool. [I started doing these kinds of things a long time ago on Gist](https://gist.github.com/LeCoupa). To better keep track of the history and to let people contribute, I reorganized all of them into this single repository. Most of the content is coming from official documentation and some books I have read. Feel free to take a look. You might learn new things. They have been designed to provide a quick way to assess your knowledge and to save you time. @@ -100,8 +100,9 @@ Feel free to take a look. You might learn new things. They have been designed to - [Kubernetes](tools/kubernetes.sh) - [Nanobox Boxfile](tools/nanobox_boxfile.yml) - [Nanobox CLI](tools/nanobox_cli.sh) +- [Heroku CLI](tools/heroku.sh) ## ๐Ÿ™Œ๐Ÿผ How to Contribute? -You are more than welcome to contribute and build your own cheatsheet for your favorite programming language, framework or development tool. Just submit changes via pull request and I will review them before merging. +You are more than welcome to contribute and build your own cheat sheet for your favorite programming language, framework or development tool. Just submit changes via pull request and I will review them before merging. diff --git a/backend/django.py b/backend/django.py index 3cc384c..12a33ee 100644 --- a/backend/django.py +++ b/backend/django.py @@ -43,10 +43,34 @@ # ***************************************************************************** -django-admin startproject # create a new project directory structure -django-admin startapp # create a new django application with the specified name -django-admin migrate # synchronize the database state with your current state project models and migrations -django-admin makemigrations # create new migrations to the database based on the changes detected in the models -django-admin runserver # start the development webserver at 127.0.0.1 with the port 8000 +django-admin check # Checks the entire django project for potential problems +django-admin changepassword # Allows changing a userโ€™s password. It prompts you to enter a new password twice for the given user. +django-admin clearsessions # Can be run as a cron job or directly to clean out expired sessions. +django-admin collectstatic # Helps to collect all the static files in the one mentioned director +django-admin createsuperuser # Creates a superuser account (a user who has all permissions). +django-admin compilemessages # Compiles .po files to .mo files for use with builtin gettext support +django-admin createcachetable # Creates the tables needed to use the SQL cache backend. +django-admin dbshell # Runs the command-line client for specified database, or the default database if none is provided. +django-admin diffsettings # Displays differences between the current settings.py and Django's default settings. +django-admin dumpdata # Output the contents of the database as a fixture of the given format (using each model's default manager unless --all is specified). +django-admin flush # Removes ALL DATA from the database, including data added during migrations. Does not achieve a "fresh install" state. +django-admin inspectdb # Introspects the database tables in the given database and outputs a Django model module. +django-admin loaddata # Installs the named fixture(s) in the database. +django-admin makemessages # Runs over the entire source tree of the current directory and pulls out all strings marked for translation. It creates (or updates) a message file in the conf/locale (in the django tree) or locale (for projects and applications) directory. You must run this command with one of either the --locale, --exclude, or --all options. django-admin help # display usage information and a list of the commands provided by each application +django-admin makemigrations # create new migrations to the database based on the changes detected in the models +django-admin migrate # synchronize the database state with your current state project models and migrations +django-admin remove_stale_contenttypes # Deletes stale content types (from deleted models) in your database.y. +django-admin runserver # start the development webserver at 127.0.0.1 with the port 8000 +django-admin sendtestemail # Sends a test email to the email addresses specified as arguments. +django-admin shell # Runs a Python interactive interpreter. Tries to use IPython or bpython, if one of them is available. Any standard input is executed as code. +django-admin showmigrations # Shows all available migrations for the current project. +django-admin sqlflush # Returns a list of the SQL statements required to return all tables in the database to the state they were in just after they were installed. +django-admin sqlmigrate # Prints the SQL statements for the named migration. +django-admin sqlsequencereset # Prints the SQL statements for resetting sequences for the given app name(s). +django-admin squashmigrations # Squashes an existing set of migrations (from first until specified) into a single new one. +django-admin startapp # create a new django application with the specified name +django-admin startproject # create a new project directory structure +django-admin testserver # Runs a development server with data from the given fixture(s). django-admin version # display the current django version + diff --git a/languages/php.php b/languages/php.php index 78a565f..572cf93 100644 --- a/languages/php.php +++ b/languages/php.php @@ -303,3 +303,39 @@ abstract class AbstractClassName abstract function abstractFunction(Type $var = null): Type; } + + +/** + * Basic Implementation of LoggerAwareInterface. + * @see https://github.com/php-fig/log/blob/master/Psr/Log/LoggerAwareTrait.php + */ +trait LoggerAwareTrait +{ + /** + * The logger instance. + * + * @var LoggerInterface + */ + protected $logger; + /** + * Sets a logger. + * + * @param LoggerInterface $logger + */ + public function setLogger(LoggerInterface $logger) + { + $this->logger = $logger; + } +} + + +/** + * Example with use of LoggerAwareTrait. + */ +class ClassWithLogger +{ + /** + * Use the LoggerAwareTrait in this class. + */ + use LoggerAwareTrait; +} \ No newline at end of file diff --git a/tools/gcp.md b/tools/gcp.md new file mode 100644 index 0000000..dba1226 --- /dev/null +++ b/tools/gcp.md @@ -0,0 +1,178 @@ +# GCLOUD SDK AND TOOLBELT CHEATSHEET + +## GCP BASICS + +- `Check Version and Settings`: gcloud version, gcloud info, gcloud components list + +- `Init Profile`: gcloud init This will ask you to open an OpenID URL + +- `List all zones`: gcloud compute zones list + +- `Upgrade local SDK`: gcloud components update, gcloud components update --version 219.0.1 + + +## BUCKET BASICS + +- `List all buckets and files`: gsutil ls, gsutil ls -lh gs:// + +- `Download file`: gsutil cp gs:////package-1.1.tgz . + +- `Upload file`: gsutil cp gs://// + +- `Cat file`: gsutil cat gs://// + +- `Delete file`: gsutil rm gs:/// + +- `Move file`: gsutil mv gs://// + +- `Copy folder`: gsutil cp -r ./conf gs:/// + +- `Show disk usage`: gsutil du -h gs://// + +- `Create bucket`: gsutil mb gs:// + +- `Caculate file sha1sum`: gsha1sum syslog-migration-10.0.2.tgz, shasum syslog-migration-10.0.2.tgz + +- `Gsutil help`: gsutil help, gsutil help cp, gsutil help options + + +## GCP PROJECT + +- `List projects `: gcloud config list, gcloud config list project + +- `Show project info `: gcloud compute project-info describe + +- `Switch project `: gcloud config set project + + +## GKE + +- `Display a list of credentialed accounts `: gcloud auth list + +- `Set the active account `: gcloud config set account + +- `Set kubectl context `: gcloud container clusters get-credentials + +- `Change region `: gcloud config set compute/region us-west + +- `Change zone `: gcloud config set compute/zone us-west1-b + +- `List all container clusters `: gcloud container clusters list + + +## IAM + +- `Authenticate client `: gcloud auth activate-service-account --key-file + +- `Display a list of credentialed accounts `: gcloud auth list + +- `Set the active account `: gcloud config set account + +- `Auth to GCP Container Registry `: gcloud auth configure-docker + +- `Print token for active account `: gcloud auth print-access-token, gcloud auth print-refresh-token + +- `Revoke previous generated credential `: gcloud auth revoke + + +## BUCKET SECURITY + +- `Make all files readable `: gsutil -m acl set -R -a public-read gs:/// + +- `Config auth `: gsutil config -a + +- `Grant bucket access `: gsutil iam ch user:denny@gmail.com:objectCreator,objectViewer gs:// + +- `Remove bucket access `: gsutil iam ch -d user:denny@gmail.com:objectCreator,objectViewer gs:// + + +## VM + +- `List all instances `: gcloud compute instances list, gcloud compute instance-templates list + +- `Show instance info `: gcloud compute instances describe "" --project "" --zone "us-west2-a" + +- `Stop an instance `: gcloud compute instances stop instance-2 + +- `Start an instance `: gcloud compute instances start instance-2 + +- `Create an instance `: gcloud compute instances create vm1 --image image-1 --tags test --zone "" --machine-type f1-micro + +- `SSH to instance `: gcloud compute ssh --project "" --zone "" "" + +- `Download files `: gcloud compute copy-files example-instance:~/REMOTE-DIR ~/LOCAL-DIR --zone us-central1-a + +- `Upload files `: gcloud compute copy-files ~/LOCAL-FILE-1 example-instance:~/REMOTE-DIR --zone us-central1-a + + +## DISKS & VOLUMES + +- `List all disks `: gcloud compute disks list + +- `List all disk types `: gcloud compute disk-types list + +- `List all snapshots `: gcloud compute snapshots list + +- `Create snapshot `: gcloud compute disks snapshot --snapshotname --zone $zone + + +## NETWORK + +- `List all networks `: gcloud compute networks list + +- `Detail of one network `: gcloud compute networks describe --format json + +- `Create network `: gcloud compute networks create + +- `Create subnet `: gcloud compute networks subnets create subnet1 --network net1 --range 10.5.4.0/24 + +- `Get a static ip `: gcloud compute addresses create --region us-west2-a vpn-1-static-ip + +- `List all ip addresses `: gcloud compute addresses list + +- `Describe ip address `: gcloud compute addresses describe --region us-central1 + +- `List all routes `: gcloud compute routes list + + +## DNS + +- `List of all record-sets in my zone `: gcloud dns record-sets list --zone my_zone + +- `List first 10 DNS records `: gcloud dns record-sets list --zone my_zone --limit=10 + + +## FIREWALL + +- `List all firewall rules `: gcloud compute firewall-rules list + +- `List all forwarding rules `: gcloud compute forwarding-rules list + +- `Describe one firewall rule `: gcloud compute firewall-rules describe + +- `Create one firewall rule `: gcloud compute firewall-rules create my-rule --network default --allow tcp:9200 tcp:3306 + +- `Update one firewall rule `: gcloud compute firewall-rules update default --network default --allow tcp:9200 tcp:9300 + + +## IMAGES & CONTAINERS + +- `List all images `: gcloud compute images list + +- `List all container clusters `: gcloud container clusters list + +- `Set kubectl context `: gcloud container clusters get-credentials + + +## RDS + +- `List all sql instances `: gcloud sql instances list + + +## SERVICES + +- `List my backend services `: gcloud compute backend-services list + +- `List all my health check endpoints `: gcloud compute http-health-checks list + +- `List all URL maps `: gcloud compute url-maps list diff --git a/tools/heroku.sh b/tools/heroku.sh new file mode 100644 index 0000000..d6c1c00 --- /dev/null +++ b/tools/heroku.sh @@ -0,0 +1,114 @@ +# ############################################################################## +##### HEROKU TOOLBELT COMPLETE GUIDE ########################################### +################################################################################ + + + +# Installing Heroku toolbelt using command line + +# For MacOS... +brew tap heroku/brew && brew install heroku + +# For Ubuntu... +sudo snap install --classic heroku + +# Other installation methods are + +curl https://cli-assets.heroku.com/install.sh | sh # only for unix based systems, windows incompatible as it needs sudo + +curl https://cli-assets.heroku.com/install-ubuntu.sh | sh # Ubuntu/Debian apt-get + +yay -S heroku-cli # Arch linux, Note: This package is community maintained not by heroku + +npm install -g heroku # This installation method is required for users on ARM and BSD... + + +############ + +# Verifying your installation + +heroku --version + + +# Let's get started with heroku + +heroku login # To login into the heroku toolbelt with your heroku account, this will open browser for you. + +heroku login -i # If you prefer to stay in the command line environment, then you can execute this command + + +# Now navigate to your desired directory and create a blank heroku application + +cd ~/myapp +heorku create + + +# If you are facing login issues, try to execute the following command + +mv ~/.netrc ~/.netrc.backup +heroku login + + +# Uninstalling the heroku CLI + +# For macOS +rm -rf /usr/local/heroku /usr/local/lib/heroku /usr/local/bin/heroku ~/.local/share/heroku ~/Library/Caches/heroku + +# or you can try the below command also on macOS +brew uninstall heroku +rm -rf ~/.local/share/heroku ~/Library/Caches/heroku + +# For Linux (Standalone installs) +rm /usr/local/bin/heroku +rm -rf /usr/local/lib/heroku /usr/local/heroku +rm -rf ~/.local/share/heroku ~/.cache/heroku + +# For Linux (Debian and Ubuntu installs) +sudo apt-get remove heroku heroku-toolbelt +sudo rm /etc/apt/sources.list.d/heroku.list + + + + +##################################################################################################### +### Managing and deploying applications on Heroku (Using Git) ################################### +##################################################################################################### + + +cd myapp # Changing into the project directory +git init # Initializing the project into a git repository +git add . # Adding all the contents of the project into the repository excluding .gitignore content +git commit -m "My first commit" # Commiting the content to the repository + +heroku create # Creating a new empty application on Heroku +git remote -v # verifying that the remote is set to the heroku + +heroku git:remote -a thawing-inlet-61413 # For an existing heroku app, you can add remote to the application +git remote rename heroku heroku-staging # renaming remotes + +git push heroku master # Deploying code to the heroku application +git push heroku testbranch:master # Deploying code from a non-master branch to the heroku application + +heroku create --ssh-git # ssh git transport for the application instead of https +git config --global url.ssh://git@heroku.com/.insteadOf https://git.heroku.com/ # For using ssh always +git config --global --remove-section url.ssh://git@heroku.com/ # To remove this rewrite setting run the command + + + + +##################################################################################################### +### Managing and deploying applications on Heroku (Using Docker) ################################### +##################################################################################################### + + +heroku container:login # Login to the container resistry +git clone https://github.com/heroku/alpinehelloworld.git # Get sample code by cloning into the following repository +heroku create # Creating a blank heroku application + +heroku container:push web # Build the image and push to Container Registry +heroku container:push --recursive # Pushing from the root directory of the project in recursive manner +heroku container:push web worker --recursive # Building the image and pushing to container resistry in recursive manner +heroku container:release web # Releasing the image to your application + +heroku open # Open the application in the browser + diff --git a/tools/sublime_text.md b/tools/sublime_text.md new file mode 100644 index 0000000..8ba2cf8 --- /dev/null +++ b/tools/sublime_text.md @@ -0,0 +1,141 @@ +# SUBLIME TEXT 3 CHEATSHEET + +## Access every command with the command palette + +- `shift + cmd + P `: Command palette + + +## Goto anything + +- `cmd + P `: Goto file + +- `ctrl + G `: Goto line + +- `cmd + P and # `: Fuzzy search + +- `cmd + R `: Goto symbol + + +## Quick selections + +- `cmd + D `: Select word + +- `cmd + K D `: Skip and add next + +- `cmd + U `: Undo quick select + +- `cmd + L `: Select line + +- `ctrl + cmd + G `: Select all in file + +- `shift + cmd + space `: Expand selection to scope + +- `shift + cmd + L `: Split into lines + + +## Edit code + +- `cmd + J `: Join 2 lines + +- `cmd + shift + D `: Duplicate line + +- `cmd + shift + R `: Reindent + +- `cmd + shift + K `: Delete line + +- `ctrl + cmd + up/down `: Move line/selection up/down + +- `alt + cmd + V `: Paste from history + +- `shift + cmd + / `: Comment/uncomment line + +- `alt + backspace `: Delete word by word + +- `alt + fn + backspace `: Forward delete word by word + +- `cmd + shift + enter `: Insert line before + +- `cmd + enter `: Insert line after + + +## Searching + +- `cmd + F `: Search in file + +- `shift + cmd + F `: Search in all files + +- ` `: where filter + + +## Miscelaneous + +- `alt + cmd + right/left `: Switch open tab + +- `Indent selection `: Indent selection + +- `Unindent selection `: Unindent selection + +- `Go to previous cursor position `: Go to previous cursor position + +- `Go to next previous cursor position `: Go to next previous cursor position + +- `Build and execute file `: Build and execute file + + +## Must have packages + +`A file icon, BracketHighlighter, Color Highlighter, Comment-Snippets, DevDocs, EditorConfig, Emmet, File Rename, Git, Git blame, GitGutter, HTML-CSS-JS Prettify, JavaScript Completions, JavaScript Patterns, JavaScript Snippets, LESS, Nodejs, Package Control, Pretty JSON, SideBarEnhancements, SublimeLinter, SublimeLinter-contrib-eslint, Terminal` + + +## Preferences + +```javascript +{ +"color_scheme": "Packages/User/Color Highlighter/themes/Boxy Ocean.tmTheme", +"detect_indentation": false, +"folder_exclude_patterns": +[ +"node_modules", +".svn", +".git", +".meteor/local" +], +"ignored_packages": +[ +"Vintage" +], +"show_definitions": true, +"theme": "Adaptive.sublime-theme" +} +``` + +## Keymap + +```javascript +[ +{ "keys": ["super+v"], "command": "paste_and_indent" }, +{ "keys": ["super+shift+v"], "command": "paste" }, +{ "keys": ["super+shift+r"], "command": "reindent" }, +{ "keys": ["super+h"], "command": "dev_docs_search_selection" } +] + +``` + +## Syncing settings with iCloud + +- `cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages` + +- `mkdir -p ~/Library/Mobile\ Documents/com\~apple\~CloudDocs/WebDev/ST3/Plugins` + +- `mv User ~/Library/Mobile\ Documents/com\~apple\~CloudDocs/WebDev/ST3/Plugins` + +- `ln -s ~/Library/Mobile\ Documents/com\~apple\~CloudDocs/WebDev/ST3/Plugins/User` + + +## Restore settings from iCloud + +- `cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages` + +- `rm -rf User` + +- `ln -s ~/Library/Mobile\ Documents/com\~apple\~CloudDocs/WebDev/ST3/Plugins/User`