This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const createElement = (tag, props, children ) => ({ tag, props, children }); | |
const hooks = []; | |
let useStateCalls = -1; | |
const useState = (initialState) => { | |
useStateCalls += 1; | |
// Each hook is an array with two elements: | |
// - hook[0] is the state | |
// - hook[1] is the setState function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<div id="root"></div> | |
<!-- First article on building a react-like library --> | |
<script src="./static-dom.js"></script> | |
<body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const createElement = (tag, props, children ) => ({ | |
tag, | |
props, | |
children, | |
element: null, | |
currentNode: null, | |
}); | |
const hooks = []; | |
let useStateCalls = -1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Used in the article: https://www.gimtec.io/articles/metraprogramming-example-orm/ | |
const pg = require('pg'); | |
/** | |
* ORM Setup with metaprogramming | |
*/ | |
const define = async (dbUrl, table) => { | |
try { | |
const getTableSchema = (table) => `select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='${table}';`; | |
const client = new pg.Client(dbUrl); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Long calculation | |
const getHighNumber = () => { | |
let x = BigInt(0); | |
for (let i = BigInt(0); i < BigInt(1_000_000); i++) { | |
x += i * i; | |
} | |
return x; | |
}; | |
document.getElementById('sluggish').addEventListener('click', async () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Select all, copy-paste it in the console and try it out. | |
const expectedMilliseconds = 1000; | |
const startTime = new Date(); | |
const logOne = () => console.log(1); | |
const logTwo = () => { | |
// This should be close to 0 | |
console.log("Diff:", (new Date() - startTime) - expectedMilliseconds); | |
console.log(2); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from socket import AF_INET, SOCK_STREAM, socket | |
server_port = 12000 | |
server_ip = 'localhost' | |
# Create a TCP socket | |
# AF_INET indicats undelying network IPv4 | |
# SOCK_STREAM means TCP socket rather than UDP | |
# OS handles the port of the client | |
client_socket = socket(AF_INET, SOCK_STREAM) | |
# initiates TCP connection between client and server | |
# parameters are the address of the server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const num = 10; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
identifier := (A-Z,"_") | |
var_name := ":"<identifier> | |
command := "FD" | "BD" | "LT" | "RT" | "PEN" | |
positive_integer := \d+ | |
expression := <positive_integer> | "UP" | "DOWN" | <var_name> | <positive_integer> ("+" | "-") <expression> | |
command_statement := (<command_key> | <identifier>) <expression> | |
loop_statement := "REPEAT" <positive_integer> { <command> } "END" | |
statement := <loop_statement> | <command_statement> | |
fun_definition := "TO" <identifier> [ <var_name> ] { "," <var_name> } { <statement> } "END" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import dukpy | |
import sys | |
set_timeout_function = 'function setTimeout() { return; };' | |
if __name__ == '__main__': | |
filename = sys.argv[1] | |
(name, extension) = filename.split('.') | |
with open(filename, 'rt') as f: |
NewerOlder