Skip to content

Instantly share code, notes, and snippets.

View ianpartridge's full-sized avatar

Ian Partridge ianpartridge

  • IBM
  • UK
View GitHub Profile
@ianpartridge
ianpartridge / timerfdtest.c
Last active July 4, 2023 08:20
epoll timerfd example
#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/epoll.h>
#include <sys/timerfd.h>
static char *itimerspec_dump(struct itimerspec *ts);
#!/bin/bash
# Shell script to change a Swift package dependency to another branch
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin
git checkout $1
@ianpartridge
ianpartridge / AsyncOperation.swift
Last active January 23, 2017 11:21
Asynchronous Operation in Swift 3
import Foundation
import Dispatch
class AsyncOperation: Foundation.Operation {
private let queue = DispatchQueue(label: "async.operation.queue")
private var _executing = false
private var _finished = false
// You have an enumeration:
enum Enum {
case foo(Int)
case bar(String)
case qux(Int)
}
// And you have an array of them:
@ianpartridge
ianpartridge / foundation_on_linux.md
Last active August 8, 2017 13:20
Foundation on Linux
layout title
page
Foundation on Linux

Foundation

As a core library which underpins many Swift packages, the Foundation project is a key part of the overall swift.org ecosystem. Foundation provides a baseline of fundamental types and functionality which is useful to all applications and can be implemented on a broad range of platforms and operating systems.

Since Swift became open source in 2015 the community has worked together to improve the implementation of Foundation on Linux and the project has progessed significantly.

@ianpartridge
ianpartridge / foundation_history.sh
Created August 2, 2017 11:26
Show the number of NSUnimplemented() methods in swift-corelibs-foundation over time
#!/bin/bash
for commit in $(git rev-list --no-merges master)
do
DATE=$(git show -s --date=iso-local --format=%cd $commit)
COUNT=$(git grep NSUnimplemented $commit | wc -l)
echo "$commit, $DATE, $COUNT"
done
@ianpartridge
ianpartridge / swift-linux-testing.md
Created August 9, 2017 13:00
Swift Packages: Linux Compatibility Testing

Swift Packages: Linux Compatibility Testing

As the Swift on Linux and Swift Package Manager ecosystems mature, many authors of Swift packages want to enable their packages on Linux as well as Apple platforms. The growth of Server-Side Swift makes Linux an important target for many packages.

The first step is to run a package's unit tests on Linux, to verify it behaves as expected.

Enabling unit tests on Linux

Because Swift on Linux does not use the Objective-C runtime, the dynamic features that the XCTest unit testing framework uses to automatically discover testcases are not available.

import Foundation
import PlaygroundSupport
struct Film: Decodable
{
let title: String
}
struct Films: Decodable
{
// swift-tools-version:4.2
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "MyServer",
dependencies: [
.package(url: "https://github.com/IBM-Swift/Kitura.git", .upToNextMinor(from: "2.6.1")),
.package(url: "https://github.com/IBM-Swift/Kitura-CredentialsHTTP.git", .upToNextMinor(from: "2.1.1")),
@ianpartridge
ianpartridge / foundation.md
Created May 1, 2019 09:37
The effect of linking Foundation on Linux

Without Foundation:

# swift package init --type executable && swift run
Creating executable package: bare
Creating Package.swift
Creating README.md
Creating .gitignore
Creating Sources/
Creating Sources/bare/main.swift