Skip to content

Instantly share code, notes, and snippets.

View Azoy's full-sized avatar
:shipit:

Alejandro Alonso Azoy

:shipit:
View GitHub Profile
@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

@Azoy
Azoy / Random.swift
Last active November 13, 2017 11:01
Swift Random Unification Design
public protocol RandomSource {
static var shared: RandomSource { get }
func next<T : FixedWidthInteger>(_ type: T.Type) -> T
func nextUniform<T : BinaryFloatingPoint>(_ type: T.Type) -> T
}
// Utilizes /dev/urandom
public class DevRandom: RandomSource {
public static let shared = DevRandom()
@Azoy
Azoy / Random.swift
Last active January 22, 2018 02:06
import Darwin
public protocol RandomGenerator {
func next<T : FixedWidthInteger>(_ type: T.Type) -> T
func next<T : FixedWidthInteger>(_ type: T.Type, upperBound: T) -> T
}
public enum Random : RandomGenerator {
case `default`
@Azoy
Azoy / potential.swift
Created November 16, 2017 04:14
Randomizable Potential
struct Date : Randomizable, Strideable {
typealias Stride = Int
let timestamp: UInt32
static func random<T: RandomNumberGenerator>(using generator: T) -> Date {
return Date(timestamp: (0 ... UInt32.max).random!)
}
func distance(to other: Date) -> Int {
@Azoy
Azoy / Day1.cpp
Created March 7, 2018 02:16
Advent of Code 2017
#include <iostream>
#include <string>
int solve_capcha(int *ptr, int size) {
int tmp = 0;
for (int i = 0; i < size; i++) {
int index = i - 1;
if (i == 0) {
index = size - 1;
@Azoy
Azoy / nnnn-rng-fill-buffer.md
Created April 25, 2018 01:50
Add `fillBuffer(_:)` to `RandomNumberGenerator` (WIP)

Add fillBuffer(_:) to RandomNumberGenerator

Introduction

This proposal aims to add a new method, fillBuffer(_:), to RandomNumberGenerator, and aims to move an already defaulted method into a requirement.

@Azoy
Azoy / default-values-init.md
Last active October 21, 2018 21:02
Synthesize default values in the memberwise initializer
@Azoy
Azoy / memberwise-init.md
Last active October 19, 2018 03:32
State of the Memberwise Initializer

State of the Memberwise Initializer

Prolog

Hello Evolution,

I want to discuss where we are with the current memberwise initializer for structures and where I wish to see this initializer evolve.

Refer to SE-0018 and SE-0018 Rationale. I do not speak for the author here, but I'm rathering pulling ideas and references from SE-0018 to formulate this post.

@Azoy
Azoy / day1.swift
Last active December 2, 2018 08:04
Advent of Code 2018
// Part one
let input = """
"""
print(input.split(separator: "\n").map {
Int($0)!
}.reduce(0, +))
// Part Two
@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 {