Skip to content

Instantly share code, notes, and snippets.

View descorp's full-sized avatar

Vladimir Abramichev descorp

  • Adyen
  • Amsterdam
View GitHub Profile
@descorp
descorp / lock.swift
Created October 18, 2017 12:09
Swift lock
private let lock = NSRecursiveLock()
func synchronize(closure: ()->()){
lock.lock()
defer {
closure()
lock.unlock()
}
}
@descorp
descorp / SSH grab
Created October 13, 2017 12:55
SSH grab
pbcopy < ~/.ssh/id_rsa.pub
// Swift's untyped errors are a goddam PiTA. Here's the pattern I use to try to work around this.
// The goal is basically to try to guarantee that every throwing function in the app throws an
// ApplicationError instead of some unknown error type. We can't actually enforce this statically
// But by following this convention we can simplify error handling
enum ApplicationError: Error, CustomStringConvertible {
// These are application-specific errors that may need special treatment
case specificError1
case specificError2(SomeType)
@descorp
descorp / Playground.swift
Last active October 11, 2017 13:56
Swift: Array Profiler
//: Playground - noun: a place where people can play
import UIKit
protocol Profilable: CustomStringConvertible {
mutating func appendTime() -> Double
}
struct ProfilableArray: Profilable {
private var expected: Int
@descorp
descorp / BigNumber.cs
Last active October 3, 2017 10:48
C# BigNumbers on linked lists: calculating Factorial
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution
{
struct BigNumber
{
LinkedDigit data;
@descorp
descorp / RateLimiter.cs
Last active September 14, 2020 22:25
Lock + Timer
// Our server is calling the external API using call_api that is doing the HTTP
// call. The API provider charges us if we make more than 10 calls per second.
//
// How would you implement something that keeps us below the limit?
//: [Previous](@previous)
import Foundation
import PlaygroundSupport
using System;
using Android.Widget;
using Android.Graphics;
using Android.Util;
using Android.Text;
using Android.Content;
using Android.Runtime;
using Java.Lang;
using Android.Content.Res;
@descorp
descorp / Core.FirstViewModel.cs
Last active November 2, 2015 10:53
Mvvmcross example
using Cirrious.MvvmCross.ViewModels;
using System.Collections.ObjectModel;
using System.Windows.Input;
using System;
using Cirrious.MvvmCross.Plugins.Messenger;
namespace MvvmcrossTest.Core.ViewModels
{
public class FirstViewModel
: MvxViewModel
protected override bool FitSystemWindows(Rect insets)
{
if (!this._mActionbarOverlay)
{
Log.Verbose(Tag, "setting padding");
int bottomPadding = insets.Bottom;
// TODO: Warning !! next version could be compromised
if (Build.VERSION.SdkInt == BuildVersionCodes.Lollipop)