Skip to content

Instantly share code, notes, and snippets.

View jagomf's full-sized avatar

Jago jagomf

View GitHub Profile
@jagomf
jagomf / search.component.ts
Created December 20, 2023 08:03
Combine values collected from URL bound to inputs
@Component({
template: `
<div *ngIf="data$ | async as data">
{{ data }}
</div>
`
})
export class SearchComponent implements OnInit {
private dataService = inject(DataService);
@jagomf
jagomf / whenAsyncStates.dart
Last active August 14, 2023 14:34
Handling output with stream states
/// Originally by Simon Lightfoot
extension WhenAsyncSnapshot<T> on AsyncSnapshot<T> {
R when<R>({
R Function()? empty,
R Function(dynamic error, StackTrace? stackTrace)? error,
R Function()? loading,
R Function(T value)? data,
}) {
if (hasData && data != null) // If we have data then lets display it no-matter what!
@jagomf
jagomf / .htaccess
Created April 17, 2022 19:11
Set up apple-app-site-association file
# Located in /.well-known directory, next to a apple-app-site-association.json file
RewriteEngine On
RewriteBase /.well-known/
RewriteRule ^apple-app-site-association$ apple-app-site-association.json [NC,L]
@jagomf
jagomf / debloat.ps1
Created March 31, 2022 11:16
Windows debloater
# Windows debloater by https://github.com/Sycnex/Windows10Debloater
iwr -useb https://git.io/debloat|iex
@jagomf
jagomf / lerp_colors.dart
Last active December 16, 2021 11:03
Getting a color in between a scale in Dart/Flutter
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
const totalColorsToShow = 50;
const startColor = Colors.red;
const finalColor = Colors.green;
class MyApp extends StatelessWidget {
@override
import 'package:flutter/material.dart';
class InteractiveViewerOverlay extends StatefulWidget {
final Widget child;
final double maxScale;
const InteractiveViewerOverlay({
Key key,
@required this.child,
this.maxScale,
@jagomf
jagomf / mysql-to.json.sql
Created June 7, 2020 20:30
MySQL table to JSON
SELECT JSON_PRETTY(JSON_ARRAYAGG(
JSON_OBJECT('code', code, 'name', name, 'iso3', iso3, 'numcode', numcode, 'city', city)
)) FROM country;
@jagomf
jagomf / run-build.sh
Created June 3, 2020 12:19
Run Angular build with extra memory
node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build --aot
@jagomf
jagomf / clicked-out.ts
Created April 30, 2020 19:44
Detect click outside an Angular component
@Component({ ... })
export class Mva10SelectFieldComponent {
constructor( private elementRef: ElementRef ) { }
onClickOut(targetElement?: HTMLElement): void {
if (!targetElement) { return; }
const clickedInside = this.elementRef.nativeElement.contains(targetElement);
if (!clickedInside) {
// Clicked outside component!
@jagomf
jagomf / simple-calendar.ts
Last active February 6, 2020 10:42
Generate a simple calendar which is an array of arrays
/**
* Generates a simple Calendar formatted as an array of arrays
* @param year Year for which calendar month is generated
* @param month Calendar month to be generated
* @param startWeekMonday Optional offset -- defaults to false (week starts on Sunday)
* @returns Main array (month) of arrays (weeks) of days
* @see Based on algorithm by github:lukeed/calendarize
*/
private generateMonthCalendar(year: number, month: number, startWeekMonday = false) {
const res: number[][] = [];