Skip to content

Instantly share code, notes, and snippets.

@bramaudi
bramaudi / mkdir.js
Created September 24, 2021 02:28
NodeJS recursive mkdir
fs.mkdir(dirname(blankFile), { recursive: true}, async function (err) {
fs.writeFileSync(blankFile, 'contetn')
});
@bramaudi
bramaudi / maplist.js
Last active February 8, 2022 08:53
Vanilla JS loop templating based on Array<object>.
/**
* Loop Templating
* @param {Array<{ [key: string]: unknown }>} data
*/
function maplist($el, data, customRegExp) {
const interpolationRegex = customRegExp || /\[([\w]+)\]/g;
const num = (item, i) => ({i, n: i+1, ...item})
$el._$ = $el._$ || $el.innerHTML;
$el.textContent = '';
@bramaudi
bramaudi / index.html
Created April 14, 2021 23:39 — forked from billmei/index.html
Responsive Tables in pure CSS
<table>
<thead>
<tr>
<th>Payment</th>
<th>Issue Date</th>
<th>Amount</th>
<th>Period</th>
</tr>
</thead>
<tbody>
@bramaudi
bramaudi / 00_etc-hosts.md
Created March 4, 2021 21:19 — forked from mul14/00_etc-hosts.md
/etc/hosts for Vimeo, Reddit, and Imgur.

Unblock Vimeo, Reddit, Imgur, dan NPM

Saya support Internet Positif untuk memblokir porn, situs judi, dan hal-hal ilegal lainnya. Tapi pemerintah dan ISP sangat konyol karena tidak mengizinkan akses ke Vimeo, Reddit, Imgur, Netflix--yang mana bukanlah situs dengan konten utama ilegal.

Linux / BSD / macOS

Tambahkan list di bawah ke /etc/hosts.

Windows

@bramaudi
bramaudi / ratio.js
Created February 2, 2021 11:46
GCF Ration
// Greatest Common Factor with Euclidean Algorithm
const GCF = (a, b) => {
if (b === 0) return a
else return GCF(b, a % b)
}
// Divide each number by GCF
const ratio = (a, b) => {
const c = GCF(a, b)
a = a / c
@bramaudi
bramaudi / rating.html
Created January 27, 2021 09:34
Minimal HTML Rating Input
<style>
.input-rating {
text-align: left;
}
.rating {
unicode-bidi: bidi-override;
direction: rtl;
}
.rating > span {
display: inline-block;
@bramaudi
bramaudi / pubsub.js
Created January 4, 2021 00:16
Native Javascript EventBus
export default class EventBus {
__eventTarget
constructor(description = '') {
this.__eventTarget = document.appendChild(document.createComment(description))
}
/**
* Add event
@bramaudi
bramaudi / obervser.js
Created January 4, 2021 00:15
ES6 Proxy Oberver with support nested changes
const handler = function () {
return {
get: function (obj, prop) {
console.log('get');
// Recursive handler for nested state
if (['[object Object]', '[object Array]'].indexOf(Object.prototype.toString.call(obj[prop])) > -1) {
return new Proxy(obj[prop], handler());
}
return obj[prop];
},
@bramaudi
bramaudi / reIndexAbc.js
Last active July 11, 2020 04:37
Re-order index of alphabet by given new index pattern.
function reIndexAbc(targetAbc, targetIndex) {
const abc = 'abcdefghijklmnopqrstuvwxyz'.split('')
let result = []
let temp
const az1 = []
for (let i = 0; i < abc.indexOf(targetAbc); i++) {
az1.push(abc[i])
}
@bramaudi
bramaudi / form.js
Created May 28, 2020 05:50
Vue Form Helper
export default class FormHandler {
constructor (field = []) {
this.formField = field
}
// menghubungkan vue instance
bind (vm) {
this.vm = vm
}