Skip to content

Instantly share code, notes, and snippets.

View Kentzo's full-sized avatar
🤖

Ilya Kulakov Kentzo

🤖
View GitHub Profile
@Kentzo
Kentzo / nptv6.rsc
Last active July 28, 2023 20:37
RouterOS: Maintain NPTv6 from dynamic DHCPv6 delegated prefix
View nptv6.rsc
# argLoopbackInt: name of the loopback interface
# argWanPool: name of the WAN pool
# argUlaPool: name of the ULA pool
# argManagedID: regex-escaped unique ID of the managed objects
:global argLoopbackInt
:global argWanPool
:global argUlaPool
:global argManagedID
@Kentzo
Kentzo / ip6.rsc
Last active July 27, 2023 23:11
RouterOS: Structured IPv6 Address
View ip6.rsc
# Usage:
#
# - $parseIP6Address ip6 [prefix length] [detail=yes]
# - $parseIP6Address ip6-prefix [detail=yes]
#
# Returns:
#
# - address (ip6): IPv6 address of the input
# addressPrefix (ip6-prefix): IPv6 address-prefix of the input
# prefix (ip6): Prefix of the input
@Kentzo
Kentzo / AoC22.pdf
Last active December 29, 2022 20:57
AoC 22
View AoC22.pdf
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Kentzo
Kentzo / README.md
Last active December 7, 2022 08:05
View README.md

The benchmark measures and compares execution time and peak memory consumption of the current and new commonpath methods.

Measurement is performed using batches of 1000 paths. Each batch contains paths generated with the following variables:

  1. Length of each path part (range(16, 65, 16))
  2. Number of parts (range(4, 17, 4))
  3. Number of common parts (range(parts_count + 1))

The batch is then split into chunks of equal size such that paths in each following chunk reduce the number of common parts so far by 1 up to the selected number [3], e.g. if the selected number of common parts is 1 then the batch would be "a/b/c", "a/b/c", "a/b/d", "a/b/d", "a/c/d", "a/c/d", "a/c/d".

Each batch is tested in two permutations:

@Kentzo
Kentzo / file.py
Last active October 16, 2022 06:38
Guess file type from python on macOS, no dependencies
View file.py
import contextlib
import subprocess
def file_proc():
args = [
'/usr/bin/file',
'--brief',
'-E',
'--no-dereference',
'--no-buffer',
View fpvector_from_uint64.asm
punpckldq xmm0, 0x4530000043300000
subpd xmm0, 0x4330000000000000
haddpd xmm0, xmm0
@Kentzo
Kentzo / FB7642814
Created March 28, 2020 09:19
Carbon API to handle Global Hot Keys should propagate hot key events as regular KeyDown / KeyUp events if not handled
View FB7642814
Among the small subset of Carbon API that still exists and has no modern replacement is an API to register Global Hot Keys. This API works in 2 steps:
1. Install an Event Handler for GetEventDispatcherTarget() for kEventHotKeyPressed and kEventHotKeyReleased
2. Registering Hot Keys with RegisterEventHotKey for GetEventDispatcherTarget()
Once the registered key combination is pressed, custom Event Handler gets called. The handler can then either return a noErr indicating that the event was processed and does not need to be propagated further, return eventNotHandledErr indicating that event should be propagated or any other error.
This issue with this API is that once a keyboard event is recognized as a Hot Key it's not put back onto event queues by macOS as a regular KeyDown / KeyUp event. Not even when all installed event handlers return eventNotHandledErr.
The workaround is to construct the appropriate KeyDown / KeyUp and manually post it on an event queue. This, unfortunately, requires the app to have t
View _0_NoReentryScope.m
void _NoReentryScopeEnter(BOOL *aVar)
{
if (*aVar)
[NSException raise:NSInternalInconsistencyException format:@"the method is not reentrable"];
*aVar = YES;
}
void _NoReentryScopeLeave(BOOL **aVar)
{
View final_attempt.m
NS_SWIFT_NAME(RecorderControlStyle)
@interface SRRecorderControlStyle: NSObject
@end
NS_SWIFT_NAME(SRRecorderControlStyle.Components)
// NS_SWIFT_NAME(RecorderControlStyle.Components) also works!
@interface SRRecorderControlStyleComponents: NSObject
@end
typedef NS_ENUM(NSUInteger, SRRecorderControlStyleComponentsAppearance)
View apple.swift
var sandwich: Sandwich?
var preferences: Sandwich.Preferences?
var breadType: Sandwich.Preferences.BreadType?