Skip to content

Instantly share code, notes, and snippets.

@marcinkuptel
marcinkuptel / StringHash.swift
Created February 16, 2016 20:49
Function computing a hash value of a string
let prime = 1231247
let alphabetSize = 26
let A: UInt32 = 96
func stringHash(inout input: String, fromIndex: String.UnicodeScalarView.Index, length: Int) -> Int {
var hash = 0
var index = fromIndex
for i in 0..<length {
let char = input.unicodeScalars[index]
@marcinkuptel
marcinkuptel / ArrayRotation.swift
Last active February 6, 2016 15:32
Algorithm rotating the contents of an array by the number of positions specified as a parameter.
extension Array
{
mutating func rotateBy(var positions: Int) {
positions = positions < 0 ? (self.count - abs(positions) % self.count) : positions % self.count
if self.count % 2 == 0 {
rotateFrom(0, elements: self.count/2, stride: positions)
rotateFrom(1, elements: self.count/2, stride: positions)
}else{
@marcinkuptel
marcinkuptel / SlideMenuController.cs
Last active September 3, 2017 19:42
SlideMenuController - Advanced UI with Xamarin.iOS
using System;
using Foundation;
using UIKit;
using System.Collections.Generic;
using System.Diagnostics;
using CoreGraphics;
namespace iOS
{
/// <summary>
@marcinkuptel
marcinkuptel / IProxyViewDelegate.cs
Created October 24, 2015 17:02
IProxyViewDelegate - Advanced UI with Xamarin.iOS
using System;
namespace iOS
{
public interface IProxyViewDelegate
{
void ScrollViewDidScroll(int scrollViewIndex, nfloat offsetY);
void ParentScrollViewDidScroll(nfloat offsetX);
void ProxyTappedAtLocation(ProxyView proxyView, CoreGraphics.CGPoint location);
}
@marcinkuptel
marcinkuptel / ProxyView.cs
Created October 24, 2015 16:43
ProxyView - Advanced UI with Xamarin.iOS
using System;
using System.Collections.Generic;
using UIKit;
using CoreGraphics;
using Foundation;
namespace iOS
{
public class ProxyView: UIView
{
@marcinkuptel
marcinkuptel / BSTValidator.m
Last active August 29, 2015 14:22
Method checking whether a binary tree is also a BST
#import <Foundation/Foundation.h>
@interface Node: NSObject
@property (nonatomic, readonly, assign) int key;
@property (nonatomic, readonly, strong) id value;
@property (nonatomic, strong) Node *left;
@property (nonatomic, strong) Node *right;
+ (Node*) nodeWithKey: (int) key value: (id) value;