Skip to content

Instantly share code, notes, and snippets.

View cemolcay's full-sized avatar
🎼
🎶

Cem Olcay cemolcay

🎼
🎶
View GitHub Profile
@cemolcay
cemolcay / ABLLinkManager.swift
Last active October 21, 2024 17:56
Swift 4.0 port for LinkKit iOS of Ableton Link
//
// ABLLinkManager.swift
//
// Created by Cem Olcay on 5.03.2018.
// Copyright © 2018 cemolcay. All rights reserved.
//
import Foundation
import AVFoundation
func convertValue(oldValue: CGFloat, oldMin: CGFloat, oldMax: CGFloat, newMin: CGFloat, newMax: CGFloat) -> CGFloat {
let oldRange = oldMax - oldMin
let newRange = newMax - newMin
return (((oldValue - oldMin) * newRange) / oldRange) + newMin
}
@cemolcay
cemolcay / circular-array-subscript.swift
Created October 5, 2017 07:03
Swift circular array subscript
extension Array {
subscript(circular index: Int) -> Element? {
var i = index
if i < 0 || isEmpty {
return nil
} else if i > count - 1 {
i = index % count
}
return self[i]
}
@cemolcay
cemolcay / gist:8d408e0ded9263e31aa10b4cc358311b
Created August 14, 2017 21:59
hackerrank swift input reader
import Foundation
var input = [[Int]]()
while let line = readLine() {
input.append(line.components(separatedBy: [" "]).map { Int($0)! })
}
print(input)
@cemolcay
cemolcay / git-tag-move.sh
Created August 14, 2017 12:13
git-tag-move.sh
# git-tag-move.sh
TAG = $1
COMMIT = $2
git tag --force TAG COMMIT
git push --force --tags
@cemolcay
cemolcay / killport.sh
Created August 3, 2017 08:32
killport.sh
PORT=$1
PIDS=$(lsof -t -i:$PORT)
for i in ${PIDS[@]}
do
kill -9 $i
echo "PID $i on port $PORT killed"
done
@cemolcay
cemolcay / TensorflowNOT.py
Created June 28, 2017 07:22
NOT logical problem with Tensorflow
from __future__ import absolute_import, division, print_function
import tensorflow as tf
import tflearn
import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
# Logical NOT operator
X = [[0.], [1.]]
@cemolcay
cemolcay / NSBezierPath port
Created February 1, 2017 10:48
UIBezierPath methods missing on NSBezierPath for swift 3
public struct NSRectCorner: OptionSet {
public let rawValue: UInt
public static let none = NSRectCorner(rawValue: 0)
public static let topLeft = NSRectCorner(rawValue: 1 << 0)
public static let topRight = NSRectCorner(rawValue: 1 << 1)
public static let bottomLeft = NSRectCorner(rawValue: 1 << 2)
public static let bottomRight = NSRectCorner(rawValue: 1 << 3)
public static var all: NSRectCorner {
return [.topLeft, .topRight, .bottomLeft, .bottomRight]
@cemolcay
cemolcay / ArcTextLayer.swift
Created January 22, 2017 22:03
Draws a curved string on a CALayer with angle, radius and text that you give.
import UIKit
// swift port of stackoverflow answer
// http://stackoverflow.com/a/31301238/2048130
extension CGFloat {
/** Degrees to Radian **/
var degrees: CGFloat {
return self * (180.0 / .pi)
}
@cemolcay
cemolcay / NoiseMap.swift
Created November 13, 2016 16:56
Having fun with GKNoiseMap procedurally generated tile maps
//: Playground - noun: a place where people can play
import UIKit
import SpriteKit
import GameplayKit
enum NoiseTileType: CustomStringConvertible {
case ocean
case grass
case mountain