Skip to content

Instantly share code, notes, and snippets.

View LuizZak's full-sized avatar

Luiz Fernando LuizZak

  • São Paulo, Brasil
View GitHub Profile
@LuizZak
LuizZak / gist:9cd03f8b090ffc56af15
Last active February 27, 2024 17:35
C# rolled vs unrolled loop
using System;
using System.Diagnostics;
using System.Windows.Forms;
namespace Test
{
static class Program
{
[STAThread]
static void Main(string[] args)
@LuizZak
LuizZak / gist:06cf133166cd4bf32f5e
Last active August 29, 2015 14:18
LINQPad runnable resolution to the Fix the Index interview problem (http://ayende.com/blog/170402/interview-question-fix-the-index)
void Main()
{
var tests = new IndexTests();
tests.CanIndexAndQuery();
tests.CanUpdate();
}
// Internal doc class
class Document
@LuizZak
LuizZak / EnumBinaryTree.swift
Last active January 7, 2016 19:44
Simple self-balancing binary tree data structure written with enums in Swift 2.0
import Foundation
/// A protocol to be implemented by self-contained, recursive binary-tree data structures
protocol BinaryTreeType: SequenceType, CustomStringConvertible {
/// The type of element stored in this binary tree. This value must implement the Comparable protocol
typealias Element: Comparable
/// Gets the value in this binary tree element
var value: Element? { get }
@LuizZak
LuizZak / retry.swift
Last active February 12, 2018 10:27
PromiseKit retrying functions using encapsulated blocks that return promises
/// Retries the given throwing `block` as a promise `tries` times,
/// re-calling `block` another time until exhausting the tries.
func retry<T>(tries count: Int, block: () throws -> T) -> Promise<T> {
return Promise().thenRetry(tries: count, block: block)
}
/// Retries the given promise-returning `block` as a promise `tries` times,
/// re-calling `block` another time until exhausting the tries.
func retry<T>(tries count: Int, block: () -> Promise<T>) -> Promise<T> {
return Promise().thenRetry(tries: count, block: block)
@LuizZak
LuizZak / README.md
Last active February 22, 2019 00:50
A chainable, storable, composable configuration object featuring Swift keypaths

With.swift - A chainable, storable, composable configuration object featuring Swift keypaths

Based on some source I don't exactly remember right now but will add a link to later.

// When used on instances, allows changing fields directly using keypaths (handy way to avoid 'lazy var' property closures!)
let label
    = UILabel()
        .with(\.text, setTo: "Hello!")
        .with(\.textColor, setTo: UIColor.darkGray)
@LuizZak
LuizZak / SwiftGrammar.md
Last active November 27, 2018 10:23
Swift's Grammar Summary
@LuizZak
LuizZak / RC211V.mr
Last active September 9, 2022 01:50
RC221V
import "engine_sim.mr"
// Honda RC211V 75.5° V5 - used in MotoGP from ~2001-2004
// Reference for some of the numbers in the design: https://patents.google.com/patent/US6745730B2/en
// Potential firing order referenced from: https://youtu.be/U5_wWC2cURU?t=260
/*
- Running engine:
- main.mr: