Skip to content

Instantly share code, notes, and snippets.

View dennislysenko's full-sized avatar

Dennis Lysenko dennislysenko

View GitHub Profile
@dennislysenko
dennislysenko / gist:fcc65bcf24c94af82a47
Created April 5, 2015 03:42
Spotify Cocoa ScriptingBridge Header
//
// Spotify.h
// BeardedSpice
//
// Created by Dennis Lysenko on 4/4/15.
// Copyright (c) 2015 Tyler Rhodes / Jose Falcon. All rights reserved.
//
/*
* Spotify.h
@dennislysenko
dennislysenko / gist:f8e804eeec91df4f0c0c
Created April 6, 2015 16:46
[UIViewController fubar] -- method to recursively color the view hierarchy
- (void)fubar
{
[self fubarWithViews:self.view.subviews];
}
- (void)fubarWithViews:(NSArray *)views
{
for (UIView *view in views) {
CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0
CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white
CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black
//
// SpotifyTabAdapter.m
// BeardedSpice
//
// Created by Dennis Lysenko on 4/4/15.
// Copyright (c) 2015 Tyler Rhodes / Jose Falcon. All rights reserved.
//
#import "SpotifyTabAdapter.h"
#import "runningSBApplication.h"
@dennislysenko
dennislysenko / BKTree.swift
Created June 11, 2015 02:09
Fuzzy String Matching (BK Tree)
// Fuzzy string-matching algorithm
// Implementation of algorithm described at: http://blog.notdot.net/2007/4/Damn-Cool-Algorithms-Part-1-BK-Trees
// Essentially builds an index of strings by levenshtein distance (N-ary tree) on which you can run range queries.
// The root node can be chosen arbitrarily. Each node holds a string and a collection of edges, representing distance to other strings, which then have their own children and so on, building a complete index.
// See https://github.com/vy/bk-tree for (impressive) performance statistics despite this tending to create an unbalanced N-ary tree
class BKTreeNode {
var value: String
var edges: Dictionary<Int, BKTreeNode>

Keybase proof

I hereby claim:

  • I am dslysenko on github.
  • I am lysenko (https://keybase.io/lysenko) on keybase.
  • I have a public key whose fingerprint is 4087 C50D 1032 765B 843B 1FDF F6EA 64B9 5E00 ED5C

To claim this, I am signing this object:

@dennislysenko
dennislysenko / SocialAccount.swift
Created October 20, 2015 15:54
Genome+MappableCoreDataObject Example
//
// SocialAccount.swift
// Riff
//
// Created by Dennis Lysenko on 10/19/15.
// Copyright © 2015 Riff Digital. All rights reserved.
//
import Foundation
import CoreData
// Setup: We want to arm a NuclearWarhead and get a LaunchCode from it but there's a 1/10 chance of a PrematureDetonationError
// (nb: if Swift had any kind of useful random generator that I could pick up in 5 seconds I would use that instead of this pseudorandom-at-best algorithm)
struct NuclearWarhead {}
struct LaunchCode {}
struct PrematureDetonationError: ErrorType {}
func armNuclearWarhead(warhead: NuclearWarhead) throws -> LaunchCode {
let currentTimestamp = NSDate().timeIntervalSince1970
let lastDigit = currentTimestamp % 10
if lastDigit == 8 {

Keybase proof

I hereby claim:

  • I am dennislysenko on github.
  • I am lysenko (https://keybase.io/lysenko) on keybase.
  • I have a public key ASDsv4zgEBA5cq7_3BJnk-AqdpyZGlXfyyd-HBsoEpdGxQo

To claim this, I am signing this object:

@dennislysenko
dennislysenko / QuickProfiling.swift
Created February 24, 2016 18:13
Profile your Swift code when you're too lazy to use Instruments
// Profile your code when you're too lazy to use Instruments
// Method one: get the time to execute a block
func getTimeToExecute(block: () throws -> Void) rethrows -> NSTimeInterval {
let start = NSDate().timeIntervalSince1970
try block()
return NSDate().timeIntervalSince1970 - start
}
// example:
@dennislysenko
dennislysenko / SimpleMediaSaver.swift
Last active December 10, 2019 02:54
Simplifies saving media on iOS to an app-specific collection in the Photo Library
//
// SimpleMediaSaver.swift
//
// Created by Dennis Lysenko on 27-09-16.
// Copyright © 2016 Dennis Lysenko. All rights reserved.
// https://gist.github.com/dennislysenko/5388cacb83b754e8983e99bff7fef2d2
//
// This gist is licensed under the terms of the MIT license.
//