Skip to content

Instantly share code, notes, and snippets.

View filiph's full-sized avatar
:shipit:

Filip Hracek filiph

:shipit:
View GitHub Profile
@filiph
filiph / normalized_double.dart
Created May 3, 2024 06:56
An idea for an extension type for normalized floating point values
/// A value that is guaranteed to be normalized (between `0.0` and `1.0`).
///
/// Might be useful to avoid confusion in math-heavy code.
/// For example, a function might expect some of its arguments
/// to be normalized real numbers. Instead of just documenting
/// it in API docs or checking it at runtime, we can express it
/// through the parameter's static type.
///
/// This is an extension type. The nice thing about those is that
/// they have zero runtime overhead.
@filiph
filiph / helloworld.dart
Created June 18, 2016 00:28
The smallest possible hello world program in Dart.
main() => print("Hello World!");
@filiph
filiph / main.dart
Created August 8, 2020 02:31
SnackBar floating regression
import 'package:flutter/material.dart';
void main() => runApp(SnackBarDemo());
class SnackBarDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'SnackBar Demo',
home: Scaffold(
@filiph
filiph / main.dart
Last active October 11, 2022 13:23
Human Life Counter
// This now lives in https://github.com/filiph/human-life/blob/main/lib/main.dart as source
// and at https://filiph.github.io/human-life/ as an app.
import 'dart:math';
import 'package:flutter/material.dart';
void main() {
runApp(HumanLifeApp());
}
@filiph
filiph / main.dart
Last active October 11, 2022 13:21
Fading Scroller (naive implementation in Flutter)
// The accompanying tweet (incl. video) is here:
// https://twitter.com/filiphracek/status/1494213873422974978
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
@filiph
filiph / main.dart
Last active July 11, 2021 10:22
A functional way to capitalize each word in a sentence (a.k.a. Title Case). This is not efficient -- use something like string_scanner if you need to run this in a tight loop.
main() {
var city = "new york";
print(titleCase(city));
}
/// Inefficient way of capitalizing each word in a string.
String titleCase(String text) {
if (text.length <= 1) return text.toUpperCase();
var words = text.split(' ');
var capitalized = words.map((word) {
void main() {
print("Hello DartPad");
}
@filiph
filiph / index.html
Last active April 15, 2021 23:22
Combine lists
<h1 id="header">Combinations</h1>
<p>This tiny tool will combine any number of lists, combining every option with every other option. Separate lists by a blank line.</p>
<textarea id="input" rows=20 cols=40>
In college, I had
good grades,
bad grades,
@filiph
filiph / main.dart
Created March 31, 2021 19:54
Scrollbar widget of the week
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
@filiph
filiph / main.dart
Created February 19, 2021 04:36
Unbounded error app
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(