Skip to content

Instantly share code, notes, and snippets.

View chientrm's full-sized avatar
🏠
Working from home

Chien Tran chientrm

🏠
Working from home
View GitHub Profile
@chientrm
chientrm / gtm.svelte
Created January 25, 2024 06:44
SvelteKit Google Tag Manager
onMount(() => {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' });
const gtmScript = document.createElement('script');
gtmScript.src = 'https://www.googletagmanager.com/gtm.js?id=' + PUBLIC_TAG_ID;
document.head.append(gtmScript);
});
@chientrm
chientrm / +server.ts
Last active February 2, 2024 03:58
SvelteKit PayPal webhook
import { CLIENT_SECRET, PAYPAL, WEBHOOK_ID } from '$env/static/private';
import { PUBLIC_CLIENT_ID } from '$env/static/public';
import { Events } from '$lib/schema';
import { forceOk } from '$lib/util.server';
import { Buffer } from 'node:buffer';
const authenticate = () =>
fetch(`${PAYPAL}/v1/oauth2/token`, {
method: 'POST',
headers: {
@chientrm
chientrm / player.ts
Last active December 9, 2023 03:07
Reconcile glitch
import type { PlayerController } from '@chientrm/game';
import type { GameScene } from './scene';
export class Player {
ship: Phaser.GameObjects.Sprite;
flame: Phaser.GameObjects.Sprite;
controller: PlayerController;
anim: string;
constructor(scene: GameScene, controller: PlayerController, slot: number) {
this.controller = controller;
@chientrm
chientrm / worker.ts
Created August 20, 2023 17:43
Worker MailChannels
import { zValidator } from '@hono/zod-validator';
import { Hono } from 'hono';
import { z } from 'zod';
const app = new Hono<{ Bindings: { DKIM_PRIVATE_KEY: string } }>();
app.get('/', (c) => c.text('Hello Hono!'));
app.post(
'/send_email',
zValidator(
@chientrm
chientrm / gist:c1250422b982593c3ebd31ed35735e16
Created August 16, 2023 17:32 — forked from BjornDCode/gist:5cb836a6b23638d6d02f5cb6ed59a04a
Tailwind - Fixed sidebar, scrollable content
// Source: https://twitter.com/calebporzio/status/1151876736931549185
<div class="flex">
<aside class="h-screen sticky top-0">
// Fixed Sidebar
</aside>
<main>
// Content
</main>
@chientrm
chientrm / worker.ts
Created August 15, 2023 07:33
mailshitpostai
import { array, object, string } from 'yup';
import { validate } from './validate';
import { Router, json, error } from 'itty-router';
export default {
async fetch(
request: Request,
env: Env,
ctx: ExecutionContext,
): Promise<Response> {
Scaffold(
snackbarHost = { SnackbarHost(snackbarHostState) },
bottomBar = {
NavigationBar {
val navBackStackEntry by navController.currentBackStackEntryFlow.collectAsState(null)
val currentDestination = navBackStackEntry?.destination
NavigationBarItem(
selected = currentDestination?.route == Routes.HOME,
onClick = {
navController.navigate(Routes.HOME) {
package site.chientrm.youwave.services.youwave
import com.google.firebase.auth.FirebaseAuth
import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.tasks.await
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
@chientrm
chientrm / worker.js
Last active October 3, 2022 17:11
Sample CF Worker
const
_ = {
author : 'chientrm',
title : 'TODO list with CF Worker',
description : 'This project is done via quick edit only',
year : '2022',
keywords : 'cloudflare, worker, quick, edit',
license : 'MIT',
},
_________________________CONSTANTS_____________________________=_,
{
...
"scripts": {
...
"dist": "npm run build && node esbuild.js",
...
},
"type": "module"
}