diff --git a/README.md b/README.md index 7c50647..98cc045 100644 --- a/README.md +++ b/README.md @@ -1,64 +1,112 @@ -![AWESOME CHEATSHEETS LOgO](_images/awesome_cheatsheets_logo@2x.png) +![AWESOME CHEATSHEETS LOGO](_images/awesome_cheatsheets_logo@2x.png) + +[![Awesome](https://awesome.re/badge.svg)](https://awesome.re) > 📚 Awesome cheatsheets for popular programming languages, frameworks and development tools. They include everything you should know in one single file. -> ❤️ **If you love this repository, [you can click here to make it spread](https://ctt.ec/PHba4).** +> ❤️ **If you like this repository, [you can click here to tweet it and make it spread](https://ctt.ec/PHba4).** -## Why Awesome Cheatsheets? +## 🎩 Why Awesome-Cheatsheets? -I always 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) but as it is easier to keep track of the history, I reorganized everything into a single repository. Most of the content is coming from official documentations or some books I have read. +I always 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 to them, I reorganized everything into this single repository. Most of the content is coming from official documentations and some books I have read. -Feel free to browse each file to learn new things and to keep them at hand when you forgot about something. They have been designed to save you time when you are building great things and to provide a quick way to assess your knowledge. - -**If you want to follow this mindset for your favorite programming language, framework or development tool, you are more than welcome to contribute. Just submit changes via pull request and I will review it.** +Feel free to browse each cheatsheet to learn new things and to keep them at hand when you forgot about one command. They have been designed to provide a quick way to assess your knowledge and to save you time. -## Table of Contents +## 🙌🏼 How to Contribute? -- [Languages](#languages) - -- [Backend](#backend) - -- [Frontend](#frontend) - -- [Databases](#databases) - -- [Tools](#tools) +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. -## Languages +## 📚 Table of Contents -- [Bash](languages/bash.sh) +### 📃 Languages -- [JavaScript](languages/javascript.js) +
+View contents + +#### Command line interface + +* [Bash](languages/bash.sh) + +#### Imperative + +* [PHP](languages/php.php) + +#### Functional + +* [JavaScript](languages/javascript.js) +
-## Backend +### 📦 Backend -- [Django](backend/django.py) +
+View contents -- [Feathers.js](backend/feathers.js) +#### Python -- [Node.js](backend/node.js) +* [Django](backend/django.py) + +#### Javascript + +* [Feathers.js](backend/feathers.js) +* [Node.js](backend/node.js) +
-## Frontend +### 🌐 Frontend -- [Vue.js](frontend/vue.js) +
+View contents + +#### Frameworks + +* [Vue.js](frontend/vue.js) +
-## Databases +### 🗃️ Databases -- [Redis](databases/redis.sh) +
+View contents + +#### NoSQL + +* [Redis](databases/redis.sh) +
-## Tools +### 🔧 Tools -- [Docker](tools/docker.sh) +
+View contents -- [Nanobox Boxfile](tools/nanobox_boxfile.yml) +#### Development -- [Nanobox CLI](tools/nanobox_cli.sh) +* [VIM](tools/vim.txt) +* [XCode](tools/xcode.txt) -- [VIM](tools/vim.txt) +#### Infrastructure + +* [Docker](tools/docker.sh) +* [Nanobox Boxfile](tools/nanobox_boxfile.yml) +* [Nanobox CLI](tools/nanobox_cli.sh) +
+ + +## Contribution + + + + + + +
+ + + +
+ +> 👋 Do you want your company to be listed there? Contribute with a cheatsheet for your favorite programming language, framework or development tool. diff --git a/backend/django.py b/backend/django.py index 3676b5c..42895ed 100644 --- a/backend/django.py +++ b/backend/django.py @@ -36,3 +36,15 @@ # Use underscores in URL pattern names rather than dashes. + + +# ***************************************************************************** +# DJANGO-ADMIN +# ***************************************************************************** + + +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 diff --git a/backend/feathers.js b/backend/feathers.js index 559b2f6..5e59096 100644 --- a/backend/feathers.js +++ b/backend/feathers.js @@ -81,6 +81,9 @@ class MyService { setup(app, path) {} } +params.query // contains the URL query parameters sent from the client +params.provider // for any service method call made through REST params.provider will be set to rest + app.use('/my-service', new MyService()); // Important: Always use the service returned by app.service(path) @@ -159,13 +162,12 @@ channel.connections // contains a list of all connections in this channel channel.length // returns the total number of connections in this channel service.publish([event,] fn) // registers a publishing function for a specific service for a specific event or all events if no event name was given -app.publish([event,] fn) +app.publish([event,] fn) // registers an event publishing callback app.on('connection', connection => {}) // fired every time a new real-time connection is established app.on('login', (payload, info) => {}) // sent by the authentication module and also contains the connection in the info object that is passed as the second parameter - /* ******************************************************************************************* * 2. TRANSPORT: Expose a Feathers application as an API server. * ******************************************************************************************* */ @@ -182,6 +184,53 @@ npm install @feathersjs/socketio --save npm install @feathersjs/primus --save ``` +// --> EXPRESS <-- + +const feathers = require('@feathersjs/feathers'); +const express = require('@feathersjs/express'); + +// Create an app that is a Feathers AND Express application +const app = express(feathers()); + +// If no Feathers application is passed, express() returns a plain Express application +// just like a normal call to Express would +const app = express(); + +app.use(path, service|mw) // registers either a service object or an Express middleware on the given path +app.listen(port) // will first call Express app.listen and then internally also call the Feathers app.setup(server) +app.setup(server) // usually called internally by app.listen but in the cases described below needs to be called explicitly + +express.rest() // registers a Feathers transport mechanism that allows you to expose and consume services through a RESTful API. +app.configure(express.rest()) // configures the transport provider with a standard formatter sending JSON response via res.json + +express.notFound() // returns middleware that returns a NotFound (404) Feathers error +express.errorHandler() // middleware that formats any error response to a REST call as JSON and sets the appropriate error code +app.use(express.errorHandler()) // set up the error handler with the default configuration + +// --> SOCKET.IO <-- + +const feathers = require('@feathersjs/feathers'); +const socketio = require('@feathersjs/socketio'); + +const app = feathers(); + +app.configure(socketio()); // sets up the Socket.io transport with the default configuration using either the server provided by app.listen or passed in app.setup(server) +app.configure(socketio(callback)) // sets up the Socket.io transport with the default configuration and call callback with the Socket.io server object +app.configure(socketio(options [, callback])) // sets up the Socket.io transport with the given Socket.io options object and optionally calls the callback +app.configure(socketio(port, [options], [callback])) // creates a new Socket.io server on a separate port. Options and a callback are optional + +// The options can also be used to initialize uWebSocket which is a WebSocket server +// implementation that provides better performace and reduced latency. +// npm install uws --save +app.configure(socketio({ + wsEngine: 'uws' +})); + +// --> PRIMUS <-- + +app.configure(primus(options)) // sets up the Primus transport with the given Primus options +app.configure(primus(options, callback)) // sets up the Primus transport with the given Primus options and calls the callback with the Primus server instance + /* ******************************************************************************************* * 3. CLIENT: More details on how to use Feathers on the client. @@ -189,6 +238,10 @@ npm install @feathersjs/primus --save ```bash +# Bundles the separate Feathers client side modules into one providing the code as ES5 (compatible with modern browsers) +# You do not have to install or load any of the other modules listed below +npm install @feathersjs/client --save + # Allows to connect to services through REST HTTP npm install @feathersjs/rest-client --save @@ -202,6 +255,26 @@ npm install @feathersjs/primus-client --save npm install @feathersjs/authentication-client --save ``` +// --> REST CLIENT <-- + +rest([baseUrl]) // Initialize a client object with a base URL + +app.configure(restClient.jquery(window.jQuery)); // connect to a service using jQuery +app.configure(restClient.request(requestClient)); // connect to a service using request +app.configure(restClient.superagent(superagent)); // connect to a service using Superagent +app.configure(restClient.axios(axios)); // connect to a service using Axion +app.configure(restClient.fetch(window.fetch)); // connect to a service using Fetch + +// --> SOCKET.IO <-- + +socketio(socket) // initialize the Socket.io client using a given socket and the default options +socketio(socket, options) // initialize the Socket.io client using a given socket and the given options + +// --> PRISMUS <-- + +primus(socket) // initialize the Primus client using a given socket and the default options +primus(socket, options) // initialize the Primus client using a given socket and the given options + /* ******************************************************************************************* * 4. AUTHENTICATION: Feathers authentication mechanism. @@ -225,6 +298,33 @@ npm install @feathersjs/authentication-oauth1 --save npm install @feathersjs/authentication-oauth2 --save ``` +app.configure(auth(options)) // configure the authentication plugin with the given options + +options = { + path: '/authentication', // the authentication service path + header: 'Authorization', // the header to use when using JWT auth + entity: 'user', // the entity that will be added to the request, socket, and context.params. (ie. req.user, socket.user, context.params.user) + service: 'users', // the service to look up the entity + passReqToCallback: true, // whether the request object should be passed to the strategies `verify` function + session: false, // whether to use sessions + cookie: { + enabled: false, // whether cookie creation is enabled + name: 'feathers-jwt', // the cookie name + httpOnly: false, // when enabled, prevents the client from reading the cookie. + secure: true // whether cookies should only be available over HTTPS + }, + jwt: { + header: { typ: 'access' }, // by default is an access token but can be any type + audience: 'https://yourdomain.com', // The resource server where the token is processed + subject: 'anonymous', // Typically the entity id associated with the JWT + issuer: 'feathers', // The issuing server, application or resource + algorithm: 'HS256', // the algorithm to use + expiresIn: '1d' // the access token expiry + } +} + +app.service('authentication') // + /* ******************************************************************************************* * 5. DATABASE: Feathers common database adapter API and querying mechanism. diff --git a/languages/bash.sh b/languages/bash.sh index 0c12f51..4dff618 100644 --- a/languages/bash.sh +++ b/languages/bash.sh @@ -144,11 +144,11 @@ echo $! # prints process ID of the most recently invoked ba echo $? # displays the exit status of the last command export VARNAME=value # defines an environment variable (will be available in subprocesses) -array[0]=valA # how to define an array +array[0]=valA # how to define an array array[1]=valB array[2]=valC -array=([2]=valC [0]=valA [1]=valB) # another way -array(valA valB valC) # and another +array=([2]=valC [0]=valA [1]=valB) # another way +array=(valA valB valC) # and another ${array[i]} # displays array's value for this index. If no index is supplied, array element 0 is assumed ${#array[i]} # to find out the length of any element in the array @@ -407,7 +407,7 @@ function errtrap { echo "ERROR line $1: Command exited with status $es." } -trap 'errtrap $LINENO' ERR # is run whenever a command in the surrounding script or function exists with non-zero status +trap 'errtrap $LINENO' ERR # is run whenever a command in the surrounding script or function exits with non-zero status function dbgtrap { echo "badvar is $badvar" diff --git a/languages/javascript.js b/languages/javascript.js index b0eab0a..fa7a5e2 100644 --- a/languages/javascript.js +++ b/languages/javascript.js @@ -5,7 +5,8 @@ // Global object: properties -Array.length // Reflects the number of elements in an array +Array.length // Reflects the number of elements in an array. +Array.prototype // Represents the prototype for the Array constructor and allows to add new properties and methods to all Array objects. // Global object: methods Array.from(arrayLike[, mapFn[, thisArg]]) // Creates a new Array instance from an array-like or iterable object. diff --git a/languages/php.php b/languages/php.php new file mode 100644 index 0000000..4c8d311 --- /dev/null +++ b/languages/php.php @@ -0,0 +1,235 @@ + PROPERTY TYPES <-- + + /** + * Public property, everyone can access this property. + * @var Type + */ + public $property; + + /** + * Private property, only this instance can access this property. + * @var Type + */ + private $property; + + /** + * Protected property, this instance and childs can access this property. + * @var Type + */ + protected $property; + + /** + * Static property, is the same for all instances of this class. + * @var Type + */ + static $property; + + // --> FUNCTION TYPES <-- + + /** + * Public function, everyone can access this function. + * @param Type + * @return Type + */ + public function publicFunction(Type $var = null): Type + { + } + + /** + * Private function, only this instance can access this function. + * @param Type + * @return Type + */ + private function privateFunction(Type $var = null): Type + { + } + + /** + * Protected function, this instance and childs can access this function. + * @param Type + * @return Type + */ + protected function protectedFunction(Type $var = null): Type + { + } + + /** + * Static function, doesn't need an instance to be executed. + * @param Type + * @return Type + */ + public static function staticFunction(Type $var = null): Type + { + } + + // --> MAGIC METHODS <-- + + /** + * Gets triggered on creating a new class instance + * http://php.net/manual/en/language.oop5.decon.php + * @param Type + * @return void + */ + public function __construct(Type $var = null) + { + } + + /** + * Gets triggered on destruction of a class instance + * http://php.net/manual/en/language.oop5.decon.php + * @return void + */ + public function __destruct() + { + } + + /** + * __set() is run when writing data to inaccessible properties. + * http://php.net/manual/en/language.oop5.overloading.php + * @param string name + * @param mixed value + * @return void + */ + public function __set(string $name , mixed $value) + { + } + + /** + * __get() is utilized for reading data from inaccessible properties. + * http://php.net/manual/en/language.oop5.overloading.php + * @param string name + * @return mixed + */ + public function __get(string $name) + { + } + + /** + * __isset() is triggered by calling isset() or empty() on inaccessible properties. + * http://php.net/manual/en/language.oop5.overloading.php + * @param string name + * @return bool + */ + public function __isset(string $name) + { + } + + /** + * __unset() is invoked when unset() is used on inaccessible properties. + * http://php.net/manual/en/language.oop5.overloading.php + * @param string name + * @return void + */ + public function __unset(string $name) + { + } + + /** + * __call is triggered when invoking inaccessible methods in an object context. + * http://php.net/manual/en/language.oop5.overloading.php + * @param string name + * @param array arguments + * @return mixed + */ + public function __call(string $name, array $arguments) + { + } + + /** + * __callStatic() is triggered when invoking inaccessible methods in a static context. + * http://php.net/manual/en/language.oop5.overloading.php + * @param string name + * @param array arguments + * @return mixed + */ + public static function __callStatic(string $name, array $arguments) + { + } + + /** + * http://php.net/manual/en/language.oop5.magic.php + * @return array + */ + public function __sleep() + { + } + + /** + * http://php.net/manual/en/language.oop5.magic.php + * @return void + */ + public function __wakeup() + { + } + + /** + * http://php.net/manual/en/language.oop5.magic.php + * @return string + */ + public function __toString() + { + } + + /** + * http://php.net/manual/en/language.oop5.magic.php + * @param Type + * @return mixed + */ + public function __invoke(Type $var = null) + { + } + + /** + * http://php.net/manual/en/language.oop5.magic.php + * @param array properties + * @return object + */ + public static function __set_state(array $properties) + { + } + + /** + * http://php.net/manual/en/language.oop5.magic.php + * @return array + */ + public function __debugInfo() + { + } + +} + +/** + * Every class that has implemented this interface need to have the same functions. + */ +interface InterfaceName +{ + + public function FunctionName(Type $var = null): Type; + +} + +/** + * Combination of class and interface. + */ +abstract class AbstractClassName +{ + + /** + * Classes extending this abstract class need to have this function. + * @param Type + * @return Type + */ + abstract function abstractFunction(Type $var = null): Type; + +} diff --git a/tools/docker.sh b/tools/docker.sh index 10bece1..3b87fca 100644 --- a/tools/docker.sh +++ b/tools/docker.sh @@ -27,10 +27,29 @@ docker run username/repository:tag # Run image from a registry ############################################################################## -docker-compose up -docker-compose up -d -docker-compose down -docker-compose logs +docker-compose up # Create and start containers +docker-compose up -d # Create and start containers in detached mode +docker-compose down # Stop and remove containers, networks, images, and volumes +docker-compose logs # View output from containers +docker-compose restart # Restart all service +docker-compose pull # Pull all image service +docker-compose build # Build all image service +docker-compose config # Validate and view the Compose file +docker-compose scale = # Scale special service(s) +docker-compose top # Display the running processes + + +############################################################################## +# DOCKER SERVICES +############################################################################## + + +docker service create # Create new service +docker service inspect --pretty # Display detailed information Service(s) +docker service ls # List Services +docker service ps # List the tasks of Services +docker service scale = # Scale special service(s) +docker service update # Update Service options ############################################################################## diff --git a/tools/vim.txt b/tools/vim.txt index cac6e7c..41e5a7d 100644 --- a/tools/vim.txt +++ b/tools/vim.txt @@ -86,7 +86,7 @@ R enter Insert mode, replacing characters rather than insertin J join line below to the current one cc change (replace) an entire line cw change (replace) to the end of word -c$ change (replace) to the end of line +C change (replace) to the end of line s delete character at cursor and substitute text S delete line at cursor and substitute text (same as cc) xp transpose two letters (delete and paste, technically) diff --git a/tools/xcode.txt b/tools/xcode.txt new file mode 100644 index 0000000..a26dcc9 --- /dev/null +++ b/tools/xcode.txt @@ -0,0 +1,106 @@ +############################################################################## +# XCODE CHEAT SHEET +# WEBSITE: https://developer.apple.com/xcode/ +# DOCUMENTATION: https://developer.apple.com/documentation/xcodekit +############################################################################## + + +############################################################################## +# SEARCH +############################################################################## + + +Cmd + F Find in File +Cmd + Option + F Find & Replace in File +Cmd + Shift + F Find in Project +Cmd + Option + Shift + F Find & Replace in Project + + +############################################################################## +# TABS +############################################################################## + + +Cmd + T New Tab +Cmd + } Previous Tab +Cmd + { Next Tab + + +############################################################################## +# NAVIGATION +############################################################################## + + +Cmd + Shift + O Quick Open +Cmd + J Focus to Editor +Cmd + Ctrl + UP Next Counterpart +Cmd + Ctrl + DOWN Previous Counterpart +Cmd + Ctrl + RIGHT Next Recent File +Cmd + Ctrl + LEFT Previous Recent File +Cmd + click Defination of Symbol +Cmd + L Go to Line +Cmd + Option + LEFT Fold Section +Cmd + Option + RIGHT Unfold Section + + +############################################################################## +# EDITING +############################################################################## + + +Cmd + Option + ENTER Show Assitant Editor +Cmd + ENTER Hide Assitant Editor +Ctrl + SPACE or ESC Toggle Completions +Cmd + ] Indent Section +Cmd + [ Outdent Section +Ctrl + i Fix Indentation +Cmd + / Comment / Uncomment +Cmd + Option + [ Move Line Up +Cmd + Option + ] Move Line Down + + +############################################################################## +# NAVIGATOR (LEFT PANEL) +############################################################################## + + +Cmd + 0 Show /Hide +Cmd + 1-8 Switch tabs +Option + click Open Assistant Editor +Shift + Option + click Decide where to Open +double click Open in New Window + + +############################################################################## +# DEBUGGING +############################################################################## + + +Cmd + Shift + Y Toggle Debug Area +Cmd + ' Next Issue +Cmd + " Previous Issue +Cmd + \ Add / Remove Breakpoint +Cmd + Y Active / Deactive Breakpoints +Cmd + K Clear Console + + +############################################################################## +# UTILITIES (RIGHT PANEL) +############################################################################## + + +Cmd + Option + 0 Show / Hide +Cmd + Option + 1-9 Go to Tab + + +############################################################################## +# DUBUGGING & RUN +############################################################################## + + +Cmd + B Build +Cmd + R Run +Cmd + . Stop +Cmd + Shift + B Analyze +Cmd + U Test +Cmd + Shift + K Clean