Skip to content

Instantly share code, notes, and snippets.

Avatar

Prana Adiwira intrnl

View GitHub Profile
@intrnl
intrnl / google-forms-get-url-with-filled-answer.js
Last active Nov 18, 2020
Creates Google Forms URL containing answers that have been filled
View google-forms-get-url-with-filled-answer.js
// A teacher told us to submit the same form multiple times as sort of memory strengthening.
// I don't like that though, so here's a script that creates a Forms URL that contains the answers I've already filled.
location.origin + location.pathname + '?' +
Array.from(document.querySelectorAll('input[name^="entry."]'))
.filter((el) => el.value)
.map((el) => `${el.name}=${encodeURIComponent(el.value)}`)
.join('&');
View use-reactive.jsx
import { render } from 'preact';
import { useRef, useState } from 'preact/hooks';
function useReactive (initialState) {
let [, forceUpdate] = useState({});
let reactive = useRef(null);
if (!reactive.current) {
reactive.current = new Proxy(initialState, {
@intrnl
intrnl / 0001-fix-indent.patch
Created Oct 21, 2020
microsoft-edge-dev-bin patch
View 0001-fix-indent.patch
From 13c2054ae99cf4c1587d9c6f2058d0ae18db3cc3 Mon Sep 17 00:00:00 2001
From: intrnl <intrnl28+git@gmail.com>
Date: Wed, 21 Oct 2020 17:08:08 +0700
Subject: [PATCH 1/2] fix indent
---
PKGBUILD | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/PKGBUILD b/PKGBUILD
View jsx-static.js
function __append (el, children) {
for (let child of children) {
if (!child) continue;
if (Array.isArray(child)) __append(el, child);
else if (child instanceof HTMLElement || child instanceof DocumentFragment) el.append(child);
else el.append(document.createTextNode(child));
}
}
View async-to-generator.js
function __async (generator) {
return function (...args) {
let it = generator.apply(this, args);
return new Promise((resolve, reject) => {
step(it.next());
function step (result) {
if (result.done) resolve(result.value);
else Promise.resolve(result.value).then(fulfilled, rejected);
@intrnl
intrnl / minified-default.js
Created Aug 26, 2020
CSS modules namespace import
View minified-default.js
// 249 bytes
var o={helloWorld:"hello-world-123",fooBar:"foo-bar-245",barBaz:"bar-baz-934"};let l=Object.assign(document.createElement("div"),{textContent:"Hello world!",className:[o.helloWorld,o.helloWorld,o.fooBar,o.barBaz].join(" ")});document.body.append(l);
View timestamp_to_snowflake.js
let epoch = 1420070400000;
let increment = 0;
function timestamp_to_snowflake (timestamp = Date.now()) {
let snowflake = '';
// timestamp
snowflake += (timestamp - epoch).toString(2).padStart(42, '0');
// worker id
snowflake += '00001';
View count_occurences.js
function count (str: string, search: string) {
let n = -1;
let i = 0;
while (i !== -1) {
i = str.indexOf(search, i + 1);
n++;
}
return n;
@intrnl
intrnl / svelte-store.js
Last active Jul 22, 2020
Svelte's Store implementation
View svelte-store.js
function noop () {}
export function writable (init, start) {
let subscribers = [];
let prev = init;
let running = false;
let stop;
function notify () {
let subs = subscribers.concat();
@intrnl
intrnl / store.js
Created Jul 22, 2020
Basic readable and derived stores
View store.js
export function readable (init, start) {
function subscribe (listener) {
let running = true;
let prev = init;
let stop;
function set (curr) {
if (running && curr !== prev) {
prev = curr;
if (stop) listener(curr);
You can’t perform that action at this time.