Compare commits

..

2 Commits

Author SHA1 Message Date
Kelvin Anigboro
0f3b49da86 Merge 02d739afa8 into 0931c8fc67 2024-07-09 00:36:15 -04:00
Kelvin Anigboro
02d739afa8 Add Comprehensive TypeScript Cheatsheet with Intro and Installation Guide 2024-01-01 18:58:34 +00:00
11 changed files with 325 additions and 105 deletions

View File

@@ -88,7 +88,7 @@ CHEATSHEET C#
string newStr = oldStr.Replace("old","new"); string newStr = oldStr.Replace("old","new");
//IndexOf //IndexOf
//Finds the first occurrence of a string in a larger string //Finds the first ocurrence of a string in a larger string
//Returns -1 if the string is not found //Returns -1 if the string is not found
String.IndexOf(val, start, num) String.IndexOf(val, start, num)
val - string to search for val - string to search for
@@ -102,7 +102,7 @@ CHEATSHEET C#
String.Split(Char[]); String.Split(Char[]);
//ToCharArray //ToCharArray
//Places selected characters in a string in a char array //Places selected characteres in a string in a char array
String str = "AaBbCcDd"; String str = "AaBbCcDd";
//create array of 8 vowels //create array of 8 vowels
var chars = str.ToCharArray(); var chars = str.ToCharArray();
@@ -135,7 +135,7 @@ CHEATSHEET C#
6.1 TimeSpan Constructor 6.1 TimeSpan Constructor
TimeSpan(hour, minute, sec) TimpeSpan(hour, minute, sec)
TimeSpan timeS = new TimeSpan(10, 14, 50); TimeSpan timeS = new TimeSpan(10, 14, 50);
TimeSpan timeS_Hours = TimeSpan.FromDays(3640); TimeSpan timeS_Hours = TimeSpan.FromDays(3640);
@@ -144,8 +144,8 @@ CHEATSHEET C#
Format item syntax: {index[,alignment][:format string]} Format item syntax: {index[,alignment][:format string]}
index - Specifies element in list of values to which format is applied index - Specifies element in list of values to which format is applied
alignment - Indicates minimum width (in characters) to display value aligment - Indicates minimun width (in characters) to display value
format string - Contains the code which specifies the format of the displayed value format string - Contains the code which specififes the format of the displayed value
7.1 Numeric 7.1 Numeric
@@ -293,7 +293,7 @@ CHEATSHEET C#
[access modifier] className (parameters) [:initializer] [access modifier] className (parameters) [:initializer]
initializer -base calls constructor in base class. initializer -base calls constructor in base class.
this calls constructor within class. this calls constuctor within class.
public class nameClass : Initializer { public class nameClass : Initializer {
public className(dataType param1 , dataType param2, ...) : base(param1, param2) public className(dataType param1 , dataType param2, ...) : base(param1, param2)
@@ -313,8 +313,8 @@ CHEATSHEET C#
abstract must be implemented by subclass abstract must be implemented by subclass
Passing parameters: Passing parameters:
1. By default, parameters are passed by value 1. By default, parametres are passed by value
2. Passing by reference: ref, in and out modifiers 2. Passing by reference: ref, in and out modifers
To pass a parameter by reference with the intent of changing the value, use the ref, or out keyword. To pass by reference with the intent of avoiding copying but not changing the value, use the in modifier To pass a parameter by reference with the intent of changing the value, use the ref, or out keyword. To pass by reference with the intent of avoiding copying but not changing the value, use the in modifier

View File

@@ -524,14 +524,14 @@ Cyan='\033[0;36m' # Cyan
White='\033[0;97m' # White White='\033[0;97m' # White
# Additional colors # Additional colors
LGrey='\033[0;37m' # Light Gray LGrey='\033[0;37m' # Ligth Gray
DGrey='\033[0;90m' # Dark Gray DGrey='\033[0;90m' # Dark Gray
LRed='\033[0;91m' # Light Red LRed='\033[0;91m' # Ligth Red
LGreen='\033[0;92m' # Light Green LGreen='\033[0;92m' # Ligth Green
LYellow='\033[0;93m'# Light Yellow LYellow='\033[0;93m'# Ligth Yellow
LBlue='\033[0;94m' # Light Blue LBlue='\033[0;94m' # Ligth Blue
LPurple='\033[0;95m'# Light Purple LPurple='\033[0;95m'# Light Purple
LCyan='\033[0;96m' # Light Cyan LCyan='\033[0;96m' # Ligth Cyan
# Bold # Bold

View File

@@ -397,8 +397,8 @@ d, t := doubleAndTriple(5)
_, t := doubleAndTriple(3) _, t := doubleAndTriple(3)
// t = 9 // t = 9
// Functions can defer commands. Deferred commands are // Functions can defer commands. Defered commands are
// ran in a stack order after the execution and // runned in a stack order after the execution and
// returning of a function // returning of a function
var aux = 0 var aux = 0
@@ -488,7 +488,7 @@ person3.Age // 0
## Maps ## Maps
Maps are data structures that holds values assigned to a key. Maps are data structures that holds values assigneds to a key.
```go ```go
// Declaring a map // Declaring a map
@@ -508,7 +508,7 @@ newYork // "EUA"
// Delete // Delete
delete(cities, "NY") delete(cities, "NY")
// Check if a key is set // Check if a key is setted
value, ok := cities["NY"] value, ok := cities["NY"]
ok // false ok // false
value // "" value // ""

View File

@@ -308,7 +308,7 @@ for(dataType item : array) {
//Declare a variable, object name //Declare a variable, object name
String s; String s;
//Invoke a constructor to create an object //Invoke a contructor to create an object
s = new String ("Hello World"); s = new String ("Hello World");
//Invoke an instance method that operates on the object's value //Invoke an instance method that operates on the object's value

View File

@@ -95,9 +95,3 @@ arr.reduce(callback[, initialValue]) // Apply a function against
arr.reduceRight(callback[, initialValue]) // Apply a function against an accumulator and each value of the array (from right-to-left) as to reduce it to a single value. arr.reduceRight(callback[, initialValue]) // Apply a function against an accumulator and each value of the array (from right-to-left) as to reduce it to a single value.
arr.some(callback[, initialValue]) // Returns true if at least one element in this array satisfies the provided testing function. arr.some(callback[, initialValue]) // Returns true if at least one element in this array satisfies the provided testing function.
arr.values() // Returns a new Array Iterator object that contains the values for each index in the array. arr.values() // Returns a new Array Iterator object that contains the values for each index in the array.
// String methods
String.charAt(index) // Returns the character at the specified index in a string.
String.indexOf(character) // Returns the index of the first occurrence of a specified value in a string.
String.substring(starting_index, ending_index) // Returns a new string that is a subset of the original string.
String.substring(starting_index) // Returns a substring from starting index to last index of string.

View File

@@ -1,8 +1,8 @@
<?php <?php
// Exit the file, string inside get's echo'ed // Exit the file, string inside get's echo'ed
die("This file is not meant to be ran. ¯\_(ツ)_/¯"); die("This file is not ment to be ran. ¯\_(ツ)_/¯");
exit("This file is not meant to be ran. ¯\_(ツ)_/¯"); exit("This file is not ment to be ran. ¯\_(ツ)_/¯");
/** /**
* Printing * Printing
@@ -17,7 +17,7 @@ var_dump($arr); // Print anything, with type hints for any value and sizes
$string = 'Awesome cheatsheets'; $string = 'Awesome cheatsheets';
str_contains($string, 'cheat'); // Find if the string contains the specified string (PHP >= 8.0) str_contains($string, 'cheat'); // Find if the string contains the specified string (PHP >= 8.0)
str_replace('Awesome', 'Bonjour', $string); // Replace all occurrence str_replace('Awesome', 'Bonjour', $string); // Replace all occurence
strcmp($string, 'Awesome cheatsheets'); // Compare two strings strcmp($string, 'Awesome cheatsheets'); // Compare two strings
strpos($string, 'a', 0); // Get position in the string strpos($string, 'a', 0); // Get position in the string
str_split($string, 2); // Split the string str_split($string, 2); // Split the string
@@ -541,7 +541,7 @@ u Pattern is treated as UTF-8
\w Any "word" character (a-z 0-9 _) \w Any "word" character (a-z 0-9 _)
\W Any non "word" character \W Any non "word" character
\s Whitespace (space, tab CRLF) \s Whitespace (space, tab CRLF)
\S Any non whitespace character \S Any non whitepsace character
\d Digits (0-9) \d Digits (0-9)
\D Any non digit character \D Any non digit character
. (Period) - Any character except newline . (Period) - Any character except newline

View File

@@ -71,7 +71,7 @@
| import | import libraries/modules/packages | import | | import | import libraries/modules/packages | import |
| from | import specific function/classes from modules/packages | import | | from | import specific function/classes from modules/packages | import |
| try | this block will be tried to get executed | exception handling | | try | this block will be tried to get executed | exception handling |
| except | is any exception/error has occurred it'll be executed | exception handling | | except | is any exception/error has occured it'll be executed | exception handling |
| finally | It'll be executed no matter exception occurs or not | exception handling | | finally | It'll be executed no matter exception occurs or not | exception handling |
| raise | throws any specific error/exception | exception handling | | raise | throws any specific error/exception | exception handling |
| assert | throws an AssertionError if condition is false | exception handling | | assert | throws an AssertionError if condition is false | exception handling |

227
languages/typescript.sh Normal file
View File

@@ -0,0 +1,227 @@
# *****************************************************************************
# Introduction to TypeScript
# *****************************************************************************
# What is TypeScript?
# TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale.
# It's a superset of JavaScript, which means all JavaScript code is valid TypeScript, but TypeScript has additional features like static typing, interfaces, and generics.
# Why Use TypeScript?
# - Provides type safety on top of the JavaScript, reducing runtime errors.
# - Makes the code more readable and maintainable.
# - Offers great tooling support with IntelliSense in popular editors.
# - Facilitates easier refactoring and debugging.
# *****************************************************************************
# Installing TypeScript
# *****************************************************************************
# Prerequisites:
# - Ensure Node.js is installed on your system. If not, download and install it from https://nodejs.org/
# Installation:
# - TypeScript can be installed as a Node.js package globally or in your project using npm (Node Package Manager).
# - To install TypeScript globally, use the following command in your terminal:
npm install -g typescript
# Checking Installation:
# - To verify that TypeScript has been installed correctly, you can check its version:
tsc --version
# Compiling TypeScript to JavaScript:
# - Once installed, you can compile .ts files to .js using the TypeScript compiler. For example:
tsc hello.ts
# *****************************************************************************
# Basic Syntax and Data Types
# *****************************************************************************
// Boolean type
let isDone: boolean = false;
// Number type
let decimal: number = 6;
// String type
let color: string = "blue";
// Array type
let list: number[] = [1, 2, 3];
// Tuple type
let tuple: [string, number] = ["hello", 10];
// Enum type
enum Color { Red, Green, Blue }
// Any type
let notSure: any = 4;
// Void type
let unusable: void = undefined;
// Null and Undefined
let u: undefined = undefined;
let n: null = null;
# *****************************************************************************
# Functions
# *****************************************************************************
// Function with no return type
function warnUser(): void { /* ... */ }
// Function with return type
function buildName(firstName: string, lastName: string): string { /* ... */ }
// Function with optional parameters
function buildNameOptional(firstName: string, lastName?: string): string { /* ... */ }
// Function with default parameters
function buildNameDefault(firstName: string, lastName = "Smith"): string { /* ... */ }
# *****************************************************************************
# Interfaces
# *****************************************************************************
// Simple interface
interface LabelledValue {
label: string;
}
// Function in an interface
interface SearchFunc {
(source: string, subString: string): boolean;
}
// Indexable types
interface StringArray {
[index: number]: string;
}
// Class types in interfaces
interface ClockInterface {
currentTime: Date;
setTime(d: Date): void;
}
# *****************************************************************************
# Classes
# *****************************************************************************
// Basic class
class Greeter {
greeting: string;
constructor(message: string) { this.greeting = message; }
greet() { return "Hello, " + this.greeting; }
}
// Inheritance
class Animal {
move(distanceInMeters: number = 0) { /* ... */ }
}
class Dog extends Animal {
bark() { /* ... */ }
}
// Class with interfaces
class Clock implements ClockInterface {
currentTime: Date = new Date();
setTime(d: Date) { this.currentTime = d; }
}
# *****************************************************************************
# Advanced Types
# *****************************************************************************
// Union types
function padLeft(value: string, padding: string | number) { /* ... */ }
// Intersection types
interface BusinessPartner {
name: string;
credit: number;
}
type Contact = BusinessPartner & { email: string };
// Type guards
function isFish(pet: Fish | Bird): pet is Fish { /* ... */ }
// Nullable types
function f(sn: string | null): string { /* ... */ }
// Type Aliases
type NameOrNameArray = string | string[];
// Generics
function identity<T>(arg: T): T { return arg; }
# *****************************************************************************
# Enums and Namespaces
# *****************************************************************************
// Numeric enums
enum Direction { Up = 1, Down, Left, Right }
// String enums
enum Response { No = "NO", Yes = "YES" }
// Namespaces
namespace Validation {
export interface StringValidator {
isAcceptable(s: string): boolean;
}
}
# *****************************************************************************
# Modules
# *****************************************************************************
// Importing modules
import { moduleName } from "module";
// Exporting from modules
export function someFunction() { /* ... */ }
// Default exports
export default class SomeType { /* ... */ }
# *****************************************************************************
# Decorators
# *****************************************************************************
// Class decorator
function sealed(constructor: Function) { /* ... */ }
// Method decorator
function enumerable(value: boolean) {
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) { /* ... */ };
}
// Accessor decorator
function configurable(value: boolean) { /* ... */ }
# *****************************************************************************
# Type Assertions
# *****************************************************************************
let someValue: any = "this is a string";
let strLength: number = (someValue as string).length;
# *****************************************************************************
# Miscellaneous
# *****************************************************************************
// Type inference
let x = 3; // `x` will be inferred as `number`
// Type compatibility
interface Named {
name: string;
}
let x: Named;
let y = { name: "Alice", location: "Seattle" };
x = y; // OK
// Ambient declarations
declare var $: JQuery;

View File

@@ -21,7 +21,6 @@ cat /proc/<process_id>/maps # Show the current virtual memory usage of a Linux
ip r # Display ip of the server ip r # Display ip of the server
lsof -i :9000 # List process running on port 9000 lsof -i :9000 # List process running on port 9000
kill -9 $(lsof -t -i:PORT) # Kill the process running on whichever port specified
journalctl -u minio.service -n 100 --no-pager # List last 100 logs for specific service journalctl -u minio.service -n 100 --no-pager # List last 100 logs for specific service