Skip to content

Instantly share code, notes, and snippets.

View ambroseus's full-sized avatar
😎
let code = async think => await think(twice)

Eugene Samonenko ambroseus

😎
let code = async think => await think(twice)
View GitHub Profile
@ambroseus
ambroseus / node-typescript-esm.md
Created January 11, 2024 10:12 — forked from khalidx/node-typescript-esm.md
A Node + TypeScript + ts-node + ESM experience that works.

The experience of using Node.JS with TypeScript, ts-node, and ESM is horrible.

There are countless guides of how to integrate them, but none of them seem to work.

Here's what worked for me.

Just add the following files and run npm run dev. You'll be good to go!

package.json

@ambroseus
ambroseus / useEvent.js
Last active January 2, 2024 09:47
A Hook to define an event handler with an always-stable function identity
// A Hook to define an event handler with an always-stable function identity
function useEvent(handler) {
const handlerRef = useRef(null);
// In a real implementation, this would run before layout effects
useLayoutEffect(() => {
handlerRef.current = handler;
});
@ambroseus
ambroseus / README.md
Created December 4, 2023 11:08 — forked from kfox/README.md
TCP echo server for Node.js

TCP echo server for Node.js

Usage

  1. Make sure you have a modern-ish version of Node.js installed.
  2. Type npx https://gist.github.com/kfox/1280c2f0ee8324067dba15300e0f2fd3
  3. Connect to it from a client, e.g. netcat or similar: nc localhost 9000
@ambroseus
ambroseus / fix-wsl2-dns-resolution
Created April 19, 2022 08:32 — forked from coltenkrauter/fix-wsl2-dns-resolution
Fix DNS resolution in WSL2
More recent resolution:
1. cd ~/../../etc (go to etc folder in WSL).
2. echo "[network]" | sudo tee wsl.conf (Create wsl.conf file and add the first line).
3. echo "generateResolvConf = false" | sudo tee -a wsl.conf (Append wsl.conf the next line).
4. wsl --terminate Debian (Terminate WSL in Windows cmd, in case is Ubuntu not Debian).
5. cd ~/../../etc (go to etc folder in WSL).
6. sudo rm -Rf resolv.conf (Delete the resolv.conf file).
7. In windows cmd, ps or terminal with the vpn connected do: Get-NetIPInterface or ipconfig /all for get the dns primary and
secondary.
// Core assets
let coreAssets = [];
// On install, cache core assets
self.addEventListener('install', function (event) {
// Cache core assets
event.waitUntil(caches.open(coreID).then(function (cache) {
for (let asset of coreAssets) {
cache.add(new Request(asset));
@ambroseus
ambroseus / HappyBirthdayCray.html
Last active September 20, 2021 08:50
Happy Birthday, Cray!
<!doctype html>
<html lang="en">
<body>
<script>
const HB = "Happy Birthday"
const name = "Cray"
let i = 0;
while (i < 2) {
document.write(`${HB} to you.<br/>`)
i++
@ambroseus
ambroseus / metrials-go.md
Created March 14, 2021 08:50 — forked from egorsmkv/metrials-go.md
Материалы по Go (golang): мануалы, статьи, книги и ссылки на сообщества

Материалы по Go (golang)

На русском языке

Мануалы и туториалы

  • [Введение в программирование на Go][1]
  • [Маленькая книга о Go][3]
  • [Эффективный Go][2]
  • Есть еще [Краткий пересказ Effective Go на русском языке][4], но 2009 года
@ambroseus
ambroseus / execScript.js
Created March 3, 2021 07:15
node vm exec script
const { VM } = require('vm2')
const defaultVMOptions = {
timeout: 5000, // 5 sec
eval: false, // no eval
wasm: false, // no wasm
fixAsync: true, // no async
}
function execScript({
import React, { ReactNode } from 'react'
interface MarkerProps {
id: string
className?: string
children: ReactNode
}
const Marker = ({ id, className, children }: MarkerProps) => (
<marker
@ambroseus
ambroseus / variants-benchmark.js
Created October 10, 2020 07:52
variants benchmark
const imVariants = require('./variants-im')
const fnVariants = require('./variants-fn')
const str = '012345678901234'
count = 100
console.time('imperative variants');
for (let i = 0; i < count; i++) {
imVariants(str)
}