Skip to content

Instantly share code, notes, and snippets.

View debkanchan's full-sized avatar
🤖
tinkering with ai

DK debkanchan

🤖
tinkering with ai
View GitHub Profile
@debkanchan
debkanchan / index.ts
Last active October 29, 2024 09:21
ChromaDB on GCP (using Pulumi)
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const chromaApiKey = new pulumi.Config("chroma").requireSecret("apiKey");
const zone = gcp.config.region || <your preferred region>;
// Create a new secret for Chroma API key.
const chromaApiKeySecret = new gcp.secretmanager.Secret(
"chroma-api-key-secret",
{
@debkanchan
debkanchan / setup-trunk.sh
Created July 2, 2022 13:55
Trunk git hooks setup
# We will use .githooks as hooks path but you can use your own
mkdir .githooks
# Add the pre-commit formatting hook
cat >>.githooks/pre-commit <<EOF
trunk fmt
EOF
# Add pre push linting hook
cat >>.githooks/pre-push <<EOF
@debkanchan
debkanchan / nested-map.ts
Created February 11, 2022 17:18
Nested Map of a type in js
type NestedMap<V> = { [key: string]: V | NestedMap<V> };
let myObj: NestedMap<number> = {} //valid
myObj = {a: 5} //valid
myObj = {a: 'sdfsdf'} //invalid
myObj = {a: 5, b: { c: 2 }} //valid
myObj = {a: 5, b: { c: 'foobar' }} //invalid
myObj = {a: 5, b: { c: { d: { e: { f: { g: 5}}}}}} //valid
@debkanchan
debkanchan / promised_returned_type.ts
Last active December 26, 2021 19:07
Get Promised return type of an async function in TypeScript
type PromisedReturnType<T extends (...args: any) => any> = T extends (...args: any[]) => PromiseLike<infer R> ? R : any
//usage
async function f1() {
return "Value";
}
async function f2(): Promise<number> {
return Promise.resolve(5);
}
@debkanchan
debkanchan / dart.json
Created February 12, 2021 16:52
Flutter Riverpod Snippets
{
"Hook Widget": {
"prefix": "hookw",
"body": [
"class ${1:WidgetName} extends HookWidget {",
"\t@override",
"\tWidget build(BuildContext context) {",
"\t\treturn ${2};",
"\t}",
"}",
@debkanchan
debkanchan / dart.json
Created February 12, 2021 16:50
Flutter/Dart Freezed Snippets
{
"Freezed Class": {
"prefix": "frz",
"body": [
"import 'package:freezed_annotation/freezed_annotation.dart';",
"",
"part '${1/(.*)/${1:/downcase}/}.freezed.dart';",
"part '${1/(.*)/${1:/downcase}/}.g.dart'",
"",
"@freezed",
@debkanchan
debkanchan / regex.md
Last active February 27, 2025 10:17
RegEx for Latitude and Longitude

Regular Expression(RegExp) for Latitude and Longitude

Just Latitude:

^-?([0-8]?[0-9]|90)(\.[0-9]{1,10})$

matches:

  • 56.3847
  • -56.387

unmatches:

@debkanchan
debkanchan / decodePolyline.dart
Last active April 25, 2020 06:09
Flutter/Dart Google Maps API encoded polyline decoder
List _decode(String input) {
var list=input.codeUnits;
List lList = new List();
int index=0;
int len=input.length;
int c=0;
List<LatLng> positions = new List();
// repeating until all attributes are decoded
do {
var shift=0;