doc org
This commit is contained in:
@@ -1,162 +0,0 @@
|
|||||||
# JavaScript Cheat Sheet for Web Development
|
|
||||||
|
|
||||||
## 1. Variables and Data Types
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
let myVariable = 5; // Variable
|
|
||||||
const myConstant = 10; // Constant
|
|
||||||
let string = "This is a string";
|
|
||||||
let number = 42;
|
|
||||||
let boolean = true;
|
|
||||||
let nullValue = null;
|
|
||||||
let undefinedValue = undefined;
|
|
||||||
let objectValue = { a: 1, b: 2 };
|
|
||||||
let arrayValue = [1, 2, 3];
|
|
||||||
let symbol = Symbol("symbol");
|
|
||||||
```
|
|
||||||
|
|
||||||
## 2. Operators and Conditionals
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
let a = 10,
|
|
||||||
b = 20;
|
|
||||||
let sum = a + b;
|
|
||||||
let difference = a - b;
|
|
||||||
let product = a * b;
|
|
||||||
let quotient = a / b;
|
|
||||||
let remainder = a % b;
|
|
||||||
if (a > b) {
|
|
||||||
console.log("a is greater than b");
|
|
||||||
} else if (a < b) {
|
|
||||||
console.log("a is less than b");
|
|
||||||
} else {
|
|
||||||
console.log("a is equal to b");
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 3. Strings, Template Literals and Arrays
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
let hello = "Hello,";
|
|
||||||
let world = "World!";
|
|
||||||
let greeting = hello + " " + world; // 'Hello, World!'
|
|
||||||
let world = "World!";
|
|
||||||
let greeting = `Hello, ${world}`; // 'Hello, World!'
|
|
||||||
let fruits = ["Apple", "Banana", "Cherry"];
|
|
||||||
console.log(fruits[0]); // 'Apple'
|
|
||||||
fruits.push("Durian"); // Adding to the end
|
|
||||||
fruits.unshift("Elderberry"); // Adding to the start
|
|
||||||
let firstFruit = fruits.shift(); // Removing from the start
|
|
||||||
let lastFruit = fruits.pop(); // Removing from the end
|
|
||||||
```
|
|
||||||
|
|
||||||
## 4. Functions and Objects
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
function add(a, b) {
|
|
||||||
return a + b;
|
|
||||||
}
|
|
||||||
let subtract = function (a, b) {
|
|
||||||
return a - b;
|
|
||||||
};
|
|
||||||
let multiply = (a, b) => a * b;
|
|
||||||
let car = {
|
|
||||||
make: "Tesla",
|
|
||||||
model: "Model 3",
|
|
||||||
year: 2022,
|
|
||||||
start: function () {
|
|
||||||
console.log("Starting the car...");
|
|
||||||
},
|
|
||||||
};
|
|
||||||
console.log(car.make); // 'Tesla'
|
|
||||||
car.start(); // 'Starting the car...'
|
|
||||||
```
|
|
||||||
|
|
||||||
## 5. DOM Manipulation
|
|
||||||
|
|
||||||
The Document Object Model (DOM) is a programming interface for web documents. It represents the structure of a document and enables a way to manipulate its content and visual presentation by treating it as a tree structure where each node is an object representing a part of the document. The methods under this section help in accessing and changing the DOM.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
let element = document.getElementById("myId"); // Get element by ID
|
|
||||||
let elements = document.getElementsByClassName("myClass"); // Get elements by class name
|
|
||||||
let elements = document.getElementsByTagName("myTag"); // Get elements by tag name
|
|
||||||
let element = document.querySelector("#myId"); // Get first element matching selector
|
|
||||||
let elements = document.querySelectorAll(".myClass"); // Get all elements matching selector
|
|
||||||
element.innerHTML = "New Content"; // Change HTML content
|
|
||||||
element.style.color = "red"; // Change CSS styles
|
|
||||||
let attr = element.getAttribute("myAttr"); // Get attribute value
|
|
||||||
element.setAttribute("myAttr", "New Value"); // Set attribute value
|
|
||||||
```
|
|
||||||
|
|
||||||
## 6. Event Handling
|
|
||||||
|
|
||||||
JavaScript in the browser uses an event-driven programming model. Everything starts by following an event like a user clicking a button, submitting a form, moving the mouse, etc. The addEventListener method sets up a function that will be called whenever the specified event is delivered to the target.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
element.addEventListener("click", function () {
|
|
||||||
// Code to execute when element is clicked
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
## 7. Form Handling
|
|
||||||
|
|
||||||
In web development, forms are essential for interactions between the website and the user. The provided code here prevents the default form submission behavior and provides a skeleton where one can define what should be done when the form is submitted.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
let form = document.getElementById("myForm");
|
|
||||||
form.addEventListener("submit", function (event) {
|
|
||||||
event.preventDefault(); // Prevent form submission
|
|
||||||
// Handle form data here
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
## 8. AJAX Calls
|
|
||||||
|
|
||||||
AJAX, stands for Asynchronous JavaScript And XML. In a nutshell, it is the use of the fetch API (or XMLHttpRequest object) to communicate with servers from JavaScript. It can send and receive information in various formats, including JSON, XML, HTML, and text files. AJAX’s most appealing characteristic is its "asynchronous" nature, which means it can do all of this without having to refresh the page. This allows you to update parts of a web page, without reloading the whole page.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
// Using Fetch API
|
|
||||||
fetch("https://api.mywebsite.com/data", {
|
|
||||||
method: "GET", // or 'POST'
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
// body: JSON.stringify(data) // Include this if you're doing a POST request
|
|
||||||
})
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then((data) => console.log(data))
|
|
||||||
.catch((error) => console.error("Error:", error));
|
|
||||||
|
|
||||||
// Using Async/Await
|
|
||||||
async function fetchData() {
|
|
||||||
try {
|
|
||||||
let response = await fetch("https://api.mywebsite.com/data");
|
|
||||||
let data = await response.json();
|
|
||||||
console.log(data);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error:", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fetchData();
|
|
||||||
```
|
|
||||||
|
|
||||||
## 9. Manipulating LocalStorage
|
|
||||||
|
|
||||||
The localStorage object stores data with no expiration date. The data will not be deleted when the browser is closed, and will be available the next day, week, or year. This can be
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
localStorage.setItem("myKey", "myValue"); // Store data
|
|
||||||
let data = localStorage.getItem("myKey"); // Retrieve data
|
|
||||||
localStorage.removeItem("myKey"); // Remove data
|
|
||||||
localStorage.clear(); // Clear all data
|
|
||||||
```
|
|
||||||
|
|
||||||
## 10. Manipulating Cookies
|
|
||||||
|
|
||||||
Cookies are data, stored in small text files, on your computer. When a web server has sent a web page to a browser, the connection is shut down, and the server forgets everything about the user. Cookies were invented to solve the problem of "how to remember information about the user": When a user visits a web page, his/her name can be stored in a cookie. Next time the user visits the page, the cookie "remembers" his/her name.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
document.cookie = "username=John Doe"; // Create cookie
|
|
||||||
let allCookies = document.cookie; // Read all cookies
|
|
||||||
document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; // Delete cookie
|
|
||||||
```
|
|
||||||
@@ -1,142 +0,0 @@
|
|||||||
# Adding or extending a family of adaptive instructions.
|
|
||||||
|
|
||||||
## Families of instructions
|
|
||||||
|
|
||||||
The core part of PEP 659 (specializing adaptive interpreter) is the families
|
|
||||||
of instructions that perform the adaptive specialization.
|
|
||||||
|
|
||||||
A family of instructions has the following fundamental properties:
|
|
||||||
|
|
||||||
* It corresponds to a single instruction in the code
|
|
||||||
generated by the bytecode compiler.
|
|
||||||
* It has a single adaptive instruction that records an execution count and,
|
|
||||||
at regular intervals, attempts to specialize itself. If not specializing,
|
|
||||||
it executes the non-adaptive instruction.
|
|
||||||
* It has at least one specialized form of the instruction that is tailored
|
|
||||||
for a particular value or set of values at runtime.
|
|
||||||
* All members of the family must have the same number of inline cache entries,
|
|
||||||
to ensure correct execution.
|
|
||||||
Individual family members do not need to use all of the entries,
|
|
||||||
but must skip over any unused entries when executing.
|
|
||||||
|
|
||||||
The current implementation also requires the following,
|
|
||||||
although these are not fundamental and may change:
|
|
||||||
|
|
||||||
* All families uses one or more inline cache entries,
|
|
||||||
the first entry is always the counter.
|
|
||||||
* All instruction names should start with the name of the non-adaptive
|
|
||||||
instruction.
|
|
||||||
* The adaptive instruction should end in `_ADAPTIVE`.
|
|
||||||
* Specialized forms should have names describing their specialization.
|
|
||||||
|
|
||||||
## Example family
|
|
||||||
|
|
||||||
The `LOAD_GLOBAL` instruction (in Python/ceval.c) already has an adaptive
|
|
||||||
family that serves as a relatively simple example.
|
|
||||||
|
|
||||||
The `LOAD_GLOBAL_ADAPTIVE` instruction performs adaptive specialization,
|
|
||||||
calling `_Py_Specialize_LoadGlobal()` when the counter reaches zero.
|
|
||||||
|
|
||||||
There are two specialized instructions in the family, `LOAD_GLOBAL_MODULE`
|
|
||||||
which is specialized for global variables in the module, and
|
|
||||||
`LOAD_GLOBAL_BUILTIN` which is specialized for builtin variables.
|
|
||||||
|
|
||||||
## Performance analysis
|
|
||||||
|
|
||||||
The benefit of a specialization can be assessed with the following formula:
|
|
||||||
`Tbase/Tadaptive`.
|
|
||||||
|
|
||||||
Where `Tbase` is the mean time to execute the base instruction,
|
|
||||||
and `Tadaptive` is the mean time to execute the specialized and adaptive forms.
|
|
||||||
|
|
||||||
`Tadaptive = (sum(Ti*Ni) + Tmiss*Nmiss)/(sum(Ni)+Nmiss)`
|
|
||||||
|
|
||||||
`Ti` is the time to execute the `i`th instruction in the family and `Ni` is
|
|
||||||
the number of times that instruction is executed.
|
|
||||||
`Tmiss` is the time to process a miss, including de-optimzation
|
|
||||||
and the time to execute the base instruction.
|
|
||||||
|
|
||||||
The ideal situation is where misses are rare and the specialized
|
|
||||||
forms are much faster than the base instruction.
|
|
||||||
`LOAD_GLOBAL` is near ideal, `Nmiss/sum(Ni) ≈ 0`.
|
|
||||||
In which case we have `Tadaptive ≈ sum(Ti*Ni)`.
|
|
||||||
Since we can expect the specialized forms `LOAD_GLOBAL_MODULE` and
|
|
||||||
`LOAD_GLOBAL_BUILTIN` to be much faster than the adaptive base instruction,
|
|
||||||
we would expect the specialization of `LOAD_GLOBAL` to be profitable.
|
|
||||||
|
|
||||||
## Design considerations
|
|
||||||
|
|
||||||
While `LOAD_GLOBAL` may be ideal, instructions like `LOAD_ATTR` and
|
|
||||||
`CALL_FUNCTION` are not. For maximum performance we want to keep `Ti`
|
|
||||||
low for all specialized instructions and `Nmiss` as low as possible.
|
|
||||||
|
|
||||||
Keeping `Nmiss` low means that there should be specializations for almost
|
|
||||||
all values seen by the base instruction. Keeping `sum(Ti*Ni)` low means
|
|
||||||
keeping `Ti` low which means minimizing branches and dependent memory
|
|
||||||
accesses (pointer chasing). These two objectives may be in conflict,
|
|
||||||
requiring judgement and experimentation to design the family of instructions.
|
|
||||||
|
|
||||||
The size of the inline cache should as small as possible,
|
|
||||||
without impairing performance, to reduce the number of
|
|
||||||
`EXTENDED_ARG` jumps, and to reduce pressure on the CPU's data cache.
|
|
||||||
|
|
||||||
### Gathering data
|
|
||||||
|
|
||||||
Before choosing how to specialize an instruction, it is important to gather
|
|
||||||
some data. What are the patterns of usage of the base instruction?
|
|
||||||
Data can best be gathered by instrumenting the interpreter. Since a
|
|
||||||
specialization function and adaptive instruction are going to be required,
|
|
||||||
instrumentation can most easily be added in the specialization function.
|
|
||||||
|
|
||||||
### Choice of specializations
|
|
||||||
|
|
||||||
The performance of the specializing adaptive interpreter relies on the
|
|
||||||
quality of specialization and keeping the overhead of specialization low.
|
|
||||||
|
|
||||||
Specialized instructions must be fast. In order to be fast,
|
|
||||||
specialized instructions should be tailored for a particular
|
|
||||||
set of values that allows them to:
|
|
||||||
1. Verify that incoming value is part of that set with low overhead.
|
|
||||||
2. Perform the operation quickly.
|
|
||||||
|
|
||||||
This requires that the set of values is chosen such that membership can be
|
|
||||||
tested quickly and that membership is sufficient to allow the operation to
|
|
||||||
performed quickly.
|
|
||||||
|
|
||||||
For example, `LOAD_GLOBAL_MODULE` is specialized for `globals()`
|
|
||||||
dictionaries that have a keys with the expected version.
|
|
||||||
|
|
||||||
This can be tested quickly:
|
|
||||||
* `globals->keys->dk_version == expected_version`
|
|
||||||
|
|
||||||
and the operation can be performed quickly:
|
|
||||||
* `value = entries[cache->index].me_value;`.
|
|
||||||
|
|
||||||
Because it is impossible to measure the performance of an instruction without
|
|
||||||
also measuring unrelated factors, the assessment of the quality of a
|
|
||||||
specialization will require some judgement.
|
|
||||||
|
|
||||||
As a general rule, specialized instructions should be much faster than the
|
|
||||||
base instruction.
|
|
||||||
|
|
||||||
### Implementation of specialized instructions
|
|
||||||
|
|
||||||
In general, specialized instructions should be implemented in two parts:
|
|
||||||
1. A sequence of guards, each of the form
|
|
||||||
`DEOPT_IF(guard-condition-is-false, BASE_NAME)`.
|
|
||||||
2. The operation, which should ideally have no branches and
|
|
||||||
a minimum number of dependent memory accesses.
|
|
||||||
|
|
||||||
In practice, the parts may overlap, as data required for guards
|
|
||||||
can be re-used in the operation.
|
|
||||||
|
|
||||||
If there are branches in the operation, then consider further specialization
|
|
||||||
to eliminate the branches.
|
|
||||||
|
|
||||||
### Maintaining stats
|
|
||||||
|
|
||||||
Finally, take care that stats are gather correctly.
|
|
||||||
After the last `DEOPT_IF` has passed, a hit should be recorded with
|
|
||||||
`STAT_INC(BASE_INSTRUCTION, hit)`.
|
|
||||||
After a optimization has been deferred in the `ADAPTIVE` form,
|
|
||||||
that should be recorded with `STAT_INC(BASE_INSTRUCTION, deferred)`.
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
===== Forex Trading Strategy Guideline =====
|
|
||||||
|
|
||||||
==== Key Tools and Indicators ====
|
|
||||||
|
|
||||||
=== Trend Indicators ===
|
|
||||||
|
|
||||||
* **Moving Average**:
|
|
||||||
* //Explanation//: This indicator provides a smoothed line representing price movements over a specific period, helping identify the market’s direction.
|
|
||||||
* //Example//: A common strategy is to use two moving averages, a short-term and a long-term, and to identify crosses as potential buy or sell signals.
|
|
||||||
* **MACD**:
|
|
||||||
* //Explanation//: MACD illustrates the relationship between two moving averages, helping in spotting potential buy and sell signals.
|
|
||||||
* //Example//: A buy signal is generated when the MACD line crosses above the signal line, and a sell signal is generated when it crosses below.
|
|
||||||
* **ADX**:
|
|
||||||
* //Explanation//: ADX aids in determining the strength of a trend, indicating whether to enter or avoid a trade.
|
|
||||||
* //Example//: A high ADX value (above 25) indicates a strong trend, while a low value suggests a weak trend.
|
|
||||||
* **Bollinger Bands**:
|
|
||||||
* //Explanation//: This tool identifies volatility and potential reversals in the market, helping you to find potential entry and exit points.
|
|
||||||
* //Example//: A potential buy signal is when the price touches the lower band, and a potential sell signal is when the price touches the upper band.
|
|
||||||
|
|
||||||
=== Support and Resistance Levels ===
|
|
||||||
|
|
||||||
Identifying these levels aids in determining potential reversal points and envisioning the price’s movement range.
|
|
||||||
|
|
||||||
=== Fibonacci Retracements ===
|
|
||||||
|
|
||||||
A tool based on the Fibonacci sequence, helping in predicting potential support and resistance levels.
|
|
||||||
|
|
||||||
==== Crafting Your Trading Strategy: A Step-by-Step Guide ====
|
|
||||||
|
|
||||||
- **Signal Identification**
|
|
||||||
* //Detail//: Traders can use various indicators to spot potential signals. Apart from RSI, tools like Stochastic Oscillator can also be used to identify overbought or oversold conditions.
|
|
||||||
- **Confirmation with Other Tools**
|
|
||||||
* //Detail//: Encourage the use of more than one tool for confirmation to avoid false signals. For instance, confirming a signal derived from moving averages with Bollinger Bands or MACD can be more reliable.
|
|
||||||
- **Executing the Trade**
|
|
||||||
* //Detail//: Proceed with the execution once the signals are confirmed with other tools to ensure a higher success rate.
|
|
||||||
- **Safety Measures**
|
|
||||||
* //Detail//: Emphasize the continuous revision of stop-loss levels based on market dynamics to safeguard your investment. Utilizing a trailing stop-loss can be an effective strategy here.
|
|
||||||
- **Profit Booking**
|
|
||||||
* //Detail//: Setting a target profit level is crucial to ensure disciplined trading. It helps in avoiding greed and securing profits at predetermined levels, which could be based on historical resistance levels or a set percentage.
|
|
||||||
|
|
||||||
==== Expert Tips for Enhancing Your Strategy ====
|
|
||||||
|
|
||||||
* **Diverse Tool Utilization**: Employ various indicators to sidestep false signals and pinpoint reliable trading opportunities.
|
|
||||||
* **Comprehensive Analysis**: Incorporate different forms of analysis to affirm signals and make well-informed trading decisions.
|
|
||||||
* **Strategy Backtesting**: Prior to live trading, assess your strategy using historical data to spot any shortcomings.
|
|
||||||
* **Risk Management**: Implement measures to manage your risk efficiently, including setting suitable stop-loss levels.
|
|
||||||
|
|
||||||
//Note//: Trading involves risks and it’s pivotal to approach it with a well-structured strategy to increase the probability of success.
|
|
||||||
|
|
||||||
In the forex trading landscape, it’s pivotal to amalgamate leading indicators with other analytical tools to forge a comprehensive trading strategy. This piece highlights some prominent indicators and illustrates how they can work in synergy to aid traders in making informed decisions.
|
|
||||||
|
|
||||||
==== Exploring Confluence with Leading Indicators ====
|
|
||||||
|
|
||||||
=== Trend Indicators ===
|
|
||||||
|
|
||||||
Trend indicators serve to pinpoint the overarching direction of the market and substantiate signals emanated from leading indicators. Some popular options include:
|
|
||||||
|
|
||||||
* **Moving Average**: Helps in smoothing price data to create a single flowing line, which makes it easier to identify the direction of the trend.
|
|
||||||
* **MACD (Moving Average Convergence Divergence)**: Useful in spotting changes in the strength, direction, momentum, and duration of a trend in a stock’s price.
|
|
||||||
* **ADX (Average Directional Index)**: Quantifies the strength of a trend, facilitating traders to discern the strongest trends to follow.
|
|
||||||
|
|
||||||
=== Support and Resistance Levels ===
|
|
||||||
|
|
||||||
These are critical zones on a chart where the price is expected to halt or reverse. Recognizing these levels enables traders to synchronize them with leading indicators to determine potential entry and exit points.
|
|
||||||
|
|
||||||
=== Fibonacci Retracements ===
|
|
||||||
|
|
||||||
Traders deploy this tool to spot potential reversal zones in price actions. Drawing Fibonacci retracements on a chart can aid in setting favorable targets for trades.
|
|
||||||
|
|
||||||
==== Case Study: Crafting a Strategy with Multi-dimensional Analysis ====
|
|
||||||
|
|
||||||
Let’s imagine your leading indicator, say the RSI, is indicating an oversold condition, paving the way for a potential upward reversal. Here’s a guided strategy:
|
|
||||||
|
|
||||||
- **Signal Identification**: Your first clue is an oversold notification from a leading indicator like the RSI, usually when it drops below a benchmark value, say 30, signaling a buy opportunity.
|
|
||||||
- **Confirmation through Secondary Tools**: Before taking action, seek affirmation through other tools; perhaps the price is aligning with a support level or exhibiting a bullish chart pattern.
|
|
||||||
- **Trade Initiation**: Leverage the indications to initiate a trade in the direction of the signal — considering our RSI example, a buy order would be fitting when RSI surpasses the 30 mark.
|
|
||||||
- **Risk Management**: Implement a stop loss slightly below a significant support level to curtail potential losses.
|
|
||||||
- **Profit Booking**: Set a target to book profits, which might be at a crucial resistance level or when the leading indicator exhibits a bearish signal.
|
|
||||||
|
|
||||||
==== Expert Tips for a Robust Trading Strategy ====
|
|
||||||
|
|
||||||
To sharpen your trading acumen, ponder upon these strategies:
|
|
||||||
|
|
||||||
* **Utilize Multiple Leading Indicators**: This could shield you from false signals and steer you towards more secure trading avenues.
|
|
||||||
* **Harmonize with Different Analysis Forms**: Engaging various forms of analysis can offer a deeper insight, substantiating the signals further.
|
|
||||||
* **Backtest Your Strategy**: Before diving into live trading, backtest your strategy to pinpoint any weaknesses and refine them accordingly.
|
|
||||||
* **Adopt Prudent Risk Management**: Always have risk management strategies in place, including setting judicious stop-loss levels to avert substantial losses.
|
|
||||||
|
|
||||||
//Note//: Despite the strategies outlined, remember that trading involves risks and it’s impossible to eliminate them completely. However, a well-rounded strategy can significantly enhance your prospects of success in the forex market.
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
1:13 Alibaba Alternative #1: Global Sources
|
|
||||||
2:28 Alibaba Alternative #2: Canton Fair
|
|
||||||
3:37 Alibaba Alternative #3: Import Database
|
|
||||||
4:35 Alibaba Alternative #4: China Sourcing Agent
|
|
||||||
5:36 Alibaba Alternative #5: Made-in-China
|
|
||||||
6:42 Alibaba Alternative #6: ThomasNet
|
|
||||||
7:37 Alibaba Alternative #7: DHGate
|
|
||||||
8:20 Alibaba Alternative #8: TradeKey
|
|
||||||
9:06 Alibaba Alternative #9: EC21
|
|
||||||
10:05 Alibaba Alternative #10: Yiwugo
|
|
||||||
11:15 Alibaba Alternative #11: 1688.com
|
|
||||||
12:19 Alibaba Alternative #12: Chinabrands
|
|
||||||
13:10 Alibaba Alternative #13: Chinavasion
|
|
||||||
Reference in New Issue
Block a user