Skip to content

Instantly share code, notes, and snippets.

import { assertDefined } from './utils'
type AsyncFunc<T> = () => Promise<T>
export class MagicQueue<T> {
private isActive = false
private isKilled = false
private queue: AsyncFunc<T>[] = []
@sidola
sidola / custom-error.ts
Last active November 9, 2020 20:31
TS Custom Error
export class UnknownError extends Error {
get name() { return this.constructor.name }
public detail: Readonly<string>
public error: Readonly<Error> | undefined
constructor({ detail, error }: { detail: string, error?: Error }) {
super(
@sidola
sidola / assertIsInEnum.ts
Last active November 8, 2020 12:59
TypeScript runtime assert enum value
/**
* Checks if the given value is a valid constant in the given enum object.
*
* Details: https://github.com/microsoft/TypeScript/issues/30611#issuecomment-676431018
*
* @param enumObj The enum object
* @param enumConstant The constant that must be present in the num
*/
export function assertIsInEnum<T extends string, TEnumValue extends string>(
enumObj: { [key in T]: TEnumValue },
@sidola
sidola / Config.java
Last active April 12, 2024 01:52
SPA / Spring wildcard resource serve - This is how you configure Spring Boot to work with for example react-router. It will serve the `index.html` file on all routes that aren't used by REST controllers.
import java.io.IOException;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.resource.PathResourceResolver;
@Configuration
public class Config implements WebMvcConfigurer {
module.exports = {
'env': {
'browser': true,
'es2021': true,
'node': true
},
'extends': [
'eslint:recommended',
'plugin:react/recommended',
'plugin:@typescript-eslint/recommended'
@sidola
sidola / tasks.json
Last active June 20, 2021 10:26
VSCode re-compile TS files and report errors
{
"version": "2.0.0",
"tasks": [
{
"label": "[C] re-validate typescript",
// Find your TS compiler, it's usually here or globally as "tsc"
"command": "./node_modules/typescript/bin/tsc",
// Pass the arg "-p" and point to our tsconfig file
"type": "shell",
"args": [
package me.sidbot.sandbox.repository;
public class UserRepository extends BaseRepository {
/**
* select all rows in the warehouses table
*/
public void selectAll(){
String sql = "SELECT id, name, capacity FROM warehouses";
@sidola
sidola / TimeDiff.ahk
Last active October 25, 2017 18:04
TimeDiff.ahk
/*
TimeDiff.ahk
Usage:
TimeDiff.ShowTimeDiff()
*/
class TimeDiff {
; Public API
@sidola
sidola / Preferences.sublime-settings
Created September 16, 2017 11:00
Personal ST3 Settings
{
"always_show_minimap_viewport": true,
"bold_folder_labels": true,
"color_scheme": "Packages/Material Theme/schemes/Material-Theme-Darker.tmTheme",
"font_face": "Inconsolata",
"font_size": 11,
"ignored_packages":
[
"Vintage"
],
@sidola
sidola / Material-Theme-Darker.sublime-theme
Last active September 16, 2017 13:02
Fixed Material Theme for ST3 - Changes fontsize and colors - Use this file as the "zzz A File Icon zzz" patch file for the Darker skin
[
// Material-Theme-Darker Patch
// ==========================================================================
// Sidebar Row Padding
// --------------------------------------------------------------------------
{
"class": "sidebar_tree",
},