Skip to content

Instantly share code, notes, and snippets.

@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) {
@faveoled
faveoled / j2clreadfile.java
Last active February 8, 2023 12:31
J2CL Read File contents
// add to html:
// <input type="file" id="file-selector" multiple>
HTMLInputElement fileSelector = (HTMLInputElement) DomGlobal.document.getElementById("file-selector");
fileSelector.addEventListener("change", event -> {
FileList files = ((HTMLInputElement) (event.target)).files;
for (int i = 0; i < files.length; i++) {
File file = files.item(i);
file.arrayBuffer()
.then(
success -> {
@faveoled
faveoled / Main.scala
Created January 25, 2023 14:20
Scala Native PulseAudio example
import libpulse.functions.pa_simple_new
import libpulse.functions.pa_simple_write
import libpulse.functions.pa_simple_free
import libpulse.types.pa_sample_spec
import libpulse.types.pa_sample_format
import libpulse.types.pa_stream_direction
import libpulse.extern_functions
import scala.scalanative.unsafe
import scala.scalanative.unsafe._
import scalanative.unsigned.UnsignedRichInt
@faveoled
faveoled / unpack-appimage.sh
Last active January 11, 2023 11:17
Unpack AppImage without root rights and AppImage execution
#!/bin/bash
# usage: ./unpack-appimage.sh <appimage_file.AppImage>
APP_IMAGE=$(readlink -f $1)
APP_IMAGE_FILE=$(basename ${APP_IMAGE})
APP_DIR=$(dirname $APP_IMAGE)
APP_IMAGE=$(readlink -f $1)
ELFSIZE=$(readelf -h $APP_IMAGE)
@faveoled
faveoled / gist:954d362347a263e78cdf329846425fc5
Last active November 13, 2021 18:38
Create DEB package from CMake project
# from within project root
# *.tar.gz should be present on upper level
# root directory name : {projectname}-{version}
# bin for runnable binary
debmake --binaryspec <project_name>:bin
# ESSENTIAL: remove debian/changelog nnnn references
# ESSENTIAL: update debian/control section field
debuild -us -uc