Skip to content

Instantly share code, notes, and snippets.

View colemancda's full-sized avatar
🏎️
Working with Swift on ARM

Alsey Coleman Miller colemancda

🏎️
Working with Swift on ARM
View GitHub Profile
@futurejones
futurejones / swift-apt-repo-install.sh
Last active October 10, 2023 12:54
Install script for the Swift Community Apt Repository - https://swiftlang.xyz
#! /bin/bash
#
# Install script for the Swift Community Apt Repository - swiftlang.xyz
#
# check distribution version and infer distro with switch/case
## as all distribution versions have different names we can use this information to infer the distribution name.
check_ver () {
for var in "${SUPPORTED_VER[@]}"
do
@akihikodaki
akihikodaki / README.en.md
Last active September 7, 2024 13:11
Linux Desktop on Apple Silicon in Practice

Linux Desktop on Apple Silicon in Practice

I bought M1 MacBook Air. It is the fastest computer I have, and I have been a GNOME/GNU/Linux user for long time. It is obvious conclusion that I need practical Linux desktop environment on Apple Silicon.

Fortunately, Linux already works on Apple Silicon/M1. But how practical is it?

  • Two native ports exist.
@squeuei
squeuei / lichee-nano-fel.md
Last active October 14, 2023 20:58
How to enter FEL mode on Lichee nano

How to enter FEL mode on Lichee nano

If SPI flash isn't on the board, just remove the TF(microSD) card from the board and supply the power. It's the same if SPI flash is empty,

If your board have a SPI flash with preloaded image, pull D4(SPI CLK) down to GND. You can use the metal part of USB micro B or TF card slot as GND. Diagram is in the comment below. Thanks: @ernestp for the correction and providing a diagram.

Or you can use the special boot image [link]. Just write it to a TF card and boot.

Don't forget to remove the GND connection after entering FEL mode otherwise you will never be able to write the boot image to the SPI flash.

apt-get install qemu qemu-user qemu-user-static binfmt-support debootstrap binutils
sudo debootstrap --foreign --arch i386 stretch  ./chroot-stretch-i386/ http://deb.debian.org/debian/
mount -t sysfs /sys ./chroot-stretch-i386/sys/
mount -t proc /proc ./chroot-stretch-i386/proc/
mount –-bind /dev ./chroot-stretch-i386/dev/
mount –-bind /dev/pts ./chroot-stretch-i386/dev/pts/
@AvdLee
AvdLee / DarwinNotificationCenter.swift
Last active August 1, 2024 11:24
A notification center for Darwin Notifications. MIT License applies.
//
// DarwinNotificationCenter.swift
//
// Copyright © 2017 WeTransfer. All rights reserved.
//
import Foundation
/// A Darwin notification payload. It does not contain any userInfo, a Darwin notification is purely event handling.
public struct DarwinNotification {
@AliSoftware
AliSoftware / Bindings.swift
Last active September 2, 2024 22:48
Re-implementation of @binding and @State (from SwiftUI) myself to better understand it
/*:
This is a concept re-implementation of the @Binding and @State property wrappers from SwiftUI
The only purpose of this code is to implement those wrappers myself
just to understand how they work internally and why they are needed,
⚠️ This is not supposed to be a reference implementation nor cover all
subtleties of the real Binding and State types.
The only purpose of this playground is to show how re-implementing
them myself has helped me understand the whole thing better
@Azoy
Azoy / syscall.swift
Last active August 25, 2023 21:49
Raw system calls in Swift
// macOS x86_64 syscall works as follows:
// Syscall id is moved into rax
// 1st argument is moved into rdi
// 2nd argument is moved into rsi
// 3rd argument is moved into rdx
// ... plus some more
// Return value is stored in rax (where we put syscall value)
// Mac syscall enum that contains the value to correctly call it
enum Syscall: Int {
@steipete
steipete / UIKit+iOSMac.h
Last active February 6, 2022 14:53
iOSMac Marzipan Toolbar Access. Learn more at https://speakerdeck.com/steipete/hacking-marzipan
#import <Foundation/Foundation.h>
@class NSString, UHASToolbarItem;
__attribute__((weak_import)) @interface _UIWindowToolbarItem : NSObject
@property(readonly, copy, nonatomic) NSString *label;
@property(readonly, copy, nonatomic) NSString *identifier;
- (id)initWithIdentifier:(id)arg1;
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active September 24, 2024 21:51
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

@beccadax
beccadax / JSONFeed.swift
Last active June 18, 2020 08:21
JSON Feed parser in Swift 4—now updated for Xcode 9 Beta 1. Uses the new Codable protocol and JSONDecoder class.
import Foundation
let feedURL = URL(string: "https://daringfireball.net/feeds/json")!
// MARK: Basic models
// We do not model the `userComment` field because it is not supposed to be used by
// machines. We do not model extensions because they should be ignored unless
// supported anyway.
struct Feed {