Skip to content

Instantly share code, notes, and snippets.

@albertbori
albertbori / Array+Diff.swift
Last active Aug 9, 2018
An extension for Swift Array that returns the difference between two arrays
View Array+Diff.swift
//: Playground - noun: a place where people can play
extension Array where Element: Comparable {
/**
Compares array with passed array and returns the differences. Warning: Must be a set of data (no duplicate values)
- Parameter with: The new array to compare to the existing array
- Returns: A tuple with an array of added items and an array of removed items.
*/
func diff(with array: Array) -> (added: Array, removed: Array) {
let originalArray = self.sorted()
@albertbori
albertbori / LocalNotifications.swift
Created Jul 13, 2018
NotificationCenter alternative using enums and delegates (fully swift)
View LocalNotifications.swift
import Foundation
import PlaygroundSupport
//class that allows fully-swift weak reference storage for arrays/dictionaries
class Weak<T> {
private weak var _object: AnyObject?
var object: T? { return _object as? T }
init(object: T) {
_object = object as AnyObject
@albertbori
albertbori / LocalNotifications.swift
Last active Jul 13, 2018
NotificationCenter alternative using delegates (fully swift)
View LocalNotifications.swift
import Foundation
import PlaygroundSupport
//class that allows fully-swift weak reference storage for arrays/dictionaries
class Weak<T> {
private weak var _object: AnyObject?
var object: T? { return _object as? T }
init(object: T) {
_object = object as AnyObject
View StandardTooltip.swift
//
// StandardTooltip.swift
//
// Created by Albert Bori on 11/20/17.
//
import Foundation
@objc
class StandardTooltip: NSObject {
@albertbori
albertbori / StackCollectionView.swift
Last active Aug 9, 2018
An example of a UICollectionView-like view made from UIStackViews for easy layout of small grids
View StackCollectionView.swift
//
// StackCollectionView.swift
//
// Created by Albert Bori on 6/23/17.
//
import UIKit
@IBDesignable
class StackCollectionView: UIView {
@albertbori
albertbori / README.md
Last active Nov 9, 2015
LINQ GroupByDate Reporting Extension
View README.md

LINQ GroupByDate Reporting Extension

This IQueryable<T> extension saves a bit of time when writing a report that groups results by date. You can specify which timeframes to group by (day, week, month, year), or use the default automatic thresholds.

This method also accepts and corrects null dates based on the available results. It does this by performing a simple query to grab the starting date, if it's missing, before running the main report query.

Sample Usage

public class OrderCountRow: ReportingExtensions.ReportRow
View ImageViewController.swift
import UIKit
import MBProgressHUD
class ImageViewController: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var scrollView: UIScrollView!
var imageURL: String?
private var imageView: UIImageView!
@albertbori
albertbori / HideableUIView.swift
Last active Aug 9, 2018
iOS Swift Extension for easily hiding/showing UIViews constrained using Auto Layout
View HideableUIView.swift
//
// HideableUIView.swift
// Albert Bori
//
// Created by Albert Bori on 5/19/15.
// Copyright (c) 2015 Albert Bori under the MIT license.
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
@albertbori
albertbori / PlaceholderTextView.swift
Last active Jan 13, 2020
UITextView support for Placeholder text
View PlaceholderTextView.swift
import UIKit
import Foundation
@IBDesignable class PlaceholderTextView: UITextView, UITextViewDelegate
{
private let _placeholderColor: UIColor = UIColor(white: 0.78, alpha: 1)
private var _placeholderLabel: UILabel!
@IBInspectable var placeholder: String = "" {
didSet {
@albertbori
albertbori / MyDB.cs
Last active Apr 6, 2021
.NET EntityFramework Encryption Example (C#)
View MyDB.cs
public class MyDB : IdentityDbContext<User>
{
//DBSet properties go here
public MyDB()
{
((IObjectContextAdapter)this).ObjectContext.ObjectMaterialized += new ObjectMaterializedEventHandler(ObjectMaterialized);
}
#region Encryption