Skip to content

Instantly share code, notes, and snippets.

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

Samuel Chan samuelchanx

🏠
Working from home
View GitHub Profile
@samuelchanx
samuelchanx / getHeader.dart
Created February 11, 2025 04:08
Flutter retry mechanism for getting user token
Future<Map<String, String>?>? getHeader() async {
final authenticated = auth.user != null;
if (!authenticated) {
return null;
}
var currentToken = await auth.user!.getIdToken();
var decodedToken = JwtDecoder.decode(currentToken!);
var retryTimes = 0;
while (decodedToken['https://hasura.io/jwt/claims'] == null &&
retryTimes < 10) {
@samuelchanx
samuelchanx / readme.md
Created November 13, 2024 08:21
Typescript #ts #typescript run command with dotenv file

How to run

  • ts-node -r dotenv/config xxx.ts dotenv_config_path=../../../.env.staging
@samuelchanx
samuelchanx / Generated config ios
Created October 6, 2024 16:46
Kiddy App #secret
DART_DEFINES=QllQQVNTX0FVVEhFTlRJQ0FUSU9OPWZhbHNl,SEFTVVJBX0FETUlOX1NFQ1JFVD0=,SEFTVVJBX0VORF9QT0lOVD1odHRwczovLzUyLjc0LjEyNS4xNC5uaXAuaW8vYXBpL3Jlc3Q=,RU1BSUxfU1VGRklYPUBraWRkeWltYWdpbmF0aW9uLmhr,aXNNb2JpbGU9dHJ1ZQ==,QVBQVVNFUl9FTUFJTF9TVUZGSVg9QHByb2Qua2lkZHlpbWFnaW5hdGlvbi5oaw==
@samuelchanx
samuelchanx / index.js
Created May 25, 2023 09:31
Create #SQL function based on input for loalization computed field
function generateSQLFunction(schemaName, tableName, columnName, isNullable) {
const nonNullableScript = `CREATE OR REPLACE FUNCTION ${schemaName}.${tableName}_${columnName}(data_row ${schemaName}.${tableName}, hasura_session json)
RETURNS text
LANGUAGE sql
STABLE
AS
$function$
SELECT CASE
WHEN (hasura_session ->> 'x-hasura-preferred-lang' = 'en') THEN data_row."${columnName}En"
@samuelchanx
samuelchanx / hook_basic.dart
Created December 19, 2022 11:00
Flutter hooks #dart #flutter
class ShopCouponList extends HookConsumerWidget {
final ShopCouponType type;
const ShopCouponList({
super.key,
required this.type,
});
@override
Widget build(BuildContext context, WidgetRef ref) {
const loadingWidget = Padding(
@samuelchanx
samuelchanx / focus_emulator.applescript
Last active November 8, 2022 15:55
Put the Android emulator to front on Mac #android #mac
tell application "System Events"
if (get name of every application process) contains "scrcpy" then
-- Support the scrcpy emulator
log "Contains scrcpy"
tell application process "scrcpy"
set frontmost to true
end tell
else
-- Support the system emulator
log "ask emulator to show as frontmost"
@samuelchanx
samuelchanx / guide.md
Last active October 28, 2022 10:26
Android create a new secret key #android

How to create a new key

mkdir secrets
keytool -genkey -v -keystore ./secrets/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key

Android setup

build.gradle update

@samuelchanx
samuelchanx / sync.sh
Last active November 8, 2022 15:55
Sync Android Emulator Date Time with your Host Computer #android
# Just run this in your terminal
adb -e shell su root date $(date +%m%d%H%M%Y.%S)
@samuelchanx
samuelchanx / .graphqlrc.yaml
Last active February 20, 2022 04:14
build.yaml for artemis
# To support the GraphQL validation in VSCode
name: "GraphQL API"
schema: "./schema.graphql"
documents: "./graphql/**/*.graphql"
@samuelchanx
samuelchanx / helper.dart
Created January 1, 2022 08:34
Missed dart extensions like in kotlin
ReturnType run<ReturnType>(ReturnType Function() operation) {
return operation();
}
extension ScopeFunctionsForObject<T extends Object> on T {
ReturnType let<ReturnType>(ReturnType Function(T item) operationFor) {
return operationFor(this);
}
T also(void Function(T item) operationFor) {