Skip to content

Instantly share code, notes, and snippets.

View zaydek's full-sized avatar
🤠
Howdy!

Zaydek MG zaydek

🤠
Howdy!
View GitHub Profile
async function on<T>(fn: () => T | Promise<T>): Promise<[T | null, Error | null]> {
try {
const res = await fn()
return [res, null]
} catch (error) {
return [null, error]
}
}
function sleep(ms: number): Promise<void> {
////////////////////////////////////////////////////////////////////////////////
// Todo
interface Todo {
id: string
done: boolean
text: string
setDone(value?: boolean): void
setText(value: string): void
}
import * as http from "http"
////////////////////////////////////////////////////////////////////////////////
export type Request = http.IncomingMessage
export type Response = http.ServerResponse
export type Handler = (req: Request, res: Response) => void | Promise<void>
export interface Server {
// prettier-ignore
interface Todo {
id: string
done: boolean
text: string
reset(): void
setDone(done: boolean): void
setText(text: string): void
<div>Hello, world!</div>
<div>Hello, world!</div>
<div>Hello, world!</div>
<div>Hello, world!</div>
<div>Hello, world!</div>
<div>Hello, world!</div>
<div>Hello, world!</div>
<div>Hello, world!</div>
<div>Hello, world!</div>
<div>Hello, world!</div>
@zaydek
zaydek / readme.md
Last active January 26, 2021 13:06

create-retro-app

Retro is a friendly development server and static-site generator (SSG) for React apps.


	Usage:

		retro create [dir]      // Creates a new Retro app at directory 'dir'
		retro watch [...dirs]   // Starts the development server and watches 'dirs' for changes
import { useMemo, useState } from "react"
class Form {
state = {
user: "Hello, world!",
pass: "Hello, world!",
}
constructor({ user, pass } = { user: "Hello", pass: "World" }) {
this.state = {
user,
import { useEffect, useRef } from "react"
import useMethods from "use-methods"
const app = {
initialState: {
todo: "",
todos: [],
},
reducer: state => ({
setTodo(newTodo) {
@zaydek
zaydek / promise.ts
Last active December 18, 2020 00:15
function check(fn: Function) {
try {
const ret = fn()
return [ret, null]
} catch (err) {
return [null, err]
}
}
async function checkAsync<T>(promise: Promise<T>) {
@zaydek
zaydek / input.scss
Created December 13, 2020 21:17
Generated by SassMeister.com.
@use "sass:string";
@use "sass:list";
@function replace($str, $s1, $s2) {
$n: string.index($str, $s1);
@return string.slice($str, 1, $n - 1) + $s2 + string.slice($str, $n + string.length($s1));
}
@mixin variants($variants...) {
@each $variant in $variants {