Skip to content

Instantly share code, notes, and snippets.

@faveoled
faveoled / run.scala
Created February 24, 2024 15:36
Scala.js Node.js run process
def runProcess(command: String, cwd: Option[String], details: String = ""): Future[String] = {
val msg = if (details == "") then s"Running command `${command}`" else s"${details}"
println(s"${msg}...")
val options = encodingBufferEncodingExe(BufferEncoding.utf8)
cwd.foreach(cwdR => options.cwd = cwdR)
val process = node_child_process.exec(command, options)
var strBuilder = mutable.StringBuilder()
process.stdout.asInstanceOf[typings.node.streamMod.Readable].on_data(nodeStrings.data, data => {
strBuilder.append(data)
println(s"cmd stdout: $data")
@faveoled
faveoled / snapcraft.yml
Created January 1, 2024 13:52
Graphviz snap
name: graphviz
base: core22
version: '9.0.0'
summary: S
description: |
A
grade: stable
confinement: strict
@faveoled
faveoled / oktete-msys2.log
Created July 28, 2023 10:47
Okteta build failure
[501/933] Linking CXX executable bin\bytearrayrawfilesynchronizertest.exe
FAILED: bin/bytearrayrawfilesynchronizertest.exe
cmd.exe /C "cd . && C:\msys64\mingw64\bin\c++.exe -fno-operator-names -fno-exceptions -Wall -Wextra -Wcast-align -Wchar-subscripts -Wformat-security -Wno-long-long -Wp
ointer-arith -Wundef -Wnon-virtual-dtor -Woverloaded-virtual -Werror=return-type -Werror=init-self -Wvla -Wdate-time -Wsuggest-override -Wlogical-op -fdiagnostics-colo
r=always kasten/core/io/tests/CMakeFiles/bytearrayrawfilesynchronizertest.dir/bytearrayrawfilesynchronizertest_autogen/mocs_compilation.cpp.obj kasten/core/io/tests/C
MakeFiles/bytearrayrawfilesynchronizertest.dir/bytearrayrawfilesynchronizertest.cpp.obj kasten/core/io/tests/CMakeFiles/bytearrayrawfilesynchronizertest.dir/__/__/docu
ment/bytearraydocument.cpp.obj kasten/core/io/tests/CMakeFiles/bytearrayrawfilesynchronizertest.dir/__/filesystem/bytearrayrawfilesynchronizer.cpp.obj kasten/core/io/t
ests/CMakeFiles/bytearrayrawfilesynchronizertest.dir/__/files
@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"