Skip to content

Instantly share code, notes, and snippets.

View cyco130's full-sized avatar

Fatih Aygün cyco130

  • Reaktor
  • Lisbon
  • 23:24 (UTC +01:00)
  • X @cyco130
View GitHub Profile
@cyco130
cyco130 / dploy-nginx.sh
Created April 8, 2024 09:26
Simple deployment manager
# This script also runs on the VPS.
# It handles the bits that require
# root access.
set -e
if [ $(id -u) != 0 ]; then
echo "You're not root"
exit 1
fi
@cyco130
cyco130 / promises.js
Created December 26, 2023 17:52
Promise test
function fnThatReturnsPromiseOrValue() {
const random = Math.random();
if (random > 0.5) {
return Promise.resolve(random);
} else {
return random;
}
}
async function naive() {
@cyco130
cyco130 / mini-cjs.js
Last active August 3, 2023 20:13
A toy CommonJS implementation
import fs from "node:fs";
import path from "node:path";
import url from "node:url";
const cache = {};
function createRequire(filename) {
function require(specifier) {
const resolved = require.resolve(specifier);
if (resolved in cache) {
@cyco130
cyco130 / Chat.md
Last active May 24, 2023 10:01
Copilot Chat - First Try

cyco130

Are there any problems with this code?

export function escapeHtml(text: string): string {
	return text
		.replace(/</g, "&lt;")
		.replace(/&/g, "&amp;")
		.replace(/>/g, "&gt;")
		.replace(/"/g, "&quot;")
@cyco130
cyco130 / als.mjs
Created February 22, 2023 16:25
AsyncLocalStorage-based Node server framework
import { createServer } from "node:http";
import { AsyncLocalStorage } from "node:async_hooks";
const asyncLocalStorage = new AsyncLocalStorage();
createServer((req, res) => {
asyncLocalStorage.run({ req, res }, () => {
asyncHandler().catch((err) => {
console.error(err);
if (!res.writableEnded) {
import { Dispatch, SetStateAction, useState, useEffect } from 'react';
export function usePersistentState<T>(
key: string,
defaultValue: T
): [T, Dispatch<SetStateAction<T>>] {
const [state, setState] = useState<T>(defaultValue);
// Save to session storage on unload
useEffect(() => {
export function observable<T>(value: T): Observable<T> {
const subscribers = new Set<(val: T) => void>();
function run(): T;
function run(newValue: T): void;
function run(updateFunction: (oldValue: T) => T): void;
function run(newValueOrUpdateFn?: T | ((oldValue: T) => T)): T | void {
if (newValueOrUpdateFn === undefined) {
return value;
}
interface RpcModules {
"example-remote-module": MapReturnTypesToPromise<
typeof import("example-remote-module")
>;
}
export function importRemote<S extends keyof RpcModules>(
module: S
): RpcModules[S] {
return new Proxy({} as any, {
(function () {
const ticks = Array.from(
document.querySelectorAll("[aria-label='Verified account']")
)
.filter(
(tick) =>
tick?.parentElement?.parentElement?.children[0].textContent ===
"Elon Musk"
)
.forEach((tick) => {
// Modern bir tarayıcıda https://www.turkiye.gov.tr/istanbul-buyuksehir-belediyesi-vefat-sorgulama
// adresine gidip bu kodu developer console'a yapıştırarak çalıştırabilirsiniz.
(function() {
async function send(url, date) {
let fd = new FormData();
fd.append("tarih", date);
fd.append("token", document.body.dataset.token);
fd.append("btn", "Sorgula");