Skip to content

Instantly share code, notes, and snippets.

View YanSte's full-sized avatar
🌎
Working from Zurich

Yannick Stephan YanSte

🌎
Working from Zurich
View GitHub Profile
@rwoloszyn
rwoloszyn / SettingsTest.java
Created October 3, 2016 11:45
Reset singleton field during JUnit tests, roboelectric junit tests
@After
public void teaddown() {
setting.clear();
resetSingleton(ErgoSettings.class, "sInstance");
}
public static void resetSingleton(Class clazz, String fieldName) {
Field instance;
try {
@KennethanCeyer
KennethanCeyer / open_zshrc_on_mac.sh
Created February 3, 2017 17:29
Open zshrc file to note on Mac
open ~/.zshrc
@Azoy
Azoy / install-swift-ubuntu.md
Last active December 9, 2022 03:42
Guide on how to install Swift on Ubuntu

Install Swift on Ubuntu

Requirements

  1. Ubuntu 14.04, 16.04, or 16.10

Step 1 - Dependencies

  1. Open up terminal
  2. Install core deps: sudo apt-get install clang libicu-dev git

Step 1.1 - Ubuntu 14.04 Clang

@dankogai
dankogai / gist:52cd6ef645c9fc248547b79dccd8e893
Created September 22, 2018 12:25
swift 4.2 on ubuntu 18.04 quick start
$ cd ~ # home directory で作業
$ sudo apt-get install clang libicu-dev libcurl4
$ wget https://swift.org/builds/swift-4.2-release/ubuntu1804/swift-4.2-RELEASE/swift-4.2-RELEASE-ubuntu18.04.tar.gz
$ tar xvpf swift-4.2-RELEASE-ubuntu18.04.tar.gz
$ export PATH=~/swift-4.2-RELEASE-ubuntu18.04/usr/bin:$PATH
enum Shortcuts: String {
case refreshList = "com.vialyx.MVD.refresh_list"
var identifier: String {
return rawValue
}
var title: String {
switch self {
case .refreshList:
@stinger
stinger / CombineFetcher.swift
Last active January 28, 2023 18:07
Combine - fetching data using URLSession publishers
import Foundation
import Combine
enum APIError: Error, LocalizedError {
case unknown, apiError(reason: String)
var errorDescription: String? {
switch self {
case .unknown:
return "Unknown error"
@liamnichols
liamnichols / URL+StaticString.swift
Created July 10, 2020 06:52
A non-failable initialiser extension for URL that accepts StaticString
import Foundation
extension URL {
/// Initialize with a static string.
///
/// If the `URL` cannot be formed with the string (for example, if the string contains characters that are illegal in a URL, or is an empty string), a precondition failure will trigger at runtime.
init(staticString: StaticString) {
guard let url = Self.init(string: String(describing: staticString)) else {
preconditionFailure("'\(staticString)' does not represent a legal URL")
}
@YanSte
YanSte / VibrationService.swift
Last active April 16, 2021 08:34
Vibration service on iOS
//
// Vibration.swift
//
// Created by Yannick Stephan on 2020-11-21.
//
import UIKit
import AudioToolbox
enum VibrationService {
@IanKeen
IanKeen / AnyPublisher+Extension.swift
Created March 17, 2021 17:02
Extension to create an AnyPublisher to easily 'lift' async code into Combine
extension AnyPublisher where Failure: Error {
struct Subscriber {
fileprivate let send: (Output) -> Void
fileprivate let complete: (Subscribers.Completion<Failure>) -> Void
func send(_ value: Output) { self.send(value) }
func send(completion: Subscribers.Completion<Failure>) { self.complete(completion) }
}
init(_ closure: (Subscriber) -> AnyCancellable) {
import gc
import os
import sys
import psutil
import threading
import argparse
import transformers
import datasets
import numpy as np
import torch