Skip to content

Instantly share code, notes, and snippets.

@faveoled
faveoled / salarytimer.js
Last active July 27, 2023 12:52
Salary Timer. Calculates how much you earned at current point in time during the day
// Set the constants for schedule and pay rate
const schedule = {
start: "09:00", // Start of schedule in HH:mm format
end: "17:00", // End of schedule in HH:mm format
breakStart: "12:00", // Start of break time in HH:mm format
breakEnd: "13:00" // End of break time in HH:mm format
};
const payRate = 100; // Pay rate in dollars per day
@faveoled
faveoled / tauri-scalajs-command.scala
Last active July 21, 2023 15:45
Run command in Tauri Scala.js
import tauri.ShellMod
import typings.std.stdStrings.close
import typings.tauriAppsApi.tauriAppsApiStrings
import scala.util.Failure
import scala.util.Success
import scala.concurrent.Future
import scala.collection.mutable.ArrayBuffer
import scala.concurrent.Promise
import scalajs.js.JSConverters.iterableOnceConvertible2JSRichIterableOnce
@faveoled
faveoled / pmos-issue.log
Last active July 19, 2023 10:55
PostmarketOS rndis0 problem
mkdir: can't create directory '/config/usb_gadget/g1/functions/rndis.usb0': Function not implemented
Couldn't create /config/usb_gadget/g1/functions/rndis.usb0
ln: /config/usb_gadget/g1/configs/c.1/rndis.usb0: No such file or directory
Couldn't symlink rndis.usb0
~ # ls /config/usb_gadget/g1/functions/
~ #
@faveoled
faveoled / laminarbutton.scala
Created June 23, 2023 16:56
Laminar.js button + event handler
val targetWebsiteObserver = Observer[dom.MouseEvent](onNext = ev => {
val newTarget = prompt("Please provide target website link", "https://google.com")
Storage.setTargetWebsite(newTarget)
})
button(
s"Set target links website. Current: ${Storage.getTargetWebsite()}",
onClick --> targetWebsiteObserver
),
@faveoled
faveoled / download_file.scala
Created June 12, 2023 13:28
Scala.js - download browser-generated file
import org.scalajs.dom.document
import org.scalajs.dom.window
import org.scalajs.dom.URL
import org.scalajs.dom.Blob
def download(filename: String, contents: Blob): Unit = {
val elem = window.document.createElement("a").asInstanceOf[HTMLAnchorElement];
elem.href = URL.createObjectURL(contents);
elem.download = filename;
document.body.appendChild(elem);
@faveoled
faveoled / Dgram.scala
Created March 8, 2023 13:10
Scala.js Node.js UDP client
import scala.scalajs.js
import typings.node.dgramMod as dgram
import typings.node.dgramMod.SocketType
import typings.node.nodeStrings.message
import typings.node.global.console
import typings.std.stdStrings.add
object Dgram {
def send(msg: String, host: String, port: Int): Unit = {
@faveoled
faveoled / SelfTest.scala
Created February 17, 2023 17:26
Scala single-file drop-in testing framework
import scala.concurrent.Future
import scala.scalajs.js
import scala.util.Success
import scala.util.Failure
object SelfTest {
def GREEN_CIRCLE: String = "\uD83D\uDFE2"
def RED_CIRCLE: String = "\uD83D\uDD34"
@faveoled
faveoled / scalajs_fetch.scala
Last active July 23, 2023 08:22
Scala.js Fetch API dom sample
import scala.concurrent.Future
import org.scalajs.dom
import org.scalajs.dom.Request
import org.scalajs.dom.Fetch
import org.scalajs.dom.HttpMethod
import org.scalajs.dom.RequestInit
import org.scalajs.dom.Headers
implicit val ec: scala.concurrent.ExecutionContext = scala.concurrent.ExecutionContext.global
object ApiClient {
@faveoled
faveoled / Tests.java
Created February 16, 2023 10:24
J2CL Java single-file unit testing
import elemental2.dom.DomGlobal;
import elemental2.promise.Promise;
import java.util.List;
import java.util.function.Supplier;
public class Tests {
public static final String GREEN_CIRCLE = "\uD83D\uDFE2";
public static final String RED_CIRCLE = "\uD83D\uDD34";
@faveoled
faveoled / J2CLHttp.java
Last active February 8, 2023 16:11
J2CL http request
import elemental2.dom.XMLHttpRequest;
import elemental2.promise.Promise;
public class Http {
enum HttpMethod {
GET, POST
}
public static Promise<String> request(HttpMethod method, String url) {