Skip to content

Instantly share code, notes, and snippets.

View ChristianOellers's full-sized avatar
🇻🇳
Remote work

Chris ChristianOellers

🇻🇳
Remote work
View GitHub Profile
@ChristianOellers
ChristianOellers / ILogger.ts
Created July 26, 2023 10:38
Minimal console logger wrapper. TypeScript, Node, Jest, Angular. Architectural demo with interface, config, TDD. IoC optional.
export interface ILogger {
log(...args: any[]): void;
info(): void;
error(): void;
enable(): void;
disable(): void;
}
@ChristianOellers
ChristianOellers / RegEx-Snippets - Log analysis + Filtering.sh
Last active July 26, 2023 10:04
RegEx snippets for various tasks - Data analysis, filtering, validation, ... (PCRE, Bash).
# Exemplary snippets I've been using in my own projects. Use for inspiration and take what you need.
# 'sh' file format is for syntax highlighting only: The RegEx parts should work in many scenarios.
#
# Run all snippets to normalize varying strings by replacing or removing characters (as you need).
# Once all strings are aligned, duplicates can be filtered and lines sorted.
# This leaves the log with a few distinct, unique errors that are to be considered for development.
# RegEx design aims to leave the log syntax intact, e.g., delimiters (,"').
# This might be relevant for proper syntax highlighting or use with advanced analyzers.
# ---
@ChristianOellers
ChristianOellers / 1_Request-JSON-Data.php
Created July 3, 2023 12:37
Request + Routing - Minimalist zero-dependency PHP solution for JSON handling. Useful for development, not suited for production.
<?php
declare(strict_types=1);
namespace App;
use Exception;
use function addslashes;
use function file_get_contents;
@ChristianOellers
ChristianOellers / 0_Search-Queries.sql
Last active July 3, 2023 12:32
MySQL snippets - Specific search queries and example code.
-- Find in date range
SELECT *
FROM example
WHERE (updated >= '1970-01-01' AND updated <= DATE_ADD('1970-01-01', INTERVAL 1 DAY))
-- AND ...
-- Find by date format
SELECT * FROM example
-- WHERE ...
AND YEAR(updated_at) >= '1970'
@ChristianOellers
ChristianOellers / font-scaling.scss
Last active July 3, 2023 12:23
SCSS + Bootstrap snippets. Utilities and custom font scaling mechanism. Variables in separate file.
// Custom font scaling mechanism.
//
// This allows keeping a standardized base font size (e.g. 16px ~ 1rem),
// but applying custom scales for anything that is not regular text flow.
// Font scale factors (here large Desktop set as base scale).
$font-breakpoints: (
xs: 0.65,
sm: 0.7,
md: 0.75,
@ChristianOellers
ChristianOellers / .bash_aliases
Last active July 3, 2023 12:01
Symfony + Vagrant settings - VM configuration, aliases and snippets for speedy workflows.
#!/bin/bash
# Utility aliases to call from within running Vagrant box. Speed up fixing common, recurring issues during development.
# @todo - Adjust paths and commands as needed.
# TOC
# - Symfony
# - Logs
# - SYSTEM
@ChristianOellers
ChristianOellers / phpcs.xml
Created June 11, 2023 16:36
Symfony - PHPCS config (via Squizlabs), PSR-12 standard.
<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
<arg name="basepath" value="." />
<arg name="cache" value=".phpcs-cache" />
<arg name="extensions" value="php" />
<arg name="colors" />
<arg name="report" value="summary" />
@ChristianOellers
ChristianOellers / Log4j.java
Last active June 11, 2023 14:49
Log4j - Example implementation (Java).
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class Example {
private static final Logger logger = LoggerFactory.getLogger(Example.class);
public void doSomething() {
// Levels: info, warn, ...
logger.warn("Text", 1);
}
@ChristianOellers
ChristianOellers / Format-Number-Locale.ts
Created June 11, 2023 14:36
TypeScript snippets - Locale + Languages. General purpose use cases.
export const formatNumber = (language: string, value: number | bigint): string
=> new Intl.NumberFormat(language).format(value)
@ChristianOellers
ChristianOellers / Currency-Locale.js
Last active June 11, 2023 14:49
Currency for Locale - Render-Optimized (avoid NaN). Example use: React.
/**
* Format currency for locale (which can come from anywhere).
*
* Ignore nullish values (like undefined) to avoid showing 'NaN €' as text, to keep templating simple.
* Example use case: First render occurs prior to data being available (e.g. in React).
*/
const locale = 'de-DE'
export default (val) => {