Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew awwsmm

View GitHub Profile
@awwsmm
awwsmm / webpack.config.js
Last active Mar 13, 2022 — forked from thatisuday/webpack.config.js
A simple Webpack configuration to compile TypeScript projects with fork-ts-checker-webpack-plugin.
View webpack.config.js
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 Nov 8, 2021
Java's try-with-resources pattern, but in Scala.
View tryWIthResources.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 Nov 6, 2021
Create audio from raw bits in Scala
View music.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 Jul 23, 2021
Finite State Machine with state-specific commands in Scala using Akka
View another-example.scala
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 Oct 30, 2020
Minimal Idle / Incremental Clicking "Game" in R Shiny
View gotta_click.R
library(shiny)
ui <- basicPage(
actionButton("theButton", "gotta click"),
verbatimTextOutput("theNumber")
)
server <- function(input, output, session) {
vals <- reactiveValues(counter = 0)
@awwsmm
awwsmm / 🤯.scala
Created Jun 25, 2020
Type classes and implicit conversions in Scala
View 🤯.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 Jul 12, 2019
Clickable valueBox in R Shiny which opens a modal with reactive inputs, in a module
View clickableValueBoxModule.R
# 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 Jul 12, 2019
An R Shiny Modal in a Module
View modalModule.R
# 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(
@awwsmm
awwsmm / array_contains.sh
Last active Jun 22, 2019
Merge all Java-like "classpath"s in arguments into a single valid classpath, keep other arguments intact
View array_contains.sh
#!/usr/bin/env bash
#-------------------------------------------------------------------------------
#
# array_contains - returns 0 if array contains the specified value, else 1
#
# $1 : term to search for
# $2+ : array to inspect
#
# sources:
@awwsmm
awwsmm / printargs.sh
Last active Jun 23, 2019
Easily print arguments passed to a `bash` script
View printargs.sh
#!/usr/bin/env bash
#-------------------------------------------------------------------------------
#
# print_args - easily inspect arguments passed to a bash script
#
# sources:
# https://unix.stackexchange.com/a/332126/183920
#
#-------------------------------------------------------------------------------