Skip to content

Instantly share code, notes, and snippets.

View 50kudos's full-sized avatar
🏡
Remote async work

Waranyoo Butsingkorn 50kudos

🏡
Remote async work
  • Thailand
  • 15:40 (UTC +07:00)
  • X @_fifwb
View GitHub Profile
@50kudos
50kudos / ce.css
Last active October 9, 2022 14:09
Custom elements compose nested props (https://jsfiddle.net/2L5ypn9a/2/)
button { margin: .5rem; }
input { display: inline-block; margin: 0 .5rem; }
stack-btns+span {display: block}
@50kudos
50kudos / unlike.js
Created September 7, 2022 00:05
Unlike tweets
// Adjust as your computer see fit. Too fast, resource releasing will lag.
var doit = () => {
let btns = document.querySelectorAll("[data-testid='unlike']")
if (btns.length == 0) document.querySelector("html").scrollTop += 400
else for (let btn of btns) setTimeout(() => btn.click(), 100)
setTimeout(() => doit(), 300)
}
@50kudos
50kudos / json-thick.md
Last active March 13, 2022 06:02
Json with metadata

json-thick is json whose node has metadata attached along with its value.

Purpose

Work with human interaction either directly with json file or as input/output format used by other user interfaces (e.g. GUI), with extra information on each value, suitable for guided processing or data persistence.

Example

Thick

{
  "c": "root comment",
[
"4",
"46",
"lv:phx-FjMP_AdCLJo1JfDi",
"phx_reply",
{
"response": {
"diff": {
"0": {
"6": {
defmodule FoldlaWeb.DataLive do
use Phoenix.LiveView
def render(assigns) do
FoldlaWeb.DataView.render("edit.html", assigns)
end
def mount(_params, socket) do
{:ok, assign(socket, :thing, 0)}
end
-module(w22list).
-export([take/2, nub/1]).
-spec take(integer(), [T]) -> T.
take(0, _L) -> [];
take(I, L) when I < 0 orelse I > length(L) -> L;
take(I, [H|T]) ->
[H | take(I-1, T)].
nub(L) -> nub(lists:sort(L), []).
-module(w21list).
-export([double/1, evens/1, median/1, mode/1]).
double([]) -> [];
double([H|T]) ->
[H * 2 | double(T)].
evens([]) -> [];
evens([H|T]) ->
case H rem 2 of
-module(w2list).
-export([t_product/1, product/1, t_maximum/1, maximum/1]).
% t_ prefix means tail recursion implementation.
t_product(L) ->
t_product(L, 1).
t_product([], P) ->
P;
t_product([H|T], A) when is_number(H) ->
-module(asm).
-export([perimeter/1, area/1, areaEnclose/1, perimeterEnclose/1, bits/1]).
%% Shapes
% I am so sure about the requirements, and assume:
% 1. By "smallest enclosing rectangle", means both[0]:
% - Minimum-area enclosing rectangle
% - Minimum-perimeter enclosing rectangle
% 2. It does not base on coordinate system.
%
-module(four).
-export([fact/1,fib/1,pieces/1,tFib/1,perfect/1]).
fact(0) -> 1;
fact(N) when N>0 ->
fact(N-1)*N.
fib(0) -> 0;
fib(1) -> 1;
fib(N) when N>1 ->