Skip to content

Instantly share code, notes, and snippets.

@frencojobs
frencojobs / observable.dart
Created December 13, 2019 06:31
Me explaining observables to my friends
import 'dart:async';
class Observable {
Function subscriberFunction;
Observable(this.subscriberFunction);
subscribe(observer) {
this.subscriberFunction(observer);
}
@frencojobs
frencojobs / reactivity.dart
Created April 24, 2020 14:24
Reactivity explained in dart
import 'dart:html';
class Storage {
Map db = {'count': 0};
Map deps = {'count': []};
void add(String key, dynamic value) {
db[key] = value;
}
@frencojobs
frencojobs / generate.py
Last active June 1, 2020 03:26
SourceCode generation helper for Flutter.
# pip install click
import click
import os
@click.command()
@click.option('--watch', is_flag=True, help='Watch file changes during build.')
@click.option('--restart', is_flag=True, help='Delete conflicting outputs.')
def generate(**kwargs):
'''Run build_runner source code generation'''
@frencojobs
frencojobs / action_button.dart
Created June 18, 2020 01:18
How I make better-looking IconButton replacement.
import 'package:flutter/material.dart';
class ActionButton extends StatelessWidget {
final Function onPressed;
final Icon icon;
ActionButton({
@required this.onPressed,
@required this.icon,
});
@frencojobs
frencojobs / yield.dart
Created September 4, 2020 09:56
Me trying my best to explain yield* syntax of dart.
Iterable<int> inner() sync* {
for (final i in [4, 5, 6]) {
yield i;
}
}
Iterable<int> outer() sync* {
for (final i in [1, 2, 3]) {
yield i;
}
@frencojobs
frencojobs / typescriptreact.json
Last active November 10, 2020 05:14
My vscode snippets.
{
"react functional component": {
"prefix": "rfc",
"body": [
"export const ${TM_FILENAME_BASE/(\\w)/${1:/upcase}/}: React.FC = () => {",
" return <>$0</>",
"}"
],
"description": "react functional component"
},
@frencojobs
frencojobs / and_then_vs_map.rs
Last active December 11, 2020 06:44
I made Intuitive Rust Examples that made me understand the concepts of Option
// difference between and_then vs map for `Option`
fn increment(n: i32) -> Option<i32> {
Some(n).map(|x| x + 1)
}
fn main() {
let one = Some(1);
let four = one
.map(|one| one + 1)
@frencojobs
frencojobs / readline.dart
Created March 9, 2021 12:24
Dart read from console line by line asynchronously.
import 'dart:async';
import 'dart:convert';
import 'dart:io' as io;
/// Reads a single line from [stdin] asynchronously.
Future<String> readLine() async {
final c = Completer<String>(); // completer
final l = io.stdin // stdin
.transform(utf8.decoder) // decode
.transform(const LineSplitter()) // split line
@frencojobs
frencojobs / fallbacks.css
Last active January 22, 2023 06:20
Fallbacks for my favourite fonts
@font-face {
font-family: 'Inter Fallback';
src: local('Arial');
ascent-override: 90%;
descent-override: 22.43%;
line-gap-override: 0%;
size-adjust: 107.64%;
}
@font-face {
@frencojobs
frencojobs / dropper.ts
Created March 13, 2023 05:07
Dropper Pattern in NestJS
import {Module, Inject, Injectable, ConfigurableModuleBuilder} from '@nestjs/common'
const {ConfigurableModuleClass, MODULE_OPTIONS_TOKEN} = new ConfigurableModuleBuilder<unknown>().build()
@Injectable()
class DropperService<T> {
constructor(@Inject(MODULE_OPTIONS_TOKEN) private readonly value: T) {}
drop(): T {
return this.value