Skip to content

Instantly share code, notes, and snippets.

@lrhn
lrhn / cancelable_zone.dart
Created July 24, 2020 11:34
A cancelable zone which stops further async computations from running when it's cancelled
import "dart:async";
/// A cancelable zone.
///
/// A [Zone], and a [cancel] function which makes the zone stop processing events.
/// After calling [cancel], the zone's timers, microtasks and `run` methods
/// ([Zone.run], [Zone.runUnary] and [Zone.runBinary]) stop doing anything.
/// Calling the `run` methods will throw, and any scheduled timers or
/// microtasks will do nothing instead of calling the configured callback.
class CancelableZone {
@slightfoot
slightfoot / media_query_extension.dart
Last active July 29, 2021 13:32
Media Query Extension - by Simon Lightfoot
// MIT License
//
// Copyright (c) 2020 Simon Lightfoot
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@lukepighetti
lukepighetti / client.dart
Last active September 7, 2021 20:54
Logging service using extensions for channels with multiple outputs
import 'package:logger/logger.dart';
void main() async {
/// Setup logging service
final remoteUrl = Uri.parse('http://localhost:8080');
final logger = LoggingService(
loggers: {
ConsoleLogger(),
RemoteLogger(baseUrl: remoteUrl),
},
@stropdale
stropdale / ReverseDnsLookup.swift
Created January 23, 2020 11:07
Swift Reverse DNS Lookup
import Foundation
func reverseDNS(ip: String) -> String {
var results: UnsafeMutablePointer<addrinfo>? = nil
defer {
if let results = results {
freeaddrinfo(results)
@reinvanoyen
reinvanoyen / terminal-prompt-git-branch-zsh.md
Last active April 22, 2025 18:55
Add Git Branch Name to Terminal Prompt (MacOS zsh)

Add Git Branch Name to Terminal Prompt (zsh)

Updated for MacOS with zsh

  • Catalina
  • Big Sur
  • Monterey
  • Ventura
  • Sonoma

screenshot

@qoomon
qoomon / conventional-commits-cheatsheet.md
Last active April 24, 2025 19:40
Conventional Commits Cheatsheet

Conventional Commit Messages starline

See how a minor change to your commit message style can make a difference.

Tip

Take a look at git-conventional-commits , a CLI util to ensure these conventions, determine version and generate changelogs

Commit Message Formats

Default

@pingbird
pingbird / armasm.dart
Created May 9, 2018 09:09
Little ARM assembler in dart
// By PixelToast
var src =
"mov r0, #69\n"
"bx lr\n"
"ldmedeq ip!, {a3-sp}\n"
"strbhi r13, [v2, lr, asr #3]!\n"
"ldrls a3, [sb], sp, asr #0x14\n";
main() {
@mutin-sa
mutin-sa / Top_Public_Time_Servers.md
Last active April 24, 2025 13:44
List of Top Public Time Servers

Google Public NTP [AS15169]:

time.google.com

time1.google.com

time2.google.com

time3.google.com

@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active April 10, 2025 19:06
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

@netgfx
netgfx / addObservers.swift
Last active March 4, 2025 07:16
Add observers to AVPlayer
// listening for current item change
self.audioQueueObserver = self.playerQueue?.observe(\.currentItem, options: [.new]) {
[weak self] (player, _) in
print("media item changed...")
}
// listening for current item status change
self.audioQueueStatusObserver = self.playerQueue?.currentItem?.observe(\.status, options: [.new, .old], changeHandler: {
(playerItem, change) in
if playerItem.status == .readyToPlay {