Skip to content

Instantly share code, notes, and snippets.

View hieunc229's full-sized avatar
🎯
Focusing

Hieu Nguyen (Jack) hieunc229

🎯
Focusing
View GitHub Profile
@hieunc229
hieunc229 / countryToFlag.js
Created June 14, 2021 02:28
Get country flag using its code
// ISO 3166-1 alpha-2
// ⚠️ No support for IE 11
// Source: all over the internet
function countryToFlag(code) {
let isoCode = code.split("-").pop()
return typeof String.fromCodePoint !== 'undefined'
? isoCode
.toUpperCase()
.replace(/./g, (char) => String.fromCodePoint(char.charCodeAt(0) + 127397))
: isoCode;
@hieunc229
hieunc229 / App.js
Last active June 8, 2021 03:58
Example of using Vasern with React Hooks
import React, { useState, useEffect } from "react";
import MyDB from "./conn";
import {
View, Text
} from "react-native";
export function App() {
const [items, setItems] = useState();
@hieunc229
hieunc229 / VersionControlObject.ts
Last active December 8, 2020 10:24
Object with version control, used for undo/redo
/**
* VersionControlObject allow you versioning an object,
* which show number of updates, go back and ford between the version.
* ---------------------------------------------------------------------------------------------------
* This is a typescript version with minor updates based on trincot answer on stackoverflow
* https://stackoverflow.com/a/40498130/5775993
*/
export class VersionControlObject<T> {
targets: any[] = [];
@hieunc229
hieunc229 / enumClass.js
Last active January 2, 2019 14:14
A typesafe enum implementation for JavaScript
class Enum {
constructor(type) {
Enum.initEnumType(type);
this.type = type;
}
/**
* Initate enum values ** Internal use only
* Iterate through given values and intiate enum value object
@hieunc229
hieunc229 / vasern-date-filter-example.js
Created November 27, 2018 23:17
Demonstrate filter records by date between start and end date
// An example 'TodoItems' schema with 'dueDate' using 'datetime'
var db = new Vasern({ schema: {
name: "TodoItems",
props: {
name: "string",
dueDate: "datetime"
}
}});