Skip to content

Instantly share code, notes, and snippets.

View awwsmm's full-sized avatar

Andrew awwsmm

View GitHub Profile
@awwsmm
awwsmm / build-and-bind.sh
Created April 4, 2024 11:56
Bash script to compile Rust code to WASM and generate JavaScript bindings
#!/usr/bin/env bash
# $1: package name from Cargo.toml
# run with e.g.: bash build-and-bind.sh flappy-bevy
# build
rustup target add wasm32-unknown-unknown
cargo build --release --target wasm32-unknown-unknown
@awwsmm
awwsmm / clearContents.gs
Last active September 11, 2022 18:22
Google Apps Script macro to clear contents in a Google Sheet, skipping protected columns and rows
/** @OnlyCurrentDoc */
clearTransactions(3, 1, 6, 6, true);
function clearTransactions(nHeaderRows, nHeaderColumns, nAccountsPerSection, nRowsPerDay, DEBUG = false) {
// BEGIN https://stackoverflow.com/a/21231012/2925434
function columnToLetter(column) {
var temp, letter = '';
while (column > 0) {
@awwsmm
awwsmm / webpack.config.js
Last active March 13, 2022 21:02 — forked from thatisuday/webpack.config.js
A simple Webpack configuration to compile TypeScript projects with fork-ts-checker-webpack-plugin.
const path = require( 'path' );
const ForkTsCheckerWebpackPlugin = require( 'fork-ts-checker-webpack-plugin' );
module.exports = {
// generate source maps
devtool: 'source-map',
// bundling mode
mode: 'production',
@awwsmm
awwsmm / tryWIthResources.scala
Created November 8, 2021 12:04
Java's try-with-resources pattern, but in Scala.
trait SourceUtils {
/**
* Opens a `resource`, passes it to the given function `f`, then
* closes the resource, returning the value returned from `f`.
*
* Example usage:
* {{{
* val myString: String =
* using(scala.io.Source.fromFile("file.name")) { source =>
@awwsmm
awwsmm / music.scala
Last active November 6, 2021 12:23
Create audio from raw bits in Scala
package com.awwsmm
import javax.sound.sampled.{AudioFormat, AudioSystem, SourceDataLine}
// Inspired by https://community.oracle.com/tech/developers/discussion/1273219/example-code-to-generate-audio-tone
// and https://stackoverflow.com/questions/1932490/java-generating-sound/47916383
// still some "crackling" / "popping" at the end of the tune, but most of the way there
object Main extends App {
@awwsmm
awwsmm / another-example.scala
Last active July 23, 2021 20:25
Finite State Machine with state-specific commands in Scala using Akka
import akka.actor.typed.Behavior
import akka.actor.typed.scaladsl.Behaviors
object Test extends App {
sealed trait AnimalCommand
sealed trait DogCommand extends AnimalCommand
object Bark extends DogCommand
@awwsmm
awwsmm / gotta_click.R
Created October 30, 2020 18:42
Minimal Idle / Incremental Clicking "Game" in R Shiny
library(shiny)
ui <- basicPage(
actionButton("theButton", "gotta click"),
verbatimTextOutput("theNumber")
)
server <- function(input, output, session) {
vals <- reactiveValues(counter = 0)
@awwsmm
awwsmm / 🤯.scala
Created June 25, 2020 15:10
Type classes and implicit conversions in Scala
// this is a type class
trait Eq [A] {
def === (x: A)(y: A): Boolean
def =/= (x: A)(y: A): Boolean
}
// it is a reasonable translation of this Haskell code (Wiki)
// class Eq a where
// (==) :: a -> a -> Bool
// (/=) :: a -> a -> Bool
@awwsmm
awwsmm / clickableValueBoxModule.R
Created July 12, 2019 15:48
Clickable valueBox in R Shiny which opens a modal with reactive inputs, in a module
# define the UI of the module
clickableValueBoxUI <- function(id) {
# create the namespace
ns <- NS(id)
# define the UI components
fluidRow(
valueBoxOutput(ns("my_valueBox"))
)
@awwsmm
awwsmm / modalModule.R
Created July 12, 2019 13:19
An R Shiny Modal in a Module
# define the module UI
moduleUI <- function(id) {
# create the namespace from the id
ns <- NS(id)
# As this is a function, the last statement will be the return value.
# Make sure it contains all of the UI elements you want to display
fluidPage(