Skip to content

Instantly share code, notes, and snippets.

@jernejstrasner
jernejstrasner / HMACDigest.swift
Last active May 4, 2020
HMAC digest in Swift
View HMACDigest.swift
// Make sure you add #import <CommonCrypto/CommonCrypto.h> to the Xcode bridging header!
enum CryptoAlgorithm {
case MD5, SHA1, SHA224, SHA256, SHA384, SHA512
var HMACAlgorithm: CCHmacAlgorithm {
var result: Int = 0
switch self {
case .MD5: result = kCCHmacAlgMD5
case .SHA1: result = kCCHmacAlgSHA1
@jernejstrasner
jernejstrasner / SmoothGradientView.m
Created Jul 6, 2015
iOS smooth gradient using CGShading
View SmoothGradientView.m
- (void)drawRect:(CGRect)rect {
// Draw the gradient background
CGContextRef context = UIGraphicsGetCurrentContext();
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
// Define the shading callbacks
CGFunctionCallbacks callbacks = {0, blackShade, NULL};
// As input to our function we want 1 value in the range [0.0, 1.0].
// This is our position within the 'gradient'.
@jernejstrasner
jernejstrasner / JSSubscriptingSupport.h
Created Aug 11, 2012
Enable subscripting support in the iOS 5.0 SDK
View JSSubscriptingSupport.h
//
// JSSubscriptingSupport.h
// JernejStrasner
//
// Created by Jernej Strasner on 7/27/12.
// Copyright (c) 2012 JernejStrasner.com. All rights reserved.
//
// Subscripting support for iOS SDK 5.0
//
@jernejstrasner
jernejstrasner / sorting.cpp
Created Apr 27, 2011
Various sorting algorithms in C++
View sorting.cpp
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <sys/time.h>
using namespace std;
/*
Funkcije
*/