Some helper functions that can come in handy day to day.
This file contains 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/bash | |
filepath=$1 | |
funcname=$2 | |
[[ $filepath != *.ts ]] && filepath="$filepath.ts" | |
dataurl='data:text/typescript,import { '$funcname' } from "file://'$(pwd)'/'$filepath'";console.log(await '$funcname'());' | |
deno run -A "$dataurl" |
This file contains 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
brew install SergioBenitez/osxct/x86_64-unknown-linux-gnu | |
DEB_NAME=libssl-dev_1.1.1n-0+deb10u3_amd64.deb | |
OPENSSL_DIR="$HOME/.cache/temp/libssl_dev" | |
mkdir -p $OPENSSL_DIR/include | |
cd $OPENSSL_DIR | |
curl -O http://ftp.us.debian.org/debian/pool/main/o/openssl/$DEB_NAME | |
ar p $DEB_NAME data.tar.xz | tar xvf - | |
mv usr/include/openssl/* usr/include/x86_64-linux-gnu/openssl/ |
This file contains 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
export function HomePage() { | |
const { setTemplate, update } = createPage() | |
const title = 'Example' | |
const heading = 'Simple Counter' | |
let clicked = 0 | |
function increment() { | |
clicked++ | |
update('#message') |
This file contains 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
events { | |
} | |
http { | |
server { | |
listen 80 default_server; | |
listen [::]:80 default_server; | |
server_name localhost; | |
root /usr/share/nginx/html; |
This file contains 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
<?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> | |
<key>CFBundleDisplayName</key> | |
<string>MyApplication</string> | |
<key>CFBundleExecutable</key> | |
<string>MyApplication</string> | |
<key>CFBundleIconFile</key> | |
<string>MyApplication.icns</string> |
This file contains 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 { serve } from 'https://deno.land/[email protected]/http/mod.ts' | |
const listener = Deno.listen({ port: 3000 }) | |
await serve(listener, () => { | |
console.log('before throw') | |
throw new Error('whoa! this does not print') | |
console.log('after throw') | |
return new Response('hello world') |
This file contains 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 './2.ts' |
This file contains 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
export function makeEncryptor(key: string) { | |
const textToChars = (text: string) => text.split('').map(c => c.charCodeAt(0)) | |
const byteHex = (n: number) => ('0' + Number(n).toString(16)).substr(-2) | |
const applyKeyToChar = (code: number) => textToChars(key).reduce((a, b) => a ^ b, code) | |
function decrypt(encoded: string) { | |
return (encoded.match(/.{1,2}/g) || []) | |
.map(hex => parseInt(hex, 16)) | |
.map(applyKeyToChar) | |
.map(charCode => String.fromCharCode(charCode)) |
This file contains 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 { createStreaming } from "https://dprint.dev/formatter/v2.ts"; | |
const globalConfig = { | |
indentWidth: 2, | |
lineWidth: 80, | |
}; | |
console.log("before createStreaming") | |
const tsFormatter = await createStreaming( |
NewerOlder