Skip to content

Instantly share code, notes, and snippets.

@chriseidhof
chriseidhof / helloworld.swift
Created May 28, 2018 13:58
NIO Hello World
import Foundation
import NIO
import NIOHTTP1
// Inspired/parts copied from http://www.alwaysrightinstitute.com/microexpress-nio/
final class HelloHandler: ChannelInboundHandler {
typealias InboundIn = HTTPServerRequestPart
func channelRead(ctx: ChannelHandlerContext, data: NIOAny) {
@JohnSundell
JohnSundell / simrecord
Created March 16, 2018 21:05
🎥 Script that lets you start a video recording from the iOS simulator with one command
#!/bin/bash
ITERATION=1
EXTENSION="mp4"
FILENAME="$HOME/Desktop/Simulator Recording.$EXTENSION"
while [ -e "$FILENAME" ]
do
ITERATION=$((ITERATION+1))
FILENAME="$HOME/Desktop/Simulator Recording $ITERATION.$EXTENSION"
@mbinna
mbinna / effective_modern_cmake.md
Last active May 14, 2024 03:01
Effective Modern CMake

Effective Modern CMake

Getting Started

For a brief user-level introduction to CMake, watch C++ Weekly, Episode 78, Intro to CMake by Jason Turner. LLVM’s CMake Primer provides a good high-level introduction to the CMake syntax. Go read it now.

After that, watch Mathieu Ropert’s CppCon 2017 talk Using Modern CMake Patterns to Enforce a Good Modular Design (slides). It provides a thorough explanation of what modern CMake is and why it is so much better than “old school” CMake. The modular design ideas in this talk are based on the book [Large-Scale C++ Software Design](https://www.amazon.de/Large-Scale-Soft

@shaps80
shaps80 / Color.swift
Last active December 25, 2019 04:06
A Swift color value-type. Includes hexadecimal values support, ExpressibleByString, Swift 4 Codable and other conveniences.
/*
Copyright © 01/10/2016 Shaps
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@amake
amake / glyphtest.swift
Last active December 14, 2017 05:28
Dump glyph names on iOS in order to test availability (Swift 3)
/*
* Make a dummy application and run this in e.g. UIApplicationDelegate.application(_:didFinishLaunchingWithOptions:)
*/
let filemanager = FileManager.default
let docsdir = filemanager.urls(for: .documentDirectory, in: .userDomainMask).first!
try! filemanager.createDirectory(at: docsdir, withIntermediateDirectories: true, attributes: nil)
let outfile = docsdir.appendingPathComponent("glyphtest.txt")
filemanager.createFile(atPath: outfile.path, contents: nil, attributes: nil)
@katoy
katoy / draw.swift
Last active October 28, 2016 09:48
draw line in playground (Xcode 6.1)
// See http://techlife.cookpad.com/entry/2014/11/12/170041
//
// 本来はplayground用に用意されているXCPlaygroundフレームワークのXCPShowViewを使って
// Timelineに表示することが可能ですが、現行のXcode6.1でiOS用にUIKitを使って表示した場合
// コンソールにエラーが出てしまうため使用していません。
//
import UIKit
// ビューのサイズ
@aleclarson
aleclarson / DisplayLink.swift
Last active August 21, 2019 08:34
A block-based CADisplayLink for Swift
@watert
watert / UITableView.swift
Last active July 21, 2017 15:10
UITableView example in iOS Playground with XCode 6 beta
// Playground - noun: a place where people can play
import UIKit
class ViewController: UIViewController ,UITableViewDelegate, UITableViewDataSource
{
var tableView: UITableView!
var items: NSMutableArray!
override func viewDidLoad() {
super.viewDidLoad()
@correia
correia / swift-kvo-example.swift
Last active April 16, 2023 02:38
A quick example for how to use Foundation style KVO from Swift. (Official documentation from Apple is forthcoming.)
//
// Swift-KVO
//
// Created by Jim Correia on 6/5/14.
// Copyright (c) 2014-2015 Jim Correia. All rights reserved.
//
// Update: 6/17/2014
//
// KVOContext has gone away; use the same idiom you'd use from Objective-C for the context
//
@ebiggs
ebiggs / Maybe.coffee
Last active June 20, 2016 04:32
CoffeeScript Maybe Monad - couldn't find one with a Google search so I had to roll my own, hopefully this one showed up for yours ;) Good code coverage in the jasmine spec, so feel confident using it with reckless abandon ;) Maybe.coffee was definitely built with Some(coffea arabica) in my veins ;)
###
Like java, javascript is optimized for throwing null pointer exceptions
coffeescript helps with its series of ? operators
but here is a scala option-eqsue "maybe monad" when such semantics
are preferred over the ? operators or when you want your data
to self-document its indefinite-ness (regular vars don't warn you
that you may get null or undefined!).
note that we're perfectly happy to give you a Some(null) or a Some(undefined)
just like scala. if you have an x that you want to fmap to None if it's