Skip to content

Instantly share code, notes, and snippets.

View ikhanhmai's full-sized avatar
🎯
Focusing

Khanh Mai ikhanhmai

🎯
Focusing
View GitHub Profile
@ikhanhmai
ikhanhmai / postgres_queries_and_commands.sql
Created October 20, 2023 04:17 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@ikhanhmai
ikhanhmai / 01_add_cors.config.yaml
Created March 13, 2023 07:47 — forked from vsviridov/01_add_cors.config.yaml
Add CORS to Nginx on AWS Elastic Beanstalk
container_commands:
01_fix_static_cors:
command: "/tmp/fix_static_cors.sh"
files:
"/tmp/fix_static_cors.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash
@ikhanhmai
ikhanhmai / gist:ae404013a320ce9fe38c6361742bf96f
Created March 12, 2023 03:46
Sample github actions yml file to integrate with Elastic AWS Beanstalk
name: Stage - Deploy Odidi FT BE to AWS Elastic Beanstalk
env:
APP_NAME: OdidiFT
ENV_NAME: Odidiftstage
S3_BUCKET: odidi-ft
AWS_REGION: ap-southeast-1
AWS_PLATFORM: Docker
PIPELINE_ID: ${GITHUB_RUN_ID}-${GITHUB_RUN_NUMBER}

Problem

I have two Github accounts: oanhnn (personal) and superman (for work). I want to use both accounts on same computer (without typing password everytime, when doing git push or pull).

Solution

Use ssh keys and define host aliases in ssh config file (each alias for an account).

How to?

  1. Generate ssh key pairs for accounts and add them to GitHub accounts.
@ikhanhmai
ikhanhmai / dataURItoBlob.js
Created September 22, 2019 10:37
dataURItoBlob
dataURItoBlob = (dataURI) => {
// convert base64 to raw binary data held in a string
// doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this
var byteString = atob(dataURI.split(',')[1]);
// separate out the mime component
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]
// write the bytes of the string to an ArrayBuffer
var ab = new ArrayBuffer(byteString.length);
@ikhanhmai
ikhanhmai / gist:fccf5aefdb6ba2420278
Created December 29, 2015 02:20
Unity - Get transparency of one pixel
using UnityEngine;
using System.Collections;
public class RayCasting : MonoBehaviour {
void Update () {
if (!Input.GetMouseButtonDown(0))
{
return;
@ikhanhmai
ikhanhmai / gist:dff88bb0819feab847f3
Last active December 11, 2015 07:07
Unity - Parse Callback in Main thread
System.Threading.Tasks.Task queryTask;
try {
queryTask = ParseObject.SaveAllAsync (rewards);
} catch {
queryTask = null;
}
if (queryTask != null) {
@ikhanhmai
ikhanhmai / UnitySerializerClass
Created December 10, 2015 10:56
Unity C# - Serializer Class
using System;
using System.IO;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters.Binary;
public class Serializer
{
public static T Load<T>(string filename) where T: class
import Foundation
extension String
{
// Works in Xcode but not Playgrounds because of a bug with .insert()
mutating func insertString(string:String,ind:Int) {
var insertIndex = advance(self.startIndex, ind, self.endIndex)
for c in string {
@ikhanhmai
ikhanhmai / isCustomKeyboardEnabled
Created December 10, 2015 02:03
iOS - is your Custom Keyboard enable?
func isCustomKeyboardEnabled() -> Bool {
let bundleID: String = "com.app.smappikeyboard.child"
// Replace this string with your custom keyboard's bundle ID
NSUserDefaults.standardUserDefaults().dictionaryRepresentation()
let keyboards: [String] = NSUserDefaults.standardUserDefaults().dictionaryRepresentation()["AppleKeyboards"]! as! [String]
// Array of all active keyboards
for keyboard: String in keyboards {
print("keyboard",keyboard)
if (keyboard == bundleID) {
return true