Skip to content

Instantly share code, notes, and snippets.

@Jonarod
Jonarod / Makefile
Created March 31, 2023 17:41 — forked from francois-rozet/Makefile
Step-by-step Makefile tutorial
# Macros
ALL = program1 program2 program3
SRCDIR = src/
BINDIR = bin/
EXT = cpp
CXX = g++
CXXFLAGS = -std=c++14 -O3 -Wall -Wextra
@Jonarod
Jonarod / readlines.js
Created March 21, 2023 17:59 — forked from bwasti/readlines.js
Fast line reading in bun
async function readlines(stream, callback, buffer_len = 16) {
const reader = stream.getReader()
const td = new TextDecoder('ascii')
let overflow = null
let buffer = []
function flush_buffer() {
for (let b of buffer) {
callback(td.decode(b))
}
@Jonarod
Jonarod / README.md
Created August 21, 2020 13:11
Install Android Apps on Linux
@Jonarod
Jonarod / blob_conversions_util.js
Created December 7, 2019 04:56
Javascript utility to convert Blob to Base64, ImageData or ObjectUrl back and forth. Tree shakeable and promise based.
const BlobToBase64 = function(blob){
let blobUrl = URL.createObjectURL(blob);
return new Promise((resolve, reject) => {
let img = new Image();
img.onload = () => resolve(img);
img.onerror = err => reject(err);
img.src = blobUrl;
}).then(img => {
URL.revokeObjectURL(blobUrl);
@Jonarod
Jonarod / deepCopy.js
Created December 6, 2019 01:09
Fast & concise deep copy / deep clone / shallow copy in Javascript
var deepCopy = function (o) {
var t, x, key
t = Array.isArray(o) ? [] : {}
for (key in o) {
x = o[key]
t[key] = (typeof x === "object" && x !== null && !(x instanceof Date)) ? deepCopy(x) : x
}
return t
}
@Jonarod
Jonarod / ubuntu commands.md
Last active April 1, 2020 17:27
Useful ubuntu commands

Automation

Execute a command at specific time

crontab -e

then, helped by crontab.guru, add a new line like:

@Jonarod
Jonarod / ToggleSwitch.vue
Created November 23, 2019 18:31
Simple custom Toggle Switch button for Vue.js, compatible with v-model.
/**
* @usage:
*
* <ToggleSwitch :trueFalseLabels="['On','Off']" :trueFalseColors="['#1CD4A7','#ccc']" v-model="isOn" />
*
* data() {
* return {
* isOn: false
* }
* }
@Jonarod
Jonarod / RadioBox.vue
Created November 23, 2019 18:23
Simple custom Radio component for Vue.js, compatible with v-model.
/**
* @usage:
*
* <RadioBox label="Foo" value="foo" v-model="MySelectedValue" />
* <RadioBox label="Bar" value="bar" v-model="MySelectedValue" />
* <RadioBox label="Baz" value="baz" v-model="MySelectedValue" />
*
* data(){
* return {
* MySelectedValue: "",
@Jonarod
Jonarod / CheckBox.vue
Created November 23, 2019 18:20
Simple custom CheckBox component for Vue.js, compatible with v-model.
/**
* @usage:
*
* <CheckBox label="Foo" value="foo" v-model="MySelectedValues" />
* <CheckBox label="Bar" value="bar" v-model="MySelectedValues" />
* <CheckBox label="Baz" value="baz" v-model="MySelectedValues" />
*
* data(){
* return {
* MySelectedValues: [],
@Jonarod
Jonarod / Service_Workers_Messaging.md
Last active January 3, 2024 19:16
Describes how to send messages between a page's main thread and a service worker thread

Page to ServiceWorker

// in page.html
navigator.serviceWorker.controller.postMessage({'hello':'world'});
// in sw.js
self.addEventListener('message', event => {