Skip to content

Instantly share code, notes, and snippets.

@albertbori
albertbori / README.md
Last active November 9, 2015 20:59
LINQ GroupByDate Reporting Extension

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
@albertbori
albertbori / LocalNotifications.swift
Last active July 13, 2018 23:43
NotificationCenter alternative using delegates (fully 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 / Array+Diff.swift
Last active August 9, 2018 10:13
An extension for Swift Array that returns the difference between two arrays
//: 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 July 13, 2018 23:55
NotificationCenter alternative using enums and delegates (fully 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 / StackCollectionView.swift
Last active August 9, 2018 10:14
An example of a UICollectionView-like view made from UIStackViews for easy layout of small grids
//
// StackCollectionView.swift
//
// Created by Albert Bori on 6/23/17.
//
import UIKit
@IBDesignable
class StackCollectionView: UIView {
@albertbori
albertbori / HideableUIView.swift
Last active August 9, 2018 10:14
iOS Swift Extension for easily hiding/showing UIViews constrained using Auto Layout
//
// 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.
//
//
// StandardTooltip.swift
//
// Created by Albert Bori on 11/20/17.
//
import Foundation
@objc
class StandardTooltip: NSObject {
@albertbori
albertbori / PlaceholderTextView.swift
Last active January 13, 2020 09:25
UITextView support for Placeholder text
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 {
import UIKit
import MBProgressHUD
class ImageViewController: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var scrollView: UIScrollView!
var imageURL: String?
private var imageView: UIImageView!
@albertbori
albertbori / ExampleA.swift
Last active December 16, 2022 19:37
Swift Property Wrapper Implicit Initialization Scenarios
/*
This example shows how a simple property wrapper can be declared and initialized.
*/
@propertyWrapper
struct ExampleA<Value> {
private var value: Value
var wrappedValue: Value {
get { value }