Skip to content

Instantly share code, notes, and snippets.

View taivo's full-sized avatar

Tai Vo taivo

View GitHub Profile
@taivo
taivo / d1-config-loader.ts
Created May 15, 2025 10:34
Load d1 config from wrangler.jsonc (yaml, json, etc.) and generate the local sqlite filename matching the filename used by miniflare
import crypto from "node:crypto"
import { existsSync } from "node:fs"
import { unstable_readConfig } from "wrangler"
export class D1Config {
binding: string
database_name: string
database_id: string
preview_database_id?: string
migrations_dir?: string
@taivo
taivo / drizzle-d1-proxy.ts
Created May 15, 2025 10:30
drizzle-d1-proxy using cloudflare typescript sdk
import Cloudflare from "cloudflare"
import type { DatabaseQueryParams, DatabaseRawParams } from "cloudflare/resources/d1/database.mjs"
import type { DrizzleConfig } from "drizzle-orm"
import { drizzle as drizzleProxy } from "drizzle-orm/sqlite-proxy"
export type D1Credentials = {
accountId: string
databaseId: string
token: string
}
@taivo
taivo / parse-com-anon-auth.js
Last active February 1, 2017 21:32
Anonymous user, anonymous auth with Parse JS SDK
//This is my hackish way to use methods that are already in Parse JS SDK v1.5
//to logIn as an anonymous user. Hackish because it relies on internal methods
//that starts with an underscore and thus subject to change. In any case, it
//helped me move passed authentication and on to the main parts of my project
//and I hope it helps you too.
Parse._getInstallationId().done(
function(installationId){
//
// use installation id because it's already a UUID
@taivo
taivo / ionic-google-maps-autocomplete-remove-300ms
Last active October 29, 2016 18:14
Remove 300ms delay from google maps autocomplete in ionic framework. Inspired by http://davidwalsh.name/detect-node-insertion . Tested on: Nexus 5 Android, Nexus 7 tablet, and iPhone 6 Safari
//
// CSS - define a keyframe animation called 'nodeInserted'
//
@keyframes nodeInserted {
from { opacity: 0.99; }
to { opacity: 1; }
}
@-webkit-keyframes nodeInserted{
from { opacity: 0.99; }
to { opacity: 1; }
@taivo
taivo / ion-tabs-swipable.js
Created December 16, 2014 02:37
Swipe navigation for ion-tabs (for ionic framework v 1.0.0)
angular.module('yourModule')
.directive('tabsSwipable', ['$ionicGesture', function($ionicGesture){
//
// make ionTabs swipable. leftswipe -> nextTab, rightswipe -> prevTab
// Usage: just add this as an attribute in the ionTabs tag
// <ion-tabs tabs-swipable> ... </ion-tabs>
//
return {
restrict: 'A',
require: 'ionTabs',
@taivo
taivo / x-editable-radiolist
Last active March 2, 2019 09:23
radiolist support for x-editable
/**
List of radio buttons. Unlike checklist, value is stored internally as
scalar variable instead of array. Extends Checklist to reuse some code.
@class radiolist
@extends checklist
@final
@example
<a href="#" id="options" data-type="radiolist" data-pk="1" data-url="/post" data-title="Select options"></a>
<script>