Skip to content

Instantly share code, notes, and snippets.

View heracek's full-sized avatar

Tomáš Horáček heracek

View GitHub Profile
@t3dotgg
t3dotgg / try-catch.ts
Last active March 12, 2025 20:43
Theo's preferred way of handling try/catch in TypeScript
// Types for the result object with discriminated union
type Success<T> = {
data: T;
error: null;
};
type Failure<E> = {
data: null;
error: E;
};
@faustinoaq
faustinoaq / myAngular.html
Last active March 10, 2025 07:08
Front-end libraries (React, Vue, Angular) and the basic principles of how they work, all in a single file using pure JavaScript (VanillaJS).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Angular from Scratch</title>
<style>
.my-component {
font-family: Arial, sans-serif;
#!/usr/bin/env bash
# Abort sign off on any error
set -e
# Start the benchmark timer
SECONDS=0
# Repository introspection
OWNER=$(gh repo view --json owner --jq .owner.login)
@xfournet
xfournet / pluginHttp2Proxy.ts
Last active February 7, 2025 22:15
Vite support for HTTP2 and proxy
import proxy from 'http2-proxy';
import type { Plugin, ProxyOptions } from 'vite';
export const pluginHttp2Proxy = (): Plugin => {
let routes: Record<string, string | ProxyOptions>;
return {
name: 'vite-plugin-http2-proxy',
config: (config) => {
const { server } = config;
routes = server?.proxy ?? {};
@gaearon
gaearon / 00-README-NEXT-SPA.md
Last active February 21, 2025 12:35
Next.js SPA example with dynamic client-only routing and static hosting

Next.js client-only SPA example

Made this example to show how to use Next.js router for a 100% SPA (no JS server) app.

You use Next.js router like normally, but don't define getStaticProps and such. Instead you do client-only fetching with swr, react-query, or similar methods.

You can generate HTML fallback for the page if there's something meaningful to show before you "know" the params. (Remember, HTML is static, so it can't respond to dynamic query. But it can be different per route.)

Don't like Next? Here's how to do the same in Gatsby.

@talkingmoose
talkingmoose / Download and Install Microsoft product.zsh
Last active March 11, 2025 12:01
Downloads and installs the latest available Microsoft product specified directly on the client. This avoids having to manually download and store an up-to-date installer on a distribution server every month.
#!/bin/zsh
:<<'ABOUT_THIS_SCRIPT'
-----------------------------------------------------------------------
Written by:William Smith
Partner Program Manager
Jamf
[email protected]
https://gist.github.com/b6637160b65b751824943ede022daa17

Building NW.js on macOS (for Mere Mortals) {: .doctitle}


This is an annotated version of Building NW.js from the official NW.js developer documentation. It includes my experience from building NW.js binaries for macOS, both Intel (x86-64) and M1 (arm64). The latter can be easily discerned since they are block-quoted and appear in red1.

Footnotes

  1. Not on GitHub though; they aggressively sanitize HTML in Markdown. Block quotes still work 😬

@zhuowei
zhuowei / Ensemble.plist
Last active September 18, 2023 06:26
Put this file as /Library/Preferences/FeatureFlags/Domain/Ensemble.plist and reboot to (hopefully) turn on Universal Control on macOS 12
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- not sure which one it is, so set both -->
<key>Ensemble</key>
<dict>
<key>Enabled</key>
<true/>
</dict>
@craigbilner
craigbilner / tsc.js
Created July 23, 2021 15:35
nx executor
const { exec } = require('child_process');
const { promisify } = require('util');
const path = require('path');
module.exports.default = async function tsc(options, context) {
process.chdir(
path.join(context.cwd, context.workspace.projects[context.projectName].root)
);
try {
@lucacasonato
lucacasonato / README.md
Last active April 3, 2021 22:43
FetchEvent polyfill in Deno, with demo

This example demonstrates how to polyfill the "fetch" event in Deno, and gives an example for how this can be used to run Cloudflare Workers in Deno.

To try it locally run the script below, and visit http://0.0.0.0:8080:

$ deno run --allow-net https://gist.githubusercontent.com/lucacasonato/1a30a4fa6ef6c053a93f271675ef93fc/raw/efcdc8e798604e194831830fcb962b50261384b3/example-worker.js