Skip to content

Instantly share code, notes, and snippets.

View 0xlkda's full-sized avatar
🇻🇳
code đi anh em

Alex 0xlkda

🇻🇳
code đi anh em
  • Viet Nam
  • 15:47 (UTC +07:00)
View GitHub Profile
@0xlkda
0xlkda / index.converter.js
Last active May 14, 2024 12:17
index of converters
import UnitOfDigital from './unit-of-digital.converter.js'
import UnitOfTime from './unit-of-time.converter.js'
export {
UnitOfDigital,
UnitOfTime,
}
@0xlkda
0xlkda / track-function.js
Created May 13, 2024 08:34
log function args and output with execution time
import { UnitOfTime } from './converter.js'
function timing(fn) {
let perf = performance
let A = perf.now()
let result = fn()
let B = perf.now()
return [result, B - A]
}
async function timingAsync(asyncFn) {
@0xlkda
0xlkda / new-plugin-setup-template.lua
Created February 28, 2023 09:39
template for new neovim plugin
function M.setup(opts)
-- Look up keys in user-defined table with fallback to defaults.
M.opts = setmetatable(opts or {}, {__index = require'app.defaults'})
M.initialized = true
-- Insert the engine and register the autocommand if asked to.
local engine = require'app.engine'
-- engine.do_work()
if M.opts.create_app_autocmd then
// Detects encoding of a buffer
exports.detectEncoding = function (buffer) {
for (var i = 0; i < buffer.length; i++) {
if (buffer[i] === 65533 || buffer[i] <= 8) {
// The character code 65533 is often used as a replacement character for an unknown or unprintable character in a text file.
// The check for values less than or equal to 8 is intended to exclude control characters which are typically not part of human-readable text.
return 'binary'
}
}
return 'utf8'
#!/bin/bash
# process 1:
$ mkdir /tmp/anything # create entry
$ exec 42> /tmp/anything/42 # open write on 42
$ echo "message here" >&42 # write message to 42
$ exec 42>&- # close write 42
# process 2:
$ exec 42< /tmp/anything/42 # open read on 42
$ cat <&42 # read from 42 and pipe to cat
@0xlkda
0xlkda / notes
Created December 21, 2022 14:42
Quick notes
first npm commit: https://github.com/npm/cli/commit/4626dfa73
@0xlkda
0xlkda / countryToFlag.js
Created July 24, 2021 18:48 — forked from hieunc229/countryToFlag.js
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;
const getAllCombinations = (arraysToCombine) => {
const divisors = [];
let permsCount = 1;
for (let i = arraysToCombine.length - 1; i >= 0; i--) {
divisors[i] = divisors[i + 1] ? divisors[i + 1] * arraysToCombine[i + 1].length : 1;
permsCount *= (arraysToCombine[i].length || 1);
}
const getCombination = (n, arrays, divisors) => arrays.reduce((acc, arr, i) => {
acc.push(arr[Math.floor(n / divisors[i]) % arr.length]);
@0xlkda
0xlkda / filter.js
Created September 24, 2020 11:53
Filter by list of conditions
const filterBy = (conditions, index = 0) => (value) => {
if(conditions[index] === undefined) return value
if(!conditions[index](value)) return
return filterBy(conditions, index + 1)(value)
}
const values = [1, 2, 3, 4, 5, 6, 7, 8, 9 , 10, 25, 27]
const odd = (value) => value % 2 !== 0
const greaterThan3 = (value) => value > 3
const canDivide3 = (value) => value % 3 === 0
@0xlkda
0xlkda / SketchSystems.spec
Created July 29, 2020 02:15
Schema Registry Editor
Schema Registry Editor
Inactive
focus -> Active
Active
showHelper -> Active
createSchema -> Editable
Editable
createField -> Editable
deleteField -> Editable
updateField -> Editable