Skip to content

Instantly share code, notes, and snippets.

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

Ken choong kenchoong

🏠
Working from home
View GitHub Profile
@kenchoong
kenchoong / determination-api-stack.ts
Created May 1, 2021 09:29 — forked from hassaku63/determination-api-stack.ts
aws-cdk example - API Gateway V2 HTTP API & lambda NodejsFunction
import * as path from 'path';
import * as cdk from '@aws-cdk/core';
import * as ddb from '@aws-cdk/aws-dynamodb';
import * as apiGatewayV2 from '@aws-cdk/aws-apigatewayv2';
import { LambdaProxyIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';
import { NodejsFunction, NodejsFunctionProps } from '@aws-cdk/aws-lambda-nodejs';
import { HttpIntegration, HttpIntegrationType } from '@aws-cdk/aws-apigatewayv2';
import { dirname } from 'path';
const project_root_dir = path.join(dirname(__filename), '../')
@kenchoong
kenchoong / change-permission.text
Created March 26, 2020 13:40
Change ownership and permission of a folder which inside a docker container from terminal
docker container start <container_name>
// access the docker
docker exec -u root -it <container_name> /bin/sh
//here change ownership of a folder
chown -R user_name:group_name <path/of/folder/that/need/to/change/permission>
//here change permission of a folder
chmod -R 755 /folder/path/that/need/to/change/permission
@kenchoong
kenchoong / SharedPreferenceLiveData.kt
Created January 10, 2020 20:17 — forked from rharter/SharedPreferenceLiveData.kt
Creates LiveData objects that observe a value in SharedPreferences while they have active listeners.
import android.arch.lifecycle.LiveData
import android.content.SharedPreferences
abstract class SharedPreferenceLiveData<T>(val sharedPrefs: SharedPreferences,
val key: String,
val defValue: T) : LiveData<T>() {
private val preferenceChangeListener = SharedPreferences.OnSharedPreferenceChangeListener { sharedPreferences, key ->
if (key == this.key) {
value = getValueFromPreferences(key, defValue)
abstract class SharedPreferenceLiveData<T> extends LiveData<T> {
SharedPreferences sharedPrefs;
String key;
T defValue;
public SharedPreferenceLiveData(SharedPreferences prefs, String key, T defValue) {
this.sharedPrefs = prefs;
this.key = key;
this.defValue = defValue;
@kenchoong
kenchoong / py-gitignore
Created January 6, 2020 09:34 — forked from MOOOWOOO/py-gitignore
python pycharm gitignore
# Created by .ignore support plugin (hsz.mobi)
### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
@kenchoong
kenchoong / gist:e14adeecf5e8c2a77791d7965b384982
Created January 5, 2020 17:27 — forked from pingwping/gist:92219a8a1e9d44e1dd8a
Create and update embedded documents with MongoEngine
# REF: http://www.quora.com/How-do-I-create-and-update-embedded-documents-with-MongoEngine
class Comment(EmbeddedDocument):
content = StringField()
name = StringField(max_length=120)
class Post(Document):
title = StringField(max_length=120, required=True)
author = StringField(required=True)
@kenchoong
kenchoong / Fcm.php
Created March 9, 2018 19:36
Fcm.php
<?php
/*
* Add FCM Class
*/
class Google_Service_Fcm extends Google_Service
{
/** Set URL for Google Cloud Platform services. */
const CLOUD_PLATFORM = "https://www.googleapis.com/auth/cloud-platform";
const FCM = "https://www.googleapis.com/auth/firebase.messaging";
@kenchoong
kenchoong / AVPlayer+IsPlaying.swift
Created March 2, 2018 07:50 — forked from melvinbeemer/AVPlayer+IsPlaying.swift
Check if AVPlayer is currently playing an item
import Foundation
import AVFoundation
extension AVPlayer {
var isPlaying: Bool {
if (self.rate != 0 && self.error == nil) {
return true
} else {
return false