Skip to content

Instantly share code, notes, and snippets.

@airicbear
airicbear / shadertoy-distance.glsl
Created January 19, 2025 18:29
shadertoy-distance
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
// Normalized pixel coordinates (from 0 to 1)
vec2 res = vec2(10.0, 10.0);
vec2 uv = fragCoord/res.xy;
vec2 uvMouse = iMouse.xy/res.xy;
// Calculate distance
float uvMouseDistX = uvMouse.x - uv.x;
float uvMouseDistY = uvMouse.y - uv.y;

Run server

Run a server at some port.

Put Caddyfile in Program Files/caddy

Example:

nguyene.duckdns.org
@airicbear
airicbear / cloudfront_static_website.md
Last active August 17, 2024 15:33
Create a static website in CloudFront

How to create a static website in CloudFront

  1. Create an AWS account Account-A for the root hosted zone.

  2. Create an AWS account Account-B for the static assets.

  3. Register a domain in Account-A.

  4. Create a root hosted zone in Account-A.

AWS Access Portal

Issue

Can't find AWS account in AWS access portal

Error message

Account sign in error >

@airicbear
airicbear / index.js
Created July 13, 2024 17:26
Get started with AWS SDK for JavaScript v3
import { createInterface } from "readline/promises";
import {
S3Client,
PutObjectCommand,
CreateBucketCommand,
DeleteObjectCommand,
DeleteBucketCommand,
paginateListObjectsV2,
GetObjectCommand,
import fs from "fs";
import { NextApiRequest, NextApiResponse } from "next";
import path from "path";
type Data = {
files: string[];
};
export default function handler(
req: NextApiRequest,
@airicbear
airicbear / diffaugment.py
Created February 20, 2023 19:09
DiffAugment
from typing import Callable, Dict, List
import tensorflow as tf
from .consts import strategy
with strategy.scope():
def diff_augment(x: tf.Tensor,
policy: str = '',
channels_first: bool = False) -> tf.Tensor:
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@airicbear
airicbear / fit.jl
Created March 28, 2022 22:07
Linear fit on x and y, in y = mx + b form
function fit(x,y)
= mean(x)
= mean(y)
# Calculation of fit parameters
m = sum([(xi - x̄) * yi for (xi, yi) zip(x, y)]) / sum([(xi - x̄)^2 for xi x])
b =- m*
# Calculation of standard error
D = sum([(xi - x̄)^2 for xi x])