Skip to content

Instantly share code, notes, and snippets.

@mucaho
mucaho / src.YOUR_CODE.scala
Created February 13, 2014 10:42
Akka Actors to be executed in Swing / JavaFX thread - based on Victor Klang's [Swing Actors](https://gist.github.com/viktorklang/2422443)
// After that we just create the GUI Actors with a Props with the correct dispatcher set:
val javaFxActor = context.actorOf(Props[JavaFxActor].withDispatcher("javafx-dispatcher"), "javaFxActor")
val swingActor = context.actorOf(Props[SwingActor].withDispatcher("swing-dispatcher"), "swingActor")
// Done! Now all messages processed by the new actor will be executed by the Swing/JavaFX Event Dispatch Thread, enjoy!
@mucaho
mucaho / README.md
Created July 14, 2022 10:10
Google Sitemap Test

Minimum working example for issue described in https://support.google.com/webmasters/thread/171071268?hl=en

  • Requires installation of Node.js

  • Put these files into a directory, run npm install to install dependencies

  • Use ssh -R 80:localhost:8080 localhost.run to setup a temporary tunnel to your local machine, leave that shell open

  • Copy & paste the publicly accessible tunnel url that will be established, e.g. https://XXX.lhrtunnel.link

  • Open Google Search Console and create a new URL prefix property with that tunnel link

  • Use the meta tag verification method and paste it into the project's index.html file's header

@mucaho
mucaho / generic-js-benchmark.html
Last active February 8, 2022 00:18
Generic template for benchmarking / performance testing JavaScript code using the [Benchmark node module](https://www.npmjs.com/package/benchmark)
<html>
<head>
<script src="https://wzrd.in/bundle/lodash@4.11"></script>
<script src="https://wzrd.in/bundle/platform@1.3"></script>
<script src="https://wzrd.in/bundle/benchmark@2.1"></script>
</head>
<body>
<script>
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
@mucaho
mucaho / yt_restore_video_time.user.js
Created December 7, 2021 06:35
YouTube restore video time - ViolentMonkey user script
// ==UserScript==
// @name YouTube restore video time
// @namespace Violentmonkey Scripts
// @match https://*.youtube.com/*
// @grant none
// @version 1.0
// @author mucaho
// @description -
// ==/UserScript==
@mucaho
mucaho / async_await_trap.js
Last active February 22, 2021 07:33
Example code demonstrating the not immediately apparent issue of a promise rejecting while another one is being awaited.
async function main() {
const rej = Promise.reject('err')
// the following line is needed,
// otherwise UnhandledPromiseRejectionWarning is thrown
// which can't be caught anywhere else (not even by async caller)!
// can be NOOP though, if error handling may be delayed to below catch block
rej.catch(e => console.log(e)) // logs 'err'
const del = new Promise((resolve) => {
setTimeout(() => resolve('del'), 100)
@mucaho
mucaho / Dockerfile
Last active April 13, 2020 12:20
Example Dockerfile and docker-compose.yml for a node js application with mongo db
FROM node:12-alpine
RUN apk add --no-cache tini
RUN apk add --no-cache curl
ADD https://raw.githubusercontent.com/eficode/wait-for/master/wait-for /bin/wait-for.sh
RUN chmod +rx /bin/wait-for.sh
USER node
RUN mkdir -p /home/node/app
WORKDIR /home/node/app
@mucaho
mucaho / SortedMultiMap.scala
Created April 15, 2014 17:28
Immutable, sorted multi map in Scala
import scala.collection._
import scala.collection.generic.CanBuildFrom
import scala.Iterator
/**
* Factory singleton for creating a [[ .SortedMultiMap SortedMultiMap]].
*/
object SortedMultiMap {
/**
* Construct an empty [[ .SortedMultiMap SortedMultiMap]].
@mucaho
mucaho / sc2-fast_max_supply_replays.ipynb
Last active October 10, 2017 21:49
Extract fastest Starcraft II replays that reach max supply, according to [MSC](https://github.com/wuhuikai/MSC)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mucaho
mucaho / scopelist.txt
Created April 7, 2016 22:05 — forked from jasonm23/scopelist.txt
A list of Sublime Scopes scraped from all themes listed by Aziz' tmTheme Editor
active_guide
argument-name
block_cursor
brackethighlighter.curly
brackethighlighter.tag
class
class-inheritance
class-name
comment
comment.block
@mucaho
mucaho / distance_both_axes.js
Created March 13, 2016 00:48
approximate distance ray <-> aabb
// See [this tutorial](http://www.flipcode.com/archives/Raytracing_Topics_Techniques-Part_4_Spatial_Subdivisions.shtml) and linked materials
//
// return distance to nearest corner of rectangle,
// or return Infinity if no intersection with ray
//
// origin = {_x, _y}
// direction = {x, y}
function approximateDistanceFromRay(origin, direction) {
var epsilon = 0.00000001; //maximum error allowed