Skip to content

Instantly share code, notes, and snippets.

View plvhx's full-sized avatar
🏠
Working from home

Paulus Gandung Prakosa plvhx

🏠
Working from home
View GitHub Profile
@plvhx
plvhx / lsb_msb.py
Created July 10, 2022 08:59
lsb to msb (two's complement)
#
# https://en.wikipedia.org/wiki/Two%27s_complement#Working_from_LSB_towards_MSB
#
# (c) 2022 Paulus Gandung Prakosa <[email protected]>
#
import sys
import math
num = int(sys.argv[1])
@plvhx
plvhx / rtab.go
Created March 7, 2022 14:29
Routing method approach #1 (Regex Table)
// Routing approach using Regex Table method.
// 2022 (c) Paulus Gandung Prakosa <[email protected]>
package main
import (
"fmt"
"log"
"regexp"
"sync"
@plvhx
plvhx / hell.regex
Created March 1, 2022 10:28
hellish currency detector
'(?:(?:Rp)(?:\s*)(\d+)|(?:IDR)(?:\s*)(\d+)(?:\,(\d+))+(?:\.\d+)*|(?:Rp\.)(?:\s*)(\d+)(?:\.(\d+))+|(?:RP)(?:\s*)(\d+)(?:(?:\,)(\d+))+(?:\.\-)?|(\d+)((?:(?:\.)(?:\d+))+)(?:\,00)?)'
@plvhx
plvhx / impl.go
Created February 17, 2022 01:49
http.CookieJar interface implementation
package main
import (
"fmt"
"reflect"
"net/http"
"net/url"
)
type CookieJar struct {
@plvhx
plvhx / range.go
Last active February 14, 2022 03:37
range http header
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range
package main
import (
"log"
"strconv"
"strings"
"time"
"regexp"
"encoding/json"
@plvhx
plvhx / go_concurrency_101.md
Last active January 1, 2022 06:38
go concurrency 101
  • parameter supplied to the method 'Add' in the sync.WaitGroup struct must be equal to the current running goroutine. no more, no less.
    • if less than number of current running goroutine, it will leads to unexpected behavior.
    • if more than number of current running goroutine, it will leads to deadlock.
// dirty and simple :))
package main

import (
@plvhx
plvhx / dict_filter.erl
Created August 1, 2021 09:25
filtering dict like a boss.
-module(main).
-export([start/0]).
-import(io, [fwrite/2]).
%% internal callback when calling
%% dict:filter/2
filter_even(_, Value) ->
case lists:nth(1, Value) rem 2 of
0 -> true;
1 -> false
@plvhx
plvhx / convert_date_like_hell.erl
Created July 27, 2021 06:07
converting rfc3339 to timestamp and back, like a boss.
-module(main).
-export([start/0]).
to_rfc3339(DateTime) ->
{{Y, M, D}, {H, I, S}} = DateTime,
io_lib:format(
"~4.10.0B-~2.10.0B-~2.10.0BT~2.10.0B:~2.10.0B:~2.10.0BZ",
[Y, M, D, H, I, S]
).
@plvhx
plvhx / foobar.erl
Created July 24, 2021 13:18
erlang is shit
-module(main).
-author('u know who i am better than me ~').
-export([start/0]).
%% internal callback when calling
%% array:foldl
adder(_, V, A) -> V + A.
log(Arr) ->
log_impl(Arr, array:size(Arr), 0).
@plvhx
plvhx / day4_part2.js
Created January 23, 2021 13:41
advent of code day 4 part 2
const fs = require('fs')
const splitted = fs.readFileSync('./input.txt', 'utf-8').split(String.fromCharCode(0x0a).repeat(2))
function normalize(splt) {
let tmp = Object.create({})
for (let i = 0; i < splt.length; i++) {
splt[i].split(/\s+/).forEach((el) => {
let _splt = el.split(':');
tmp[_splt[0]] = _splt[1]