Skip to content

Instantly share code, notes, and snippets.

View collindonnell's full-sized avatar

Collin Donnell collindonnell

View GitHub Profile
@collindonnell
collindonnell / Lint With Rubocop.sh
Created August 16, 2023 22:09
Lint With Rubocop for BBEdit
#!/usr/bin/env zsh
rubocop --format emacs $BB_DOC_PATH | sed 's/W:/warning:/g' | sed 's/C:/note:/g' | sed 's/F:/error:/g' | bbresults -p gcc
@collindonnell
collindonnell / multichat.rb
Created July 15, 2023 02:42
Simple Ruby TCP multi-user chat room
#!/usr/bin/env ruby
# frozen_string_literal: true
require "socket"
class Connection
def initialize(client:, server:)
@client = client
@server = server
end
@collindonnell
collindonnell / speak.c
Created October 20, 2022 06:51
Simple command line tool in C which uses getopt_long
#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
static struct config {
bool yell;
} cfg;
@collindonnell
collindonnell / async-demo.rb
Created April 8, 2022 21:47
Ruby Async Demo
#!/usr/bin/env ruby
require "async"
# Simple method to measure how long an operation takes.
def measure_time
start = Time.now
yield
puts "Duration: #{Time.now - start}"
end
@collindonnell
collindonnell / Coding Rules for Swift Apps.md
Created July 30, 2021 18:15
General guidelines for Swift apps.

Coding Rules for Swift Apps

  • Keep classes and similar below 100 lines.
  • Keep methods below ten lines, preferably five.
  • Don't check state variables or type to determine behavior (make a new type).
  • Make data sources their own type.
  • View controllers should subscribe to no more than two delegate protocols.
  • Classes manage their own behavior.
@collindonnell
collindonnell / Coding Rules for Swift Apps.md
Created July 30, 2021 18:10
Some general guidelines I came up.

Coding Rules for Swift Apps

  • Keep classes and similar below 100 lines.
  • Keep methods below ten lines, preferably five.
  • Don't check state variables or type to determine behavior over making a type.
  • Make data sources their own type.
  • View controllers should subscribe to no more than two delegate protocols.
  • Make classes manage their own behavior.
@collindonnell
collindonnell / hey_world_posts.rb
Last active May 4, 2021 20:52
Hey World Posts Counter
#!/usr/bin/env ruby
require 'rss'
require 'open-uri'
class Blog
def initialize(name)
@name = name
end
#define bitread(value, bit) (((value) >> (bit)) & 0x01)
#define bitset(value, bit) ((value) |= (1UL << (bit)))
#define bitclear(value, bit) ((value) &= ~(1UL << (bit)))
#define bitwrite(value, bit, bitvalue) (bitvalue ? bitset(value, bit) : bitclear(value, bit))
@collindonnell
collindonnell / DeselectCurrentRowAnimated.swift
Last active August 29, 2015 14:25
UITableView Extension to Deselect Currently Selected Row
import UIKit
public extension UITableView {
public func deselectSelectedRowAnimated(animated: Bool) {
if let indexPath = indexPathForSelectedRow() {
deselectRowAtIndexPath(indexPath, animated: animated)
}
}
@collindonnell
collindonnell / DeleteManagedObjectsExtension.swift
Last active December 4, 2020 23:38
NSManagedObjectContext extension methods to delete all managed objects, or all objects of a given type in the context.
//
// Created by Collin Donnell on 7/22/15.
// Copyright (c) 2015 Collin Donnell. All rights reserved.
//
import CoreData
extension NSManagedObjectContext {
convenience init(parentContext parent: NSManagedObjectContext, concurrencyType: NSManagedObjectContextConcurrencyType) {