Skip to content

Instantly share code, notes, and snippets.

View channyeintun's full-sized avatar

Chan Nyein Tun channyeintun

View GitHub Profile
package main
func changeMap(m1 *map[string]int) {
m1 = &map[string]int{"hello": 2}
}
func changeMap2(m2 *map[string]int) {
*m2 = map[string]int{"hello": 2} // without dereferencing, Go cannot achieve this
}
package main
import "fmt"
func main() {
// Let's prevent compile-time optimization by using variables
a := 0.1
b := 0.2
c := 0.3
@channyeintun
channyeintun / FlacAudioRecorder.js
Created October 27, 2023 16:47
Encode microphone audio to flac format in React.js
// To encode microphone audio to flac format in React.js
// put encoder.js, libflac3-1.3.2.min.js, libflac3-1.3.2.min.js.mem in public folder
// Get necessary files from https://github.com/mmig/speech-to-flac
export function FlacAudioRecorder({ onData }) {
let recording = false;
let stream;
let input;
let node;
@channyeintun
channyeintun / useCustomFilter.js
Last active November 20, 2022 18:11
Optimized React Custom Filter Hook
import { useEffect, useState } from "react";
import { useSelector } from "react-redux";
/*
Instead of JSON.stringifying the array of objects to use as deps in useMemo
hook, I've created custom hook that generate serial string which can be used
to decide whether filtered result should be updated or not. So, filtered result
can be used in useMemo hook without JSON.stringifying.
e.g
@channyeintun
channyeintun / showPositionMarker.js
Created April 15, 2022 14:33 — forked from jh3y/showPositionMarker.js
show text cursor position marker
/**
* shows a position marker that highlights where the cursor is
* @param {object} e - the input or click event that has been fired
*/
const showPositionMarker = e => {
// grab the input element
const { currentTarget: input } = e
// create a function that will handle clicking off of the input and hide the marker
const processClick = evt => {
if (e !== evt && evt.target !== e.target) {
@channyeintun
channyeintun / getCursorXY.js
Created April 15, 2022 14:30 — forked from jh3y/getCursorXY.js
get text cursor position
/**
* returns x, y coordinates for absolute positioning of a span within a given text input
* at a given selection point
* @param {object} input - the input element to obtain coordinates for
* @param {number} selectionPoint - the selection point for the input
*/
const getCursorXY = (input, selectionPoint) => {
const {
offsetLeft: inputX,
offsetTop: inputY,
@channyeintun
channyeintun / eventIterator.js
Created September 2, 2021 05:28 — forked from jkempff/eventIterator.js
Async generator for DOM events
async function* eventIterator(element, eventName, subscribed) {
while(true) {
yield new Promise(resolve => {
const listener = e => {
element.removeEventListener(eventName, listener);
resolve(e);
};
element.addEventListener(eventName, listener);
})
@channyeintun
channyeintun / EventRecorder.js
Created September 2, 2021 05:28 — forked from jkempff/EventRecorder.js
Records DOM-events and replays them on demand. Nice for server side rendered pages: record during page-load, replay after all javascript was initialized.
/**
* EventRecorder
* @class
* @classdesc An EventRecorder can record and replay any event on any DOM node
* @param {string} [eventName=click] - Name of the events to record
* @param {class} [EventClass=MouseEvent] - The class that should be used to recreate the events
* @param {object} [context=self] - The context DOM element, the events should be fetched from
* @example
* // Create a recorder for click events
* const clickRecorder = new EventRecorder('click', MouseEvent, window);
အရင်ကရေးဖူးတယ်။
Global Scope မှာရေးထားတဲ့ JavaScript Function တစ်ခုကို ဘယ်နှနည်းနဲ.ခေါ်လို.ရနိုင်ပါသလဲ :3
function hello()
{
console.log("JavaScript");
}
hello();
hello.call();
hello.apply();
hello.bind()();