mirror of
https://github.com/LeCoupa/awesome-cheatsheets.git
synced 2026-01-30 07:08:01 -08:00
Compare commits
11 Commits
d3a79a0494
...
d4b4914eb1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d4b4914eb1 | ||
|
|
8557d4f3d8 | ||
|
|
f8d75a7ccf | ||
|
|
5ff48033e1 | ||
|
|
6c3b6ee90e | ||
|
|
7e9e6af408 | ||
|
|
0ee3753e2f | ||
|
|
cb9ca87a4b | ||
|
|
7f1144c56a | ||
|
|
8840648ff4 | ||
|
|
52d590f1c3 |
@@ -124,6 +124,7 @@ Feel free to take a look. You might learn new things. They have been designed to
|
||||
- [Nginx](tools/nginx.sh)
|
||||
- [PM2](tools/pm2.sh)
|
||||
- [Ubuntu](tools/ubuntu.sh)
|
||||
- [Firebase CLI](tools/firebase_cli.md)
|
||||
</details>
|
||||
|
||||
## 🙌🏼 How to Contribute?
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
// MAIN.
|
||||
|
||||
php artisan clear-compiled // Remove the compiled class file
|
||||
php artisan db // Start a new database CLI session
|
||||
php artisan docs // Access the Laravel documentation
|
||||
php artisan down // Put the application into maintenance mode
|
||||
php artisan dump-server // Start the dump server to collect dump information.
|
||||
php artisan env // Display the current framework environment
|
||||
@@ -43,6 +45,9 @@ php artisan config:clear // Remove the configuration cache file
|
||||
// DB
|
||||
|
||||
php artisan db:seed // Seed the database with records
|
||||
php artisan db:show // Display information about the given database
|
||||
php artisan db:table // Display information about the given database table
|
||||
php artisan db:wipe // Drop all tables, views, and types
|
||||
|
||||
// EVENT
|
||||
|
||||
@@ -54,9 +59,10 @@ php artisan key:generate // Set the application key
|
||||
|
||||
// MAKE
|
||||
|
||||
php artisan make:auth // Scaffold basic login and registration views and routes
|
||||
php artisan make:cast // Create a new custom Eloquent cast class
|
||||
php artisan make:channel // Create a new channel class
|
||||
php artisan make:command // Create a new Artisan command
|
||||
php artisan make:component // Create a new view component class
|
||||
php artisan make:controller // Create a new controller class
|
||||
php artisan make:event // Create a new event class
|
||||
php artisan make:exception // Create a new custom exception class
|
||||
@@ -74,6 +80,7 @@ php artisan make:provider // Create a new service provider class
|
||||
php artisan make:request // Create a new form request class
|
||||
php artisan make:resource // Create a new resource
|
||||
php artisan make:rule // Create a new validation rule
|
||||
php artisan make:scope // Create a new scope class
|
||||
php artisan make:seeder // Create a new seeder class
|
||||
php artisan make:test // Create a new test class
|
||||
|
||||
@@ -86,6 +93,10 @@ php artisan migrate:reset // Rollback all database migrations
|
||||
php artisan migrate:rollback // Rollback the last database migration
|
||||
php artisan migrate:status // Show the status of each migration
|
||||
|
||||
// MODEL
|
||||
php artisan model:prune // Prune models that are no longer needed
|
||||
php artisan model:show // Show information about an Eloquent model
|
||||
|
||||
// NOTIFICATIONS
|
||||
|
||||
php artisan notifications:table // Create a migration for the notifications table
|
||||
@@ -100,13 +111,19 @@ php artisan package:discover // Rebuild the cached package manifest
|
||||
|
||||
// QUEUE
|
||||
|
||||
php artisan queue:batches-table // Create a migration for the batches database table
|
||||
php artisan queue:clear // Delete all of the jobs from the specified queue
|
||||
php artisan queue:failed // List all of the failed queue jobs
|
||||
php artisan queue:failed-table // Create a migration for the failed queue jobs database table
|
||||
php artisan queue:flush // Flush all of the failed queue jobs
|
||||
php artisan queue:forget // Delete a failed queue job
|
||||
php artisan queue:listen // Listen to a given queue
|
||||
php artisan queue:monitor // Monitor the size of the specified queues
|
||||
php artisan queue:prune-batches // Prune stale entries from the batches database
|
||||
php artisan queue:prune-failed // Prune stale entries from the failed jobs table
|
||||
php artisan queue:restart // Restart queue worker daemons after their current job
|
||||
php artisan queue:retry // Retry a failed queue job
|
||||
php artisan queue:retry-batch // Retry the failed jobs for a batch
|
||||
php artisan queue:table // Create a migration for the queue jobs database table
|
||||
php artisan queue:work // Start processing jobs on the queue as a daemon
|
||||
|
||||
@@ -116,9 +133,26 @@ php artisan route:cache // Create a route cache file for faster route r
|
||||
php artisan route:clear // Remove the route cache file
|
||||
php artisan route:list // List all registered routes
|
||||
|
||||
// SAIL
|
||||
|
||||
php artisan sail:install // Install Laravel Sail's default Docker Compose file
|
||||
php artisan sail:publish // Publish the Laravel Sail Docker files
|
||||
|
||||
// SANCTUM
|
||||
|
||||
php artisan sanctum:prune-expired // Prune tokens expired for more than specified number of hours.
|
||||
|
||||
// SCHEDULE
|
||||
|
||||
php artisan schedule:clear-cache // Delete the cached mutex files created by scheduler
|
||||
php artisan schedule:list // List the scheduled commands
|
||||
php artisan schedule:run // Run the scheduled commands
|
||||
php artisan schedule:test // Run a scheduled command
|
||||
php artisan schedule:work // Start the schedule worker
|
||||
|
||||
// SCHEMA
|
||||
|
||||
php artisan schema:dump // Dump the given database schema
|
||||
|
||||
// SESSION
|
||||
|
||||
@@ -128,6 +162,10 @@ php artisan session:table // Create a migration for the session database
|
||||
|
||||
php artisan storage:link // Create a symbolic link from "public/storage" to "storage/app/public"
|
||||
|
||||
// STUD
|
||||
|
||||
php artisan stub:publish // Publish all stubs that are available for customization
|
||||
|
||||
// VENDOR
|
||||
|
||||
php artisan vendor:publish // Publish any publishable assets from vendor packages
|
||||
|
||||
479
languages/haskell.txt
Normal file
479
languages/haskell.txt
Normal file
@@ -0,0 +1,479 @@
|
||||
CHEATSHEET HASKELL
|
||||
|
||||
Use HASKELL
|
||||
|
||||
Documentation
|
||||
- Haskell API search: http://www.haskell.org/hoogle/
|
||||
- Haskell reference: ftp://ftpdeveloppez.com/cmaneu/langages/haskell/haskellreference.zip
|
||||
|
||||
Basics
|
||||
- Load file :load filename
|
||||
- Reload file :reload
|
||||
- Launch file editor with current file :edit
|
||||
- Get information about a function :info command
|
||||
|
||||
Comments
|
||||
|
||||
A single line comment starts with ‘--’ and extends to the end of the line.
|
||||
Multi-line comments start with ’{-’ and extend to ’-}’. Comments can be nested.
|
||||
|
||||
Reserved words
|
||||
|
||||
!
|
||||
'
|
||||
''
|
||||
-
|
||||
--
|
||||
-<
|
||||
-<<
|
||||
->
|
||||
::
|
||||
;
|
||||
<-
|
||||
,
|
||||
=
|
||||
=>
|
||||
>
|
||||
?
|
||||
#
|
||||
*
|
||||
@
|
||||
[|, |]
|
||||
\
|
||||
_
|
||||
`
|
||||
{, }
|
||||
{-, -}
|
||||
|
|
||||
~
|
||||
as
|
||||
case, of
|
||||
class
|
||||
data
|
||||
data family
|
||||
data instance
|
||||
default
|
||||
deriving
|
||||
deriving instance
|
||||
do
|
||||
forall
|
||||
foreign
|
||||
hiding
|
||||
if, then, else
|
||||
import
|
||||
infix, infixl, infixr
|
||||
instance
|
||||
let, in
|
||||
mdo
|
||||
module
|
||||
newtype
|
||||
proc
|
||||
qualified
|
||||
rec
|
||||
type
|
||||
type family
|
||||
type instance
|
||||
where
|
||||
|
||||
Data types
|
||||
|
||||
All the data types must start by a capital letter.
|
||||
|
||||
Int: Integer number with fixed precision
|
||||
Integer: Integer number with virtually no limits
|
||||
Float: Real floating point with single precision
|
||||
Double: Real floating point with double the precision
|
||||
Bool: Boolean
|
||||
Char: Character, have to placed between quotes
|
||||
String: A list of Chars
|
||||
|
||||
Type redefinition
|
||||
Type NewTypeName = TypeValue
|
||||
Example: Type String = [Char]
|
||||
|
||||
List & Numbers
|
||||
|
||||
[] – Empty list
|
||||
[1,2,3,4] – List of four numbers
|
||||
1 : 2 : 3 : 4 : [] - Write a lists using cons (:) and nil ([])
|
||||
[1..100] - List of number 1,2,3..,100
|
||||
[100..] - Infinite list of number 100,101,102,103,..
|
||||
[0,-1 ..] - Negative integers 0,-1,-2,..
|
||||
(h:q) - h stands for the first element of the list and q for the result
|
||||
(f:s:t:q) - f is the first element, s is the second elemnt, t is the third and q is the rest of the elements of the list.
|
||||
|
||||
It can be added the element e to the list l with e:l
|
||||
|
||||
Basic functions for lists
|
||||
|
||||
list1++list2 append two list
|
||||
list!!n return element n
|
||||
head takes a list and returns its head. The head of a list is basically its first element.
|
||||
tail takes a list and returns its tail. In other words, it chops off a list's head.
|
||||
last takes a list and returns its last element.
|
||||
init takes a list and returns everything except its last element.
|
||||
length takes a list and returns its length, obviously.
|
||||
null checks if a list is empty.
|
||||
reverse reverses a list.
|
||||
take takes number and a list. It extracts that many elements from the beginning of the list.
|
||||
drop works in a similar way as take, only it drops the number of elements from the beginning of a list.
|
||||
maximum takes a list of stuff that can be put in some kind of order and returns the biggest element.
|
||||
minimum returns the smallest.
|
||||
sum takes a list of numbers and returns their sum.
|
||||
product takes a list of numbers and returns their product.
|
||||
elem takes a thing and a list of things and tells us if that thing is an element of the list. It's usually called as an infix function because it's easier to read that way.
|
||||
|
||||
Function for infinite lists:
|
||||
|
||||
cycle: takes a list and cycles it into an infinite list. If you just try to display the result, it will go on forever so you have to slice it off somewhere.
|
||||
repeat: takes an element and produces an infinite list of just that element. It's like cycling a list with only one element.
|
||||
replicate: takes the number of the same element in a list.
|
||||
|
||||
List comprehension
|
||||
|
||||
List comprehension is the process of generating a list using a mathematical expression.
|
||||
|
||||
[body | generator]
|
||||
|
||||
Examples: [x*a | a <- [1..3]] = [2,4,6]
|
||||
[x*y | x <- [1..5], y <- [9..5] ]
|
||||
[x | x <- [1,10,14,16,18], x>5 ]
|
||||
|
||||
Tuples
|
||||
|
||||
(1,"a") - 2-element tuple of a number and a string
|
||||
(last, 4, 'b') - 3-element tuple of a function, a number and a character
|
||||
|
||||
Note that the empty tuple () is also a type which can only have a single value: ()
|
||||
|
||||
Basic functions for Tuples
|
||||
|
||||
fst: takes a pair and returns its first component.
|
||||
snd: takes a pair and returns its second component.
|
||||
zip: takes two lists and then zips them together into one list by joining the matching elements into pairs.
|
||||
|
||||
Note: these functions operate only on pairs. They won't work on triples, 4-tuples, 5-tuples, etc.
|
||||
|
||||
|
||||
Typeclasses
|
||||
|
||||
A typeclass is a sort of interface that defines some behaviour.
|
||||
If a type is a part of a typeclass, that means that it supports and implements the behavior the typeclass describes.
|
||||
If you come from OPP you can think of them kind of as Java interfaces, only better.
|
||||
|
||||
Everything before the => symbol is called a class constraint.
|
||||
|
||||
Eq is used for types that support equality testing. Eq class constraint for a type variable in a function, it uses == or /= somewhere inside its definition
|
||||
Ord is for types that have an ordering. Ord covers all the standard comparing functions such as >, <, >= and <=
|
||||
Show can be presented as strings. show takes a value whose type is a member of Show and presents it to us as a string.
|
||||
Read is sort of the opposite typeclass of Show. The read function takes a string and returns a type which is a member of Read.
|
||||
Enum members are sequentially ordered types, they can be enumerated. Types in this class: (), Bool, Char, Ordering, Int, Integer, Float and Double.
|
||||
Bounded members have an upper and a lower bound. All tuples are part of Bounded. Types in this class: Bool, Int and Char.
|
||||
Num is a numeric typeclass. Types in this class: Int, Integer, Float and Double.
|
||||
Integral is also a numeric typeclass. In this typeclass are Int and Integer.
|
||||
Floating includes only floating point numbers. Types in this class: Float and Double.
|
||||
|
||||
Functions
|
||||
|
||||
Functions are defined by declaring their name, any arguments, and an equals sign.
|
||||
|
||||
Declare a new function starting with explicit type declaration (optional)
|
||||
functionName :: inpuntType1 [ -> inputTypeN ] -> outputType
|
||||
|
||||
Declare a new function with pattern matching
|
||||
intToChar 1 = "One"
|
||||
intToChar 2 = "Two"
|
||||
|
||||
Declare a new function with guards
|
||||
intToChar x
|
||||
| x==1 = "One"
|
||||
| x==2 = "Two"
|
||||
|
||||
Declare a new function with guards and pattern matching
|
||||
allEmpty _ = falsePart
|
||||
allEmpty [] = truePart
|
||||
|
||||
alwaysEven n
|
||||
| otherwise = False
|
||||
| n 'div' 2 == 0 = True
|
||||
|
||||
Declare a new function with record syntax
|
||||
|
||||
Being this data type:
|
||||
data Color = C { red,
|
||||
, blue
|
||||
, yellow :: Int }
|
||||
|
||||
It can only be match on blue only:
|
||||
|
||||
isBlueZero (C { blue = 0 }) = True
|
||||
isBlueZero _ = False
|
||||
|
||||
Defining a PixelColor type and a function replace values with non-zero blue components.
|
||||
|
||||
Where and let
|
||||
|
||||
Let must always be followed by in. The in must appear in the sale column as the let keyword.
|
||||
In the following example, mult multiples its argument n by x, which passed to the original multiples.
|
||||
multiples x =
|
||||
let mult n = n * x
|
||||
in map mult [1..10]
|
||||
|
||||
|
||||
Where is similar to let. The scope of a where definition is the current function.
|
||||
In the following example, the function result below has a different meaning depending on the arguments given to the function strlen:
|
||||
strlen [] = result
|
||||
where result = "No string given!"
|
||||
strlen f = result ++ " characters long!"
|
||||
where result = show (length f)
|
||||
|
||||
|
||||
It is important to know that let ... in ... is an expression, that is, it can be written wherever expressions are allowed.
|
||||
In contrast, where is bound to a surrounding syntactic construct, like the pattern matching line of a function definition.
|
||||
|
||||
Advantage of where
|
||||
Suppose you have the function
|
||||
f :: s -> (a,s)
|
||||
f x = y
|
||||
where y = ... x ...
|
||||
and later you decide to put this into the Control.Monad.State monad.
|
||||
|
||||
However, transforming to
|
||||
f :: State s a
|
||||
f = State $ \x -> y
|
||||
where y = ... x ...
|
||||
will not work, because where refers to the pattern matching f =, where no x is in scope. In contrast, if you had started with let, then you wouldn't have trouble.
|
||||
f :: s -> (a,s)
|
||||
f x =
|
||||
let y = ... x ...
|
||||
in y
|
||||
|
||||
This is easily transformed to:
|
||||
f :: State s a
|
||||
f = State $ \x ->
|
||||
let y = ... x ...
|
||||
in y
|
||||
|
||||
Advantage of let
|
||||
|
||||
Because "where" blocks are bound to a syntactic construct, they can be used to share bindings between parts of a function that are not syntactically expressions.
|
||||
For example:
|
||||
f x
|
||||
| cond1 x = a
|
||||
| cond2 x = g a
|
||||
| otherwise = f (h x a)
|
||||
where
|
||||
a = w x
|
||||
|
||||
In expression style, you might use an explicit case:
|
||||
f x
|
||||
= let a = w x
|
||||
in case () of
|
||||
_ | cond1 x -> a
|
||||
| cond2 x -> g a
|
||||
| otherwise -> f (h x a)
|
||||
|
||||
or a functional equivalent:
|
||||
f x =
|
||||
let a = w x
|
||||
in select (f (h x a))
|
||||
[(cond1 x, a),
|
||||
(cond2 x, g a)]
|
||||
or a series of if-then-else expressions:
|
||||
f x
|
||||
= let a = w x
|
||||
in if cond1 x
|
||||
then a
|
||||
else if cond2 x
|
||||
then g a
|
||||
|
||||
|
||||
Anonymous Functions
|
||||
|
||||
They are functions without names and can be defined at any time like so.
|
||||
Example: \x -> x + 1
|
||||
|
||||
Case expressions
|
||||
|
||||
case is to a switch statement in C# and Java. However, it can match a pattern.
|
||||
Example:
|
||||
data Choices = First String | Second | Third | Fourth
|
||||
|
||||
case can be used to determine which choice was given
|
||||
|
||||
whichChoice ch =
|
||||
case ch of
|
||||
First _ -> "1st!"
|
||||
Second -> "2nd!"
|
||||
_ -> "Something else."
|
||||
|
||||
|
||||
Conditionals
|
||||
|
||||
Identify ==
|
||||
Non identify /n
|
||||
Comparatives where the type must a subclass of Ord <,>,<=,>=
|
||||
|
||||
The if statement has this “signature”: if-then-else :: Bool -> a -> a -> a
|
||||
|
||||
Maps and filters
|
||||
|
||||
map takes a function and a list and applies that function to every element in the list, producing a new list.
|
||||
Examples:
|
||||
map :: (a -> b) -> [a] -> [b]
|
||||
map _ [] = []
|
||||
map f (x:xs) = f x : map f xs
|
||||
|
||||
filter is a function that takes a predicate and nd a list and then returns the list of elements that satisfy the predicate
|
||||
Examples:
|
||||
filter :: (a -> Bool) -> [a] -> [a]
|
||||
filter _ [] = []
|
||||
filter p (x:xs)
|
||||
| p x = x : filter p xs
|
||||
| otherwise = filter p xs
|
||||
|
||||
Folds
|
||||
|
||||
foldl function folds the list up from the left side.
|
||||
foldr works in a similar way to the left fold, only the accumulator eats up the values from the right.
|
||||
|
||||
The foldl1 and foldr1 functions work much like foldl and foldr, only you don't need to provide them with an explicit starting value.
|
||||
|
||||
scanl and scanr are like foldl and foldr, only they report all the intermediate accumulator states in the form of a list.
|
||||
|
||||
Function application with $
|
||||
|
||||
The $ function has the lowest precedence and the function with $ is rigth-associate
|
||||
|
||||
Default
|
||||
|
||||
Default implementations can be given for function in a class.
|
||||
|
||||
The default is defined by giving a body to one of the members' functions.
|
||||
Example == can be defined in terms of /=:
|
||||
(==) a b = not (a/b)
|
||||
|
||||
Data
|
||||
|
||||
Algebraic data types can be declared as: data MyType = MyValue1 | MyValue2
|
||||
|
||||
Note that type and constructor names must start with a capital letter. It is a syntax error otherwise.
|
||||
|
||||
|
||||
Constructors with arguments
|
||||
|
||||
Constructors that take arguments can be declared, allowing more information to be stored.
|
||||
|
||||
data Point = TwoD Int Int
|
||||
| ThreeD Int Int Int
|
||||
|
||||
Notice that the arguments for each constructor are type names, not constructors.
|
||||
|
||||
Type and constructor names
|
||||
|
||||
Both names can be the same since they will never be used in a place that would cause confusion.
|
||||
data User = User String | Admin String
|
||||
|
||||
Using this type in a function makes difference clear:
|
||||
whatUser (User _) = "normal user"
|
||||
whatUser (Admin _) = "admin user"
|
||||
|
||||
Type Variables
|
||||
|
||||
Plymorphic data types are easy to be declared just by adding type varialbe in the declaration:
|
||||
data Slot a = Slot1 a | Empty1
|
||||
|
||||
It can also be mix type variable and specific types in constructors:
|
||||
data Slot2 a = Slot2 a Int | Empty2
|
||||
|
||||
Record syntax
|
||||
|
||||
Constructors arguments can also be declared by using record syntax which gives a name to each argument.
|
||||
For example:
|
||||
data Contact = Contact { ctName :: String
|
||||
, ctEmail :: String
|
||||
, ctPhone :: String }
|
||||
|
||||
Note: Multiple constructors of the same type can use the same accessor function name for values of the same type.
|
||||
|
||||
Deriving
|
||||
|
||||
The capabilities to convert to and from strings, compare
|
||||
for equality, or order in a sequence are defined as Typeclasses and Haskell provides the deriving keyboard to automatically implement the typeclass on the associated type supported which are: Eq, Read, Show, Ord, Enum, Ix, and
|
||||
Bounded.
|
||||
|
||||
Two forms of deriving are possible.
|
||||
|
||||
The first is used when a type only derives one class:
|
||||
data Priority = Low | Medium | High
|
||||
deriving Show
|
||||
|
||||
The second is used when multiple classes are derived:
|
||||
data Alarm = Soft | Loud | Deafening
|
||||
deriving (Read, Show)
|
||||
|
||||
Class constraint
|
||||
|
||||
In any case, the syntax used is:
|
||||
data (Num a) => SomeNumber a = Two a a
|
||||
| Three a a a
|
||||
|
||||
This declares a type SomeNumber which has one type variable argument.
|
||||
Valid types are those in the Num class.
|
||||
|
||||
Do
|
||||
|
||||
Do indicates that the code to follow will be in a monadic context.
|
||||
Statements are separated by newlines, the assignment is indicated by <, and a let form is introduced which does not require the in the keyboard.
|
||||
|
||||
If, Then, Else
|
||||
|
||||
This function tests if the string is given starts with a lower case letter and, if so, convert it to upper case:
|
||||
|
||||
sentenceCase (s:rest) =
|
||||
if isLower s
|
||||
then toUpper s : rest
|
||||
else s : result
|
||||
sentenceCase _ = []
|
||||
|
||||
Deconstruction
|
||||
|
||||
The left-hand side of a let definition can also destructive its argument, in case sub-components are to be accessed.
|
||||
Examples:
|
||||
firstThree str =
|
||||
let (a:b:c:_) = str
|
||||
in "Initial three characters are: " ++
|
||||
show a ++ ", " ++
|
||||
show b ++ ", and " ++
|
||||
show c
|
||||
|
||||
Note that this is different than the following, which only works if the string has exactly three characters:
|
||||
onlyThree str =
|
||||
let (a:b:c:[]) = str
|
||||
in "The characters given are: " ++
|
||||
show a ++ ", " ++
|
||||
show b ++ ", and " ++
|
||||
show c
|
||||
|
||||
Modules
|
||||
|
||||
A module is a compilation unit which export functions, tyñes, classes, instances, and other modules.
|
||||
To make a Haskell file a module just add at the top of it:
|
||||
module MyModule where
|
||||
|
||||
Imports
|
||||
|
||||
To import everything (functions, data types and constructors, class declarations, and even other modules imported) exported by a library, just use the module name:
|
||||
import Text.Read
|
||||
|
||||
To import selectively:
|
||||
import Text.Read (readParen, lex)
|
||||
|
||||
To import data types and no constructors:
|
||||
import Text.Read (Lexeme)
|
||||
|
||||
To import data types and one or more constructors explicitly
|
||||
import Text.Read (Lexeme(Ident, Symbol))
|
||||
|
||||
To import all constructors for a given type:
|
||||
import Text.Read (Lexeme())
|
||||
344
languages/java.txt
Normal file
344
languages/java.txt
Normal file
@@ -0,0 +1,344 @@
|
||||
Java Cheatsheet
|
||||
|
||||
HELLO WORLD
|
||||
|
||||
//Text file name HelloWorld.java
|
||||
public class HelloWorld {
|
||||
// main() is the method
|
||||
public static void main (String[] arfs)
|
||||
//Prints "Hello World" in the terminal window.
|
||||
System.out.pritn("Hello World");
|
||||
}
|
||||
|
||||
DATA TYPES
|
||||
|
||||
Type Set of values Values Operators
|
||||
int integers between -2^31 and + (2^31)-1 + - * / %
|
||||
double floating-point numbers real numbers + - * /
|
||||
boolean boolean values true or false && || !
|
||||
char characters
|
||||
String sequences of characters
|
||||
|
||||
DECLARATION AND ASSIGNMENT STATEMENTS
|
||||
|
||||
//Declaration statement
|
||||
int a,b;
|
||||
|
||||
//Assignment statement
|
||||
a = 13212; //a is the variable name; 13212 is the literal which is assign to the variable a
|
||||
|
||||
//Initialization statement
|
||||
int c = a + b;
|
||||
|
||||
COMPARISON OPERATORS
|
||||
|
||||
Operation Meaning
|
||||
== equal
|
||||
!= not equal
|
||||
< less than
|
||||
> greater than
|
||||
<= less than or equal
|
||||
>= greater than or equal
|
||||
|
||||
|
||||
PRINTING
|
||||
|
||||
void System.out.print(String s) //print s
|
||||
void System.out.println(String s) //print s, followed by a newline
|
||||
void System.out.println() //print a newline
|
||||
|
||||
PARSING COMMAND-LINE ARGUMENTS
|
||||
|
||||
int Integer.parseInt(String s) //convert s to an int value
|
||||
double Double.parseDouble(String) //convert s to a double value
|
||||
long Long.parseLong(String s) // convert s to a long value
|
||||
|
||||
MATH LIBRARY
|
||||
|
||||
Public Class Math
|
||||
double abs(double a) // absolute value of a
|
||||
double max(double a, double b) //maximum of a and b
|
||||
double min(double a, dobule a) //minimum of a and b
|
||||
double sin(double theta) //sine of theta
|
||||
double cos(double theta) //cosine of theta
|
||||
double tan(double theta) //tangent of theta
|
||||
double toRadians(double degrees) // convert angle from degrees to radians
|
||||
double toDegreestouble radians) // convert angle from radians to degrees
|
||||
double exp(doube a) // exponential (e^a)
|
||||
double pow(double a, double p) //raise a to the bth power (a^b)
|
||||
double random() //random in [0,1)
|
||||
double sqrt(double a) //square root of a
|
||||
|
||||
|
||||
EXAMPLES OF TYPE CONVERSION
|
||||
|
||||
Expression Expression type Expression value
|
||||
(1 + 2 + 3 + 4) / 4.0 double 2.5
|
||||
Math.sqrt(4) double 2.0
|
||||
"123343" + 99 String "12334399"
|
||||
11 * 0.25 double 2.75
|
||||
(int) 11 * 0.25 double 2.75
|
||||
11 * (int) 0.25 int 0
|
||||
(int) (11 * 0.25) int 2
|
||||
|
||||
|
||||
ANATOMY OF AN IF STATEMENT
|
||||
|
||||
if (x>y) { // x > y is the boolean expression
|
||||
//Sequence of statements
|
||||
x = y;
|
||||
}
|
||||
|
||||
IF AND IF-ELSE STATEMENT
|
||||
|
||||
if (BOOLEAN EXPRESSION) {
|
||||
//Sequence of statements
|
||||
} else {
|
||||
//Sequence of statements
|
||||
}
|
||||
|
||||
ANATOMY OF A WHILE LOOP
|
||||
|
||||
//Initialization is a separate statement
|
||||
int power = 1;
|
||||
|
||||
while ( power <= n/2 ) // power <= n/2 is an example of the loop-continuation condition
|
||||
{
|
||||
//Statements
|
||||
}
|
||||
|
||||
ANATOMY OF A WHILE LOOP
|
||||
|
||||
//Initialize another variable in a separate statement
|
||||
int power = 1;
|
||||
|
||||
for (declare and initialize a loop control variable; loop-continuation condition/s; increment or decrement of the variable of control)
|
||||
{
|
||||
//Statement
|
||||
}
|
||||
|
||||
Example:
|
||||
for (int i = 0; i <= n; i++) {
|
||||
//Statement
|
||||
}
|
||||
|
||||
DO-WHILE LOOP
|
||||
|
||||
do{
|
||||
//Statement
|
||||
} while(lopp-continuation condition);
|
||||
|
||||
SWITCH STATEMENT
|
||||
|
||||
switch (VARIABLE TO EVALUATE ITS VALUE) {
|
||||
case value: Statement; break;
|
||||
...
|
||||
default: Statement; break;
|
||||
}
|
||||
|
||||
Example:
|
||||
|
||||
int month = 8;
|
||||
String monthString;
|
||||
switch (month) {
|
||||
case 1: monthString = "January";
|
||||
break;
|
||||
case 2: monthString = "February";
|
||||
break;
|
||||
case 3: monthString = "March";
|
||||
break;
|
||||
case 4: monthString = "April";
|
||||
break;
|
||||
case 5: monthString = "May";
|
||||
break;
|
||||
case 6: monthString = "June";
|
||||
break;
|
||||
case 7: monthString = "July";
|
||||
break;
|
||||
case 8: monthString = "August";
|
||||
break;
|
||||
case 9: monthString = "September";
|
||||
break;
|
||||
case 10: monthString = "October";
|
||||
break;
|
||||
case 11: monthString = "November";
|
||||
break;
|
||||
case 12: monthString = "December";
|
||||
break;
|
||||
default: monthString = "Invalid month";
|
||||
break;
|
||||
}
|
||||
|
||||
ARRAY DECLARATION
|
||||
|
||||
int[] ai; // array of int
|
||||
short[][] as; // array of array of short
|
||||
short s, // scalar short
|
||||
aas[][]; // array of array of short
|
||||
Object[] ao, // array of Object
|
||||
otherAo; // array of Object
|
||||
Collection<?>[] ca; // array of Collection of unknown type
|
||||
|
||||
DECLARATION OF ARRAY VARIABLE
|
||||
|
||||
Exception ae[] = new Exception[3];
|
||||
Object aao[][] = new Exception[2][3];
|
||||
int[] factorial = { 1, 1, 2, 6, 24, 120, 720, 5040 };
|
||||
char ac[] = { 'n', 'o', 't', ' ', 'a', ' ',
|
||||
'S', 't', 'r', 'i', 'n', 'g' };
|
||||
String[] aas = { "array", "of", "String", };
|
||||
|
||||
FUNCTIONS
|
||||
|
||||
public static double sum (int a, int b) { //double is the return type, sum is the method's name, a and b are two arguments of type int;
|
||||
int result; //local variable
|
||||
result = a + b;
|
||||
return result;//return statement;
|
||||
}
|
||||
|
||||
USING AN OBJECT
|
||||
|
||||
//Declare a a variable, object name
|
||||
String s;
|
||||
|
||||
//Invoke a contructor to create an object
|
||||
s = new String ("Hello World");
|
||||
|
||||
//Invoke an instance method that operates on the object's value
|
||||
char c = s.chartAt(4);
|
||||
|
||||
INSTANCE VARIABLES
|
||||
|
||||
public class Charge {
|
||||
//Instance variable declarations
|
||||
private final double rx, ry;
|
||||
private final double q;
|
||||
}
|
||||
|
||||
//private, final and public are access modifiers
|
||||
|
||||
|
||||
CONSTRUCTORS
|
||||
|
||||
//A class contains constructors that are invoked to create objects from the class blueprint.
|
||||
//Constructor declarations look like method declarations—except that they use the name of the class and have no return type
|
||||
|
||||
public Bicycle(int startCadence, int startSpeed, int startGear) {
|
||||
gear = startGear;
|
||||
cadence = startCadence;
|
||||
speed = startSpeed;
|
||||
}
|
||||
|
||||
DECLARING CLASSESS
|
||||
|
||||
|
||||
class MyClass {
|
||||
// field, constructor, and
|
||||
// method declarations
|
||||
}
|
||||
|
||||
Example:
|
||||
|
||||
public class Bicycle {
|
||||
// the Bicycle class has
|
||||
// three fields
|
||||
public int cadence;
|
||||
public int gear;
|
||||
public int speed;
|
||||
// the Bicycle class has
|
||||
// one constructor
|
||||
public Bicycle(int startCadence, int startSpeed, int startGear) {
|
||||
gear = startGear;
|
||||
cadence = startCadence;
|
||||
speed = startSpeed;
|
||||
}
|
||||
// the Bicycle class has
|
||||
// four methods
|
||||
public void setCadence(int newValue) {
|
||||
cadence = newValue;
|
||||
}
|
||||
public void setGear(int newValue) {
|
||||
gear = newValue;
|
||||
}
|
||||
public void applyBrake(int decrement) {
|
||||
speed -= decrement;
|
||||
}
|
||||
public void speedUp(int increment) {
|
||||
speed += increment;
|
||||
}
|
||||
|
||||
DECLARING CLASSESS IMPLEMENTATING AN INTERFACE
|
||||
|
||||
class MyClass extends MySuperClass implements YourInterface {
|
||||
// field, constructor, and
|
||||
// method declarations
|
||||
}
|
||||
|
||||
// MyClass is a subclass of MySuperClass and that it implements the YourInterface interface.
|
||||
|
||||
|
||||
STACK DATA TYPE
|
||||
|
||||
public class Stack<Item> implements Iterable <Item>
|
||||
|
||||
Stack() //create an empty stack
|
||||
boolean isEmpthy() //return if the stack empthy
|
||||
void push(Item item) // push an item onto the stack
|
||||
Item pop() //return and remove the item that was inserted most recently
|
||||
int size() //number of item on stack
|
||||
|
||||
QUEUE DATA TYPE
|
||||
|
||||
public class Queue<Item> implements Iterable<Item>
|
||||
|
||||
Queue() //create an emptyh queue
|
||||
boolean isEmpthy() //return if the queue empthy
|
||||
void enqueue(Item item) // insert an item onto queue
|
||||
Item dequeue() //return and remove the item that was inserted least recently
|
||||
int size() //number of item on queue
|
||||
|
||||
ITERABLE
|
||||
|
||||
//import Iterator
|
||||
import java.util.Iterator;
|
||||
|
||||
public class Queue<Item> implements Iterable <Item> {
|
||||
|
||||
//FIFO queue
|
||||
private Node first;
|
||||
private Node last;
|
||||
private class Node {
|
||||
Item item;
|
||||
Node next;
|
||||
}
|
||||
|
||||
public void enqueue (Item item)
|
||||
...
|
||||
|
||||
public Item dequeue()
|
||||
...
|
||||
|
||||
}
|
||||
|
||||
SYMBOL TABLE DATA TYPE
|
||||
|
||||
public class ST<Key extends Comparable<Key>, Value>
|
||||
|
||||
ST() //create and empthy symbol table
|
||||
void put(Key key, Value val) //associate val with key
|
||||
Value get(Key key) //value associated with key
|
||||
void remove(Key key) //remove key (and its associated value)
|
||||
boolean contains (Key key) //return if there is a value associated with key
|
||||
int size() //number of key-value pairs
|
||||
Iterable<Key> keys() // all keys in the symbol table
|
||||
|
||||
SET DATA TYPE
|
||||
|
||||
public class SET<Key extends Comparable<Key>> implements Iterable<Key>
|
||||
SET() //create an empthy set
|
||||
boolean isEmpthy() //return if the set is empthy
|
||||
void add (Key key) //add key to the set
|
||||
void remove(Key key) //remove key from set
|
||||
boolean contains(Key key) //return if the key is in the set
|
||||
int size() //number of elements in set
|
||||
|
||||
@@ -72,6 +72,7 @@ array.splice(start, deleteCount, item1, item2, ...) // Adds and/or removes elem
|
||||
arr.unshift([element1[, ...[, elementN]]]) // Adds one or more elements to the front of an array and returns the new length of the array.
|
||||
|
||||
// Instance: accessor methods
|
||||
arr.at(index) // Returns the element at the specified index in the array.
|
||||
arr.concat(value1[, value2[, ...[, valueN]]]) // Returns a new array comprised of this array joined with other array(s) and/or value(s).
|
||||
arr.includes(searchElement, fromIndex) // Determines whether an array contains a certain element, returning true or false as appropriate.
|
||||
arr.indexOf(searchElement[, fromIndex]) // Returns the first (least) index of an element within the array equal to the specified value, or -1 if none is found.
|
||||
|
||||
140
tools/firebase_cli.md
Normal file
140
tools/firebase_cli.md
Normal file
@@ -0,0 +1,140 @@
|
||||
# Firebase CLI Guide
|
||||
|
||||
Firebase CLI (Command Line Interface) is a powerful tool that allows developers to interact with Firebase services and manage their Firebase projects directly from the command line. It provides a convenient and efficient way to deploy projects, manage databases, configure authentication, and more, streamlining the development and deployment processes.
|
||||
|
||||
## Installation
|
||||
|
||||
To use the Firebase CLI, you need to have Node.js and npm (Node Package Manager) installed on your system. Follow the steps below to install the Firebase CLI:
|
||||
|
||||
1. Install Node.js and npm by downloading the installer from the [official Node.js website](https://nodejs.org/en/download/) and following the installation instructions for your operating system.
|
||||
|
||||
2. Once Node.js and npm are installed, open your terminal or command prompt and run the following command to install the Firebase CLI globally:
|
||||
|
||||
```
|
||||
npm install -g firebase-tools
|
||||
```
|
||||
|
||||
This command will download and install the Firebase CLI package from the npm registry.
|
||||
|
||||
3. After the installation is complete, you can verify that the Firebase CLI is installed correctly by running the following command:
|
||||
|
||||
```
|
||||
firebase --version
|
||||
```
|
||||
|
||||
If the installation was successful, you will see the version number of the Firebase CLI printed in the terminal.
|
||||
|
||||
Congratulations! You have successfully installed the Firebase CLI.
|
||||
|
||||
## Usage
|
||||
|
||||
The Firebase CLI allows you to interact with Firebase services and manage your Firebase projects from the command line. Here are some common tasks you can perform using the Firebase CLI:
|
||||
|
||||
- Initialize a new Firebase project in your current directory.
|
||||
- Deploy your Firebase project to Firebase hosting.
|
||||
- Manage Firebase Authentication, Realtime Database, Cloud Firestore, Cloud Functions, and other Firebase services.
|
||||
- Configure Firebase project settings.
|
||||
- Interact with Firebase emulators for local development and testing.
|
||||
|
||||
To use the Firebase CLI, open your terminal or command prompt and run the `firebase` command followed by the desired command and options.
|
||||
|
||||
Here's an example of the basic usage:
|
||||
|
||||
```
|
||||
firebase <command> [options]
|
||||
```
|
||||
|
||||
Replace `<command>` with the specific Firebase command you want to execute, and `[options]` with any additional options or flags required for that command.
|
||||
|
||||
For more detailed usage information, you can run the following command:
|
||||
|
||||
```
|
||||
firebase help
|
||||
```
|
||||
|
||||
This command will display the available Firebase commands and provide detailed information about each command.
|
||||
|
||||
## Commands
|
||||
|
||||
Here are the commonly used Firebase CLI commands along with a brief explanation, syntax, and an example for each command:
|
||||
|
||||
- `firebase init`: Initializes a new Firebase project in the current directory.
|
||||
|
||||
- Syntax: `firebase init [options]`
|
||||
- Example: `firebase init hosting` initializes Firebase Hosting for the current project.
|
||||
|
||||
- `firebase deploy`: Deploys your Firebase project to Firebase hosting or other Firebase services.
|
||||
|
||||
- Syntax: `firebase deploy [options]`
|
||||
- Example: `firebase deploy --only hosting` deploys only the Firebase Hosting content.
|
||||
|
||||
- `firebase serve`: Starts local development servers and Firebase emulators.
|
||||
|
||||
- Syntax: `firebase serve [options]`
|
||||
- Example: `firebase serve --only functions,hosting` starts the Firebase emulators for functions and hosting.
|
||||
|
||||
- `firebase login`: Authenticates the Firebase CLI with your Firebase account.
|
||||
|
||||
- Syntax: `firebase login [options]`
|
||||
- Example: `firebase login --no-localhost` initiates an interactive login session without connecting to localhost.
|
||||
|
||||
- `firebase logout`: Logs out from the Firebase CLI.
|
||||
|
||||
- Syntax: `firebase logout [options]`
|
||||
- Example: `firebase logout` logs out the currently authenticated user.
|
||||
|
||||
- `firebase use`: Sets the active Firebase project for the current directory.
|
||||
|
||||
- Syntax: `firebase use <project_id> [options]`
|
||||
- Example: `firebase use my-project` sets "my-project" as the active Firebase project.
|
||||
|
||||
- `firebase functions`: Interacts with Firebase Cloud Functions.
|
||||
|
||||
- Syntax: `firebase functions:command [options]`
|
||||
- Example: `firebase functions:delete [function_name]` deletes all functions that match the specified name in all regions.
|
||||
|
||||
- `firebase database`: Interacts with Firebase Realtime Database.
|
||||
|
||||
- Syntax: `firebase database:command [options]`
|
||||
- Example: `firebase database:get /users` retrieves data from the Firebase Realtime Database.
|
||||
|
||||
- `firebase firestore`: Interacts with Firebase Cloud Firestore.
|
||||
|
||||
- Syntax: `firebase firestore:command [options]`
|
||||
- Example: `firebase firestore:delete collection/document` deletes a document from the Firestore database.
|
||||
|
||||
- `firebase auth`: Interacts with Firebase Authentication.
|
||||
|
||||
- Syntax: `firebase auth:command [options]`
|
||||
- Example: `firebase auth:export users.csv` exports user data to a CSV file.
|
||||
|
||||
- `firebase hosting`: Interacts with Firebase Hosting.
|
||||
|
||||
- Syntax: `firebase hosting:command [options]`
|
||||
- Example: `firebase hosting:disable` disables Firebase Hosting for the current project.
|
||||
|
||||
- `firebase remoteconfig`: Interacts with Firebase Remote Config.
|
||||
|
||||
- Syntax: `firebase remoteconfig:command [options]`
|
||||
- Example: `firebase remoteconfig:get template` retrieves the Remote Config template.
|
||||
|
||||
- `firebase ext`: Interacts with Firebase Extensions.
|
||||
|
||||
- Syntax: `firebase ext:command [options]`
|
||||
- Example: `firebase ext:install firebase/delete-user-data` installs the Firebase Extension named "firebase/delete-user-data".
|
||||
|
||||
- `firebase appdistribution`: Interacts with Firebase App Distribution.
|
||||
|
||||
- Syntax: `firebase appdistribution:command [options]`
|
||||
- Example: `firebase appdistribution:testers:add` Adds testers to the project.
|
||||
|
||||
- `firebase use --add`: Adds an existing Firebase project to the current directory
|
||||
|
||||
- Syntax: `firebase use --add`
|
||||
- Example: `firebase use --add` interactively adds an existing Firebase project.
|
||||
|
||||
- `firebase projects:create`: Creates a new Firebase project.
|
||||
- Syntax: `firebase projects:create [options]`
|
||||
- Example: `firebase projects:create --display-name "My Project"` creates a new Firebase project with the given display name.
|
||||
|
||||
These are just a few examples of the available commands. You can explore more commands and their options by running `firebase help` or visiting the [official Firebase CLI documentation](https://firebase.google.com/docs/cli).
|
||||
Reference in New Issue
Block a user