Skip to content

Instantly share code, notes, and snippets.

@baflo
baflo / window-toggle.ahk
Last active December 17, 2020 08:16
AutoHotKey script: Toggles (minimizes or restores) windows an keyboard shortcut
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
ShowHideWindow(winTitle, winExe := "")
{
WinGet, targetWindowID, IDLast, %winTitle%
if ("%winExe%" != "") and (not WinExist(winTitle)) {
@baflo
baflo / buffered-requester.ts
Created July 3, 2020 07:18
Buffering requests to the same resource
class Requester {
/** Intermediate observable used to prepare fetching connector identifiers and updating `connectorIdentifiers$`. */
protected readonly fetchConnectorIdentifiers$ = new Subject<number>();
constructor() {
/**
* When idle and an identifiers fetch request comes in, this waits 100ms before triggering.
* When just received a value (within the 100ms window), these do not increase the window timeout.
*/
const fetchConnectorIdentifiersTimer$ = this.fetchConnectorIdentifiers$.pipe(mapTo(undefined), auditTime(100));
@baflo
baflo / some-angular.component.html
Last active July 1, 2020 08:24
Handling placeholders after delay with RxJS
<ng-container *ngIf="listEntities$ | async as listEntities">
<div class="label-context-panel" *ngIf="listEntities.length > 0">
<ul>
<ng-container *ngFor="let entity of listEntities">
<ng-container [ngSwitch]="entity.type">
<li *ngSwitchCase="'content'" [ngClass]="{ property: true, enabled: !entity.disabled }" (click)="selectReturnValue(entity)">{{ entity.propertyType }} <span class="name">{{ entity.propertyName }}</span>
<div [ngClass]="'tooltip'">
<div class="errorHeading" *ngIf="entity.tooltip.errorHeading">{{ entity.tooltip.errorHeading }}</div>
{{ entity.tooltip.message }}
</div>
@baflo
baflo / _lerna.sh
Last active August 12, 2019 09:27
zsh completions
#compdef _lerna lerna
#http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-System
function _lerna {
local line
_arguments -C \
"--version" \
"--loglevel[Set the log output level]:level:(silent info warn error)" \
"--concurrency[How many processes to use when lerna parallelizes tasks]" \
@baflo
baflo / server.js
Created August 2, 2019 07:32
quick node server
http.createServer(function(r, s) {
var body = [];
r.on("data", function(chunk) {
body.push(chunk)
});
r.on("end", function() {
body = Buffer.concat(body).toString();
body = r.headers["content-type"] === "application/json" ? JSON.parse(body) : body;
console.log(r.method, r.url, r.headers, JSON.stringify(body, null, 2));
s.write("OK");
# Git hook to prevent focused tests/specs (fdescribe, fit)
red='\033[0;31m'
no_color='\033[0m'
focused_spec_findings=$(git grep --cached -nIE "^\s*f(describe|it)\b")
if [ ! -z "$focused_spec_findings" ]
then
# Redirect output to stderr.
exec 1>&2
echo ${red}You still got some focused tests \(fdescribe, fit, etc.\), please clean these before committing:${no_color}
@baflo
baflo / _description.md
Last active April 26, 2019 08:25
Example locales configuration as of Dialogbits Framework 0.5.0

Loads all TypeScript, JavaScript and JSON files from locales directory, if i18next backend is not configured. .ts files shadow .js files, .js files shadow .json files. The folder/file structure is resembled in the final locales object, while the filenames are camelcased, i.e. a folder main-state will be a key mainState, which will contain all content from that folder. If LocalesLoader finds an ES6 default export or an export the same name as the camelcased file name, only this is taken from the file. In any other case, everything is exported. Files and folders of the same name are merged. An example can be found here.

"preinstall": "rm -rf assistantjs && git clone --depth=1 git@github.com:webcomputing/assistantjs --branch feature/autobind-except --single-branch && cd assistantjs && npm i && cd ./node_modules/gulp/bin && node gulp.js build-sources-and-maps build-dts && cd ../../../..",
/**
* THIS IS IMPORTANT!!!
*
* If it's typed like `new (...args: any[]) => any` these examples won't work!
*/
type Ctor = new (...args: any[]) => {};
@baflo
baflo / vboxvm-natpf.bat
Last active December 7, 2018 09:21
Set port forwarding for running vbox
@echo off
setlocal EnableDelayedExpansion
setlocal EnableExtensions
if "%~2"=="add" (
if "%~1"=="" goto :usage
if "%~3"=="" goto :usage
"%programfiles%\Oracle\VirtualBox\VBoxManage.exe" controlvm "%~1" natpf1 "%~3"
goto :EOF
)