Skip to content

Instantly share code, notes, and snippets.

@aeldar
aeldar / any-other-file.ts
Created March 3, 2023 15:50
Declare global `window` interface
// Usage example
import './global.types.ts';
// Enough to be imported in a single file, closer to the app's initialisation.
@aeldar
aeldar / version.sh
Created January 19, 2023 21:55
Gegenerate unique and sequential version of the app
#!/bin/sh
COMMIT_COUNT=$(git rev-list --count HEAD)
COMMIT_HASH=$(git rev-parse --short HEAD)
echo ${COMMIT_COUNT}-${COMMIT_HASH}
@aeldar
aeldar / nginx.conf
Last active March 14, 2024 15:46
Nginx configuration for a microfrontend inside SingleSPA
server {
listen 8080;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
location /healthz.html {
add_header Cache-Control "no-store, max-age=0"; # never cache
}
@aeldar
aeldar / app.component.scss
Created August 3, 2021 11:06
Encapsulate all Angular Material styles inside the microfrontend, changing CdkOverlayContainer root DOM node.
@import '~scss/mixins/custom-material-theme';
:host ::ng-deep {
// mixin to generate custom Material theme (see official docs)
@include custom-material-theme();
*,
*:before,
*:after {
box-sizing: border-box;
@aeldar
aeldar / Cargo.toml
Created February 2, 2021 13:58
Build rust app for windows inside docker container
# Reduce the size of the executable file:
[profile.release]
lto = true
codegen-units = 1
opt-level = "z"
panic = 'abort'
@aeldar
aeldar / index.ts
Last active September 6, 2019 16:21
RxJS operator to map emitted value to `true` and to emit `false` after some period of inactivity (On/AutoOff behavior)
import { merge, Observable, Subject } from 'rxjs';
import { debounceTime, map } from 'rxjs/operators';
// Emit `true` on any source emission, then emit `false` after period of inactivity
const turnOffAfter = (timeout: number) => (source: Observable<any>) => merge(
source.pipe(map(_ => true)), // map original value to `true`
source.pipe(debounceTime(timeout), map(_ => false)), // emit `false` after timeout
);
// Example usage
@aeldar
aeldar / env to json, filtered by prefix, with type transformations
Last active September 6, 2019 19:43
Convert ENV to JSON, filtered by prefix "WEB_APP_", with prefix removed, and with Boolean and Number values recognized. `jq` was used.
jq -n \
'env
| to_entries
| map(select(.key | startswith("WEB_APP_")))
| map({
"key": (.key | sub("WEB_APP_"; "")),
"value": (
if (.value | test("^true$"; "i")) then true
elif (.value | test("^false$"; "i")) then false
elif (.value | test("[[:digit:]]+")) then (.value | tonumber)
@aeldar
aeldar / env to json, filtered by prefix
Last active August 15, 2019 21:22
`jq` command with parameters, allowed to convert ENV to json and filter ENV variables by prefix
jq -n 'env | to_entries | map(select(.key | startswith("MY_PREFIX_"))) | from_entries'
@aeldar
aeldar / placeholder.css
Created July 30, 2015 15:38
placeholder control
input:focus::-webkit-input-placeholder { color:transparent; }
input:focus:-moz-placeholder { color:transparent; } /* FF 4-18 */
input:focus::-moz-placeholder { color:transparent; } /* FF 19+ */
input:focus:-ms-input-placeholder { color:transparent; } /* IE 10+ */
@aeldar
aeldar / gulpfile.js
Last active August 29, 2015 14:25
Gulp, browserify, babelify, source maps, babel, es6
'use strict';
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var source = require('vinyl-source-stream');
var babelify = require('babelify');
var browserify = require('browserify');
var watchify = require('watchify');
var dependencies = [