This file contains hidden or 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
| #!/bin/sh | |
| swap_file=/var/swap.img | |
| if [ ! -f $swap_file ]; then | |
| echo 'creating 1gb swap file...' | |
| touch $swap_file | |
| dd if=/dev/zero of=$swap_file bs=1024k count=1000 | |
| chmod 600 $swap_file | |
| mkswap $swap_file |
This file contains hidden or 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
| class RealArray extends Array { | |
| constructor(length) { | |
| if (!Number.isInteger(length) || length < 0) { | |
| throw new Error('RealArray requires a positive integer length') | |
| } | |
| function boundsCheck(index) { | |
| if (index in Array.prototype) { | |
| throw new RangeError('RealArray does not have ' + index) | |
| } | |
| if (parseInt(index, 10) !== parseFloat(index, 10)) { |
This file contains hidden or 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
| type Result<Ok, Err extends Error = Error> = | |
| | { kind: 'ok', value: Ok } | |
| | { kind: 'err', err: Err } | |
| const Ok = <T>(value: T): Result<T> => { | |
| return { | |
| kind: 'ok', | |
| value | |
| } | |
| } |
This file contains hidden or 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
| create table "users" ( | |
| "userId" serial, | |
| "username" text not null, | |
| primary key ("userId") | |
| ); | |
| create table "comments" ( | |
| "commentId" serial, | |
| "userId" integer not null, | |
| "content" text not null, |
This file contains hidden or 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
| function h(tagName, attributes, ...children) { | |
| if (arguments.length === 2) { | |
| if (Array.isArray(attributes) || typeof attributes !== 'object') { | |
| children = [attributes] | |
| attributes = null | |
| } | |
| } | |
| const $element = document.createElement(tagName) | |
| for (const name in attributes) { | |
| $element.setAttribute(name, attributes[name]) |
This file contains hidden or 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
| function decode(token) { | |
| const [, payload] = token.split('.') | |
| try { return JSON.parse(atob(payload)) } catch (err) {} | |
| const unsafe = payload.replace(/-/g, '+').replace(/_/g, '/') | |
| let padded = unsafe + '='.repeat(4 - unsafe.length % 4) | |
| const uriComponent = atob(padded).replace(/(.)/g, (_, c) => { | |
| const hex = c.charCodeAt(0).toString(16).toUpperCase() | |
| return '%' + (hex.length < 2 ? '0' : '') + hex | |
| }) | |
| return JSON.parse(decodeURIComponent(uriComponent)) |
This file contains hidden or 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
| import React from 'react' | |
| const RouterContext = React.createContext({ | |
| url: new URL('/', window.location.href), | |
| navigate: () => {}, | |
| redirect: () => {} | |
| }) | |
| export function Router({ children }) { | |
| const [url, setUrl] = React.useState(() => new URL(window.location.href)) |
This file contains hidden or 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
| import assert from 'assert' | |
| import { pipeline } from 'stream' | |
| import { Socket, connect, AddressInfo } from 'net' | |
| import { request, Server, IncomingMessage, ServerResponse } from 'http' | |
| type Servers = { | |
| proxyServer: Server | |
| localServer: Server | |
| } |