Skip to content

Instantly share code, notes, and snippets.

View libsteve's full-sized avatar

Steven Brunwasser libsteve

View GitHub Profile
@libsteve
libsteve / CycleIterator.swift
Created April 17, 2018 04:58
An iterator to endlessly iterate over the same sequence.
struct CycleIterator<Element>: IteratorProtocol, ExpressibleByArrayLiteral {
private var elements: [Element]
private var offset: Int = 0
init(_ elements: [Element]) {
self.elements = elements
}
init(arrayLiteral elements: Element...) {
self.init(elements)
@libsteve
libsteve / Zip3Sequence.swift
Created April 15, 2018 06:19
An implementation of zip that combines the elements of three sequences.
import Foundation
struct Zip3Sequence<Sequence1, Sequence2, Sequence3>: Sequence
where Sequence1: Sequence, Sequence2: Sequence, Sequence3: Sequence {
typealias Element = Iterator.Element
typealias Iterator = Zip3Iterator<Sequence1.Iterator, Sequence2.Iterator, Sequence3.Iterator>
private var s1: Sequence1
private var s2: Sequence2
private var s3: Sequence3
@libsteve
libsteve / reverse-utf8-string.c
Created February 1, 2018 02:13
The proper way to reverse the code points in a UTF-8 encoded string.
#include <stdio.h>
#include <assert.h>
/// Count the amount of bytes contained within a null-terminated string.
/// - returns: The amount of bits before the null-terminator in the given string.
int string_length(char const *const string);
/// Reverse an array of bytes in-place.
/// - parameter bytes: A buffer of bytes to be reversed.
/// - parameter length: The amount of bytes contained within the buffer that should be reversed.
@libsteve
libsteve / NiceConstraints.swift
Last active July 18, 2017 23:57
AutoLayout using Operators
/// - note: The equivalence operators don't work because `NSObject` implements `Equatable`.
import UIKit
// MARK: Constraint From Anchor
public func == <AnchorType>(constrained: NSLayoutAnchor<AnchorType>, reference: NSLayoutAnchor<AnchorType>) -> NSLayoutConstraint {
return constrained.constraint(equalTo: reference)
}
@libsteve
libsteve / Graphing.fs
Last active December 19, 2015 23:46
An F# module that contains functions and data structures for dealing with a graph of vertices and edges connecting them.
module Graphing.Graph
[<StructuralEquality; StructuralComparison>]
type Point =
| Point of float * float
static member X (Point (x, _)) = x
static member Y (Point (_, y)) = y
/// <summary>
@libsteve
libsteve / dymoPrintLCCN.applescript
Last active November 12, 2015 08:34
Command line utility to convert an ISBN to a Library of Congress Column Number
#!/usr/bin/osascript
on printLCCN(LCCN)
tell application "DYMO Label"
set paperOrientation to portrait
tell print object 1
set object text to LCCN
end tell
printLabel2 of it
end tell
@libsteve
libsteve / Migration.js
Last active January 11, 2019 05:04
A script for migrating the primary domain of a Google Apps account.
// migrate the script executer's primary domain
// domainName - the desired domain to migrate to
function migrateDomain(organizationName, domainName) {
var customerId = 'my_customer';
var customer = AdminDirectory.Customers.get(customerId);
customer.customerDomain = domainName;
customer.postalAddress.organizationName = organizationName;
customer.customerCreationTime = undefined; //
AdminDirectory.Customers.patch(customer, customerId);
@libsteve
libsteve / KonradZuse.c
Created June 6, 2015 00:10
A German if-then-else-end expression in C
#include <stdbool.h>
#define wenn (
#define dann ) ? (
#define sonst ) : (
#define ende )
int main() {
int x = wenn true dann 10 sonst 11 ende;
}
@libsteve
libsteve / Circle.m
Created May 7, 2014 20:04
Here is the code for getting points around a circle.
static CGPoint convertRadianToCGPoint( double angle, double length, CGPoint center ) {
double xCoord = length * cos( angle );
if( angle == M_PI ) {
xCoord = -length;
}
double yCoord = length * sin( angle );
if( angle == (3 * M_PI)/2 ){
yCoord = -length;
}

Keybase proof

I hereby claim:

  • I am altece on github.
  • I am altece (https://keybase.io/altece) on keybase.
  • I have a public key whose fingerprint is 8BB9 7FF6 F003 F8D1 C91D 05CE 42A6 ECA9 5595 440E

To claim this, I am signing this object: