Skip to content

Instantly share code, notes, and snippets.

View rcdilorenzo's full-sized avatar
🙌
Working in His Kingdom (Col 3:17)

Christian Di Lorenzo rcdilorenzo

🙌
Working in His Kingdom (Col 3:17)
View GitHub Profile
@rcdilorenzo
rcdilorenzo / main.go
Last active August 17, 2017 02:19
Golang port (for fun/school) of simple recommendation system from http://guidetodatamining.com/chapter2/
package main
import (
"fmt"
"math"
"sort"
)
type Recommendation struct {
Name string
@rcdilorenzo
rcdilorenzo / Button.swift
Created July 19, 2017 12:40
Various iOS extensions for creating reusable views in code
import UIKit
extension UIButton {
static func createBordered(light: Bool) -> UIButton {
let button = UIButton(type: .roundedRect)
button.contentEdgeInsets = UIEdgeInsets(top: 5, left: 7, bottom: 5, right: 7)
button.layer.cornerRadius = 5
button.translatesAutoresizingMaskIntoConstraints = false
if (light) {
button.backgroundColor = UIColor.white

Keybase proof

I hereby claim:

  • I am rcdilorenzo on github.
  • I am rcdilorenzo (https://keybase.io/rcdilorenzo) on keybase.
  • I have a public key ASABBZcTLyE8g_vbKklI8aSC1LTqFlK-KHgIaZuKIcm39Qo

To claim this, I am signing this object:

@rcdilorenzo
rcdilorenzo / MyControllerOrView.m
Created May 2, 2017 21:45
How to display dynamic length strings in a scrollable popover on iOS with perfect padding 👌🏻🥇
// Requires a property like the following
// @property (nonatomic, strong) UIPopoverController *textPopover;
- (void)displayPopoverForText:(NSString *)text inView:(UIView *)view presentingRect:(CGRect)rect maxSize:(CGSize)maxSize {
UIViewController *controller = [UIViewController new];
UITextView *textView = [UITextView new];
textView.text = text;
textView.editable = NO;
textView.backgroundColor = [UIColor clearColor];
@rcdilorenzo
rcdilorenzo / main.md
Created November 28, 2016 12:04
TIL: Generic Protocol Limitations in Swift

TIL: Apparently, Swift does not support creating concrete protocols from generic ones since it uses associated types for more customizable generic protocol adaptation. This is in contrast to classes and structs. Here is an example of a generic struct from my situation:

fileprivate struct WindowScopeUpdate<State> {
    let update: (State) -> (State)
}

An example usage would be like this (where TaskListWindowState is a concrete type such as a class, struct, or non-generic protocol):

@rcdilorenzo
rcdilorenzo / NSArrayDiff.h
Created August 26, 2016 15:25
A class to diff between two types of arrays (take a look at the test to see how it works)
#import <Foundation/Foundation.h>
typedef BOOL(^NSArrayDiffMatch)(id _Nonnull original, id _Nonnull comparedTo);
@interface NSArrayDiff : NSObject
+ (instancetype _Nonnull)newWithOriginal:(NSArray * _Nonnull)original
diffedAgainst:(NSArray * _Nonnull)compareTo
match:(NSArrayDiffMatch _Nonnull)match;
@rcdilorenzo
rcdilorenzo / calculator.erl
Created March 30, 2016 21:58
A dead simple erlang module for calculating the sum of the first N numbers or factorial of N
-module(calculator).
-export([sum/1, sum/2, factorial/1, factorial/2]).
sum(N) when N > 0 ->
sum(N, 0).
sum(N, Current) when N > 0 ->
sum(N-1, Current+N);
sum(0, Current) ->
@rcdilorenzo
rcdilorenzo / duration.ex
Created February 20, 2016 01:20
A simple construction of a duration time (e.g. "01:30" or "01:30:23") as a custom ecto type
defmodule Duration do
@moduledoc """
This duration module parses and formats strings
for a time duration in hours and minutes and
optionally seconds (e.g. 01:00 for an hour,
00:01:10 for one minute and ten seconds).
"""
@match ~r/^(?<hour>\d{1,2}):(?<min>\d{1,2}):?(?<sec>\d{0,2})$/
def parse(string) do
@rcdilorenzo
rcdilorenzo / LoopExample.asm
Last active August 7, 2021 18:51
Creating a MASM loop with the condition either above or below the block to execute (e.g. a while vs do..while loop in C)
; Description:
; This program demonstrates how to
; create a while-style loop with the
; condition either above or below
; the block of code to execute.
; Author: Christian Di Lorenzo
INCLUDE Irvine32.inc
@rcdilorenzo
rcdilorenzo / install-elixir.yml
Created November 30, 2015 02:33
An ansible playbook script to install elixir on a raspberry pi running Raspbian Wheezy
---
- hosts: all
remote_user: pi
tasks:
- name: check if erlang installed
shell: which erl
register: erl_check
ignore_errors: true
- apt_repository: repo='deb http://packages.erlang-solutions.com/debian wheezy contrib' state=present