Skip to content

Instantly share code, notes, and snippets.

View hacker1024's full-sized avatar
🎵
Working on my music app, Epimetheus.

hacker1024

🎵
Working on my music app, Epimetheus.
  • Melbourne, Australia
  • 23:03 (UTC +10:00)
View GitHub Profile
@hacker1024
hacker1024 / redux_state_tree_live_template.dart
Last active March 24, 2021 01:31
A live template for IntelliJ to create a new Redux state object. Objects can be nested.
import 'package:meta/meta.dart';
@immutable
class $NAME$State {
const $NAME$State();
const $NAME$State.initial() : this();
$NAME$State copyWith() => $NAME$State();
@hacker1024
hacker1024 / 10.dart
Created March 22, 2021 02:43
The most efficient way to initialize an integer with a value of 10 in Dart.
import 'dart:math';
/// Thanks to https://www.reddit.com/r/ProgrammerHumor/comments/m9r3vz/efficiency/ for the inspiration
void main() {
final random = Random();
final stopwatch = Stopwatch()..start();
int x;
do {
@hacker1024
hacker1024 / replay_stream_extension.dart
Created January 29, 2021 06:22
A Dart extension function to convert a regular Stream into an RxDart ReplayStream.
import 'package:rxdart/streams.dart';
import 'package:rxdart/subjects.dart';
extension StreamUtils<T> on Stream<T> {
ReplayStream<T> replay() {
final subject = ReplaySubject<T>();
pipe(subject);
return subject;
}
}
@hacker1024
hacker1024 / keywords.dart
Created January 20, 2021 12:46
A Dart list of Dart keywords (as of 2.12.0)
const keywords = [
'abstract',
'else',
'import',
'super',
'as',
'enum',
'in',
'switch',
'assert',
@hacker1024
hacker1024 / pkcs5.dart
Created January 17, 2021 06:32
PKCS #5 padding in Dart
import 'dart:typed_data';
Uint8List padPKCS5(List<int> input) {
final inputLength = input.length;
final paddingValue = 8 - (inputLength % 8);
final outputLength = inputLength + paddingValue;
final output = Uint8List(outputLength);
for (var i = 0; i < inputLength; ++i) {
output[i] = input[i];
@hacker1024
hacker1024 / lovelace-transmission-card.yaml
Created December 19, 2020 13:58
A Transmission control card for Home Assistant's Lovelace interface
type: entities
title: Transmission
show_header_toggle: false
entities:
- entity: switch.transmission_switch
icon: 'hass:power'
name: Enabled
secondary_info: last-changed
- entity: switch.transmission_turtle_mode
icon: 'hass:turtle'
@hacker1024
hacker1024 / scroll_detector_example.dart
Last active February 19, 2021 05:52
A Flutter scroll detector example.
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
@hacker1024
hacker1024 / aaatest.dart
Created October 11, 2020 12:17
An IntelliJ IDEA live template for Dart testing implementing Reso Coder's "Arrange, Act, Assert" structure
test(
'should $TITLE$',
() async {
// Arrange
$ARRANGE$
// Act
$ACT$
// Assert
@hacker1024
hacker1024 / caddy_json_systemd_override.conf
Last active October 1, 2020 05:41
Caddy 2 systemd service override to load a JSON configuration file
[Service]
ExecStart=
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile.json
ExecReload=
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile.json
@hacker1024
hacker1024 / custom_context_menu.dart
Created August 24, 2020 05:51
A mixin to provide convenience methods to record a tap position and show a popup menu - based on https://stackoverflow.com/a/63555370/13458266
import 'package:flutter/material.dart' hide showMenu;
import 'package:flutter/material.dart' as material show showMenu;
/// A mixin to provide convenience methods to record a tap position and show a popup menu.
mixin CustomPopupMenu<T extends StatefulWidget> on State<T> {
Offset _tapPosition;
/// Pass this method to an onTapDown parameter to record the tap position.
void storePosition(TapDownDetails details) => _tapPosition = details.globalPosition;