Skip to content

Instantly share code, notes, and snippets.

View anhtuank7c's full-sized avatar

Tuan Nguyen anhtuank7c

View GitHub Profile

Encrypting data with AES128 in JavaScript

Usage

AES128 uses a 16 byte secret key.

const key = new Uint8Array(16);
crypto.getRandomValues(key);
@MarceloPrado
MarceloPrado / useToggleStorybook.ts
Created October 18, 2023 12:32
Dynamically toggle between storybook and app
import { config } from "@/app/config";
import { createLogger } from "@/app/observability";
import { useEffect } from "react";
const { appEnv } = config;
const logger = createLogger("developer/storybook");
export const useToggleStorybook = () => {
const [isStorybookEnabled, setIsStorybookEnabled] = useState(false)
@coehne
coehne / Readme.md
Last active February 5, 2025 14:26
Host SvelteKit on Firebase Hosting with Framework Aware Hosting

SvelteKit + Firebase Hosting

These are instructions for setting up a SvelteKit demo project and deploying it to Firebase with framework aware hosting.

Installation steps

Setup SvelteKit

Setup a new SvelteKit project with:

@ciiqr
ciiqr / zod-optional-null.ts
Last active February 27, 2025 13:28
zod optional/nullable/nullish differences
// zod schema
z.object({
// valid if string or:
optional: z.string().optional(), // field not provided, or explicitly `undefined`
nullable: z.string().nullable(), // field explicitly `null`
nullish: z.string().nullish(), // field not provided, explicitly `null`, or explicitly `undefined`
});
// type
{
@acarril
acarril / bootable-win-on-mac.md
Created November 18, 2022 17:49
Create a bootable Windows USB using macOS

For some reason, it is surprisingly hard to create a bootable Windows USB using macOS. These are my steps for doing so, which have worked for me in macOS Monterey (12.6.1) for Windows 10 and 11. After following these steps, you should have a bootable Windows USB drive.

1. Download a Windows disc image (i.e. ISO file)

You can download Windows 10 or Windows 11 directly from Microsoft.

2. Identify your USB drive

After plugging the drive to your machine, identify the name of the USB device using diskutil list, which should return an output like the one below. In my case, the correct disk name is disk2.

@samsch
samsch / .md
Created June 4, 2022 00:08
Why React Data Fetching is Hard (right now)

Why React Data Fetching is Hard (right now)

Context

Recently Dan Abramov has been linking drafts of a new documentation page for useEffect, which has kicked off discussion about where you are "supposed" to do data fetching in a "React app". Some of that conversation is happening on Twitter such as here: https://twitter.com/dan_abramov/status/1532540685710147589

Within the draft and repeated on Twitter, there is a recommendation that for data fetching you should use third party libraries as either tools like React Query or useSWR or via frameworks such as Next and Remix which include integrated data fetching solutions. Writing your own data fetching using useEffect is suggested to be only a fallback in case you can't do those things, and not really a preferred recommendation.

This idea is hitting backlash, with a basic detracting idea that boils down to: React is a client side framework, how can it not include as a feature an important and common requirement like data loading.

@zhenguet
zhenguet / data.js
Last active February 22, 2022 01:28
Journey
export const Cartrip = [
{
TripInfoID: 33798,
driver: "347722874183",
CarID: 646,
Speed: 4.0,
Lt: 20.800825,
Ln: 106.903534,
Oil: 427,
Acc: "Bật",
@DenisJunio
DenisJunio / install_php_8_1.sh
Last active December 5, 2024 16:40
Laravel - PHP 8.1 Extensions - Ubuntu
#!/bin/bash
sudo apt install software-properties-common && sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
sudo apt upgrade -y
sudo apt install php8.1 -y
sudo apt install php8.1-bcmath -y
sudo apt install php8.1-bz2 -y
sudo apt install php8.1-cli -y
sudo apt install php8.1-common -y
sudo apt install php8.1-curl -y
@eveningkid
eveningkid / react-native-reanimated-drag-sort_apple-music.jsx
Last active November 2, 2024 23:36
React Native Reanimated 2 Multiple Drag and Sort: Apple Music Example
// Expo SDK40
// expo-blur: ~8.2.2
// expo-haptics: ~8.4.0
// react-native-gesture-handler: ~1.8.0
// react-native-reanimated: ^2.0.0-rc.0
// react-native-safe-area-context: 3.1.9
import React, { useState } from 'react';
import {
Image,
@nd3w
nd3w / install-nginx-mariadb-phpfpm-on-ubuntu-20.04.md
Last active September 24, 2024 08:18
How to Install Nginx, MariaDB, PHP-FPM on Ubuntu 20.04

How to Install Nginx, MariaDB, PHP-FPM on Ubuntu 20.04

This is a way to install and set up Nginx, MariaDB and PHP-FPM on Ubuntu 20.04.

NOTE: This has been prepared for ease of use in mind, not security, mostly in development machine. Please do not use these instructions to setup on a public server environment. Use other proper manuals instead.

First fetch the latest package list of Ubuntu:

$ sudo apt update