Skip to content

Instantly share code, notes, and snippets.

View buehler's full-sized avatar
🧙‍♂️
Keeper of the seven Hacks

Christoph Bühler buehler

🧙‍♂️
Keeper of the seven Hacks
View GitHub Profile
@buehler
buehler / async_lazy.dart
Created June 7, 2024 06:57
Lazy and AsyncLazy initializator for Dart / Flutter applications
import 'dart:async';
class AsyncLazy<T> {
static final _cache = Expando();
final FutureOr<T> Function() _factory;
final FutureOr Function(T)? _valueDispose;
const AsyncLazy(this._factory, [this._valueDispose]);
@buehler
buehler / worker.dart
Last active June 4, 2024 15:21
Generic Dart Isolate Worker, allows spawning a new isolate in dart and compute _anything_ in futures or streams that can be transmitted to isolates. Works with closures instead of messages.
import 'dart:async';
import 'dart:isolate';
class IsolateWorker {
IsolateWorker._(this._receivePort, this._sendPort);
final ReceivePort _receivePort;
final SendPort _sendPort;
bool _isDisposed = false;
static Future<IsolateWorker> create({String? debugName}) async {
@buehler
buehler / clickable.dart
Created March 3, 2023 04:25
"Clickable" widget for flutter that makes any widget clickable and hoverable.
import 'package:flutter/widgets.dart';
/// Makes any widget inside clickable and hover-able.
/// If the onPressed callback is null, the widget will not catch any
/// click events (but still hover events).
class Clickable extends StatefulWidget {
final Widget Function(BuildContext context, bool isHovered) builder;
final VoidCallback? onPressed;
const Clickable({super.key, this.onPressed, required this.builder});
@buehler
buehler / launch.json
Last active September 20, 2024 15:50
Debugging Rust repository in Windows with CPP Tools
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceRoot}/target/debug/<APP NAME>.exe",
"args": [],
"stopAtEntry": false,
@buehler
buehler / LocalizedIdentityErrors.cs
Created October 28, 2019 11:29
Identity Error Describer (asp.net core identity) with string localizer.
public class LocalizedIdentityErrors : IdentityErrorDescriber
{
private readonly IStringLocalizer<LocalizedIdentityErrors> _localizer;
public LocalizedIdentityErrors(IStringLocalizer<LocalizedIdentityErrors> localizer)
{
_localizer = localizer;
}
public override IdentityError DefaultError() => new IdentityError
@buehler
buehler / DefaultProxyHandler.ts
Last active November 21, 2016 07:22
Default implementation of the ProxyHandler
export class DefaultProxyHandler<T> implements ProxyHandler<T> {
public getPrototypeOf(target: T): any {
return Object.getPrototypeOf(target);
}
public setPrototypeOf(target: T, proto: any): boolean {
return Object.setPrototypeOf(target, proto);
}
public isExtensible(target: T): boolean {
@buehler
buehler / BaseViewModel.cs
Created October 21, 2015 07:32
Base view model for Xamarin bindings. Contains helper methods for setting a field and notify the binding.
using Foundation;
using System.Runtime.CompilerServices;
using System;
namespace ViewModels
{
public class BaseViewModel : NSObject
{
public event EventHandler PropertyChanged = delegate{};
@buehler
buehler / NodeJS_require_wrapper.js
Last active August 29, 2015 14:26
Wrapper for require to prevent fails in absolute pathes for windows. (Because windows does have problems with absolute paths. -> with this global function, all require actions are using "path.join")
global.__require = function () {
if (arguments.length <= 0) throw new Error('No arguments provided.');
var join = '';
for (var arg in arguments) {
if (arguments.hasOwnProperty(arg)) {
join = path.join(join, arguments[arg]);
}
}
return require(join);
};