Skip to content

Instantly share code, notes, and snippets.

@sketchytech
sketchytech / PercentageCircle.html
Created August 23, 2016 11:36
Percentage Circle in HTML Canvas
<!DOCTYPE HTML>
<html>
<head>
<style>
body {
margin: 0px;
padding: 0px;
}
</style>
</head>
@sketchytech
sketchytech / Activity+OpenIn.swift
Created July 25, 2016 09:40
UIActivityViewController that adds an Open In option
//
// ViewController.swift
// ShareTest
//
// Created by A J LEVINGS on 24/07/2016.
// Copyright © 2016 Gylphi. All rights reserved.
//
import UIKit
let UIActivityTypeOpenIn = "OpenIn"
@sketchytech
sketchytech / UIScrollingStackView.swift
Last active January 29, 2019 20:15
A stack view that scrolls (which is actually a subclass of UIScrollView)
class UIScrollingStackView:UIScrollView {
private let stack = UIStackView()
var spacing:CGFloat {
get {
return stack.spacing
}
set {
stack.spacing = newValue
}
}
@sketchytech
sketchytech / toBase.swift
Last active May 12, 2016 10:41
Swift: Conversion to different number bases (radix)
extension IntegerType {
public func toBase(b:Int) -> String
{
guard b > 1 && b < 37 else {
fatalError("base out of range")
}
let digits = ["0","1","2","3","4","5","6","7","8","9","A",
"B","C","D","E","F","G","H","I","J","K","L",
"M","N","O","P","Q","R","S","T","U","V","W",
"X","Y","Z"]
@sketchytech
sketchytech / closure.swift
Last active November 21, 2016 15:13
Swift: regular closure vs auto closure
// a regular method that doesn't have any arguments
func regularClosure(str:() -> String) {
str()
}
regularClosure{"print me!"}
// can be replaced with an @autoclosure
func autoClosure(@autoclosure str:() -> String) {
str()
}
autoClosure("print me!")
@sketchytech
sketchytech / Base64encode.swift
Last active May 5, 2016 12:14
Swift: DIY Base64 conversion (translated from Java on Wikipedia) - result compared to built-in Base64 encoding
// a translation of the Java implementation provided here: https://en.wikipedia.org/wiki/Base64
let CODES = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
func base64Encode(u:[Int]) -> String {
var out = ""
var b = 0
var i = 0
while i < u.count {
b = (u[i] & 0xFC) >> 2
out.append(CODES[CODES.startIndex.advancedBy(b)])
b = (u[i] & 0x03) << 4
@sketchytech
sketchytech / article.json
Last active March 25, 2016 15:48
Apple News Format: Scalable Images and Component Animations
{
"version": "1.1",
"identifier": "sketchyTech_Demo",
"title": "My First Article",
"language": "en",
"layout": {},
"components": [{
"role": "title",
"text": "My First Article",
"textStyle": "titleStyle",
@sketchytech
sketchytech / article.json
Last active April 21, 2017 15:54
Apple News Format: Column Layout
{
"version": "1.4",
"identifier": "sketchyTech_Demo",
"title": "My First Article",
"language": "en",
"layout": {
"columns": 3,
"width": 1024,
"margin": 30,
"gutter": 20
@sketchytech
sketchytech / channel.py
Last active March 24, 2016 14:17
Apple News Format: Read Channel, Section and Article (GET Request)
#!/usr/bin/python
import requests
import base64
from hashlib import sha256
import hmac
from datetime import datetime
channel_id = '[YOUR CHANNEL ID]'
api_key_id = '[YOUR CHANNEL KEY]'
api_key_secret = '[YOUR SECRET KEY]'
@sketchytech
sketchytech / article.json
Created March 24, 2016 09:10
Apple News Format: Mosaic and Gallery Images
{
"version": "1.1",
"identifier": "sketchyTech_Demo",
"title": "My First Article",
"language": "en",
"layout": {},
"components": [{
"role": "title",
"text": "My First Article",
"textStyle": "titleStyle"