Skip to content

Instantly share code, notes, and snippets.

View DivineDominion's full-sized avatar

Christian Tietze DivineDominion

View GitHub Profile
@kristopherjohnson
kristopherjohnson / DataStore.swift
Created September 28, 2014 14:51
Swift: Core Data persistence stack
import Foundation
import CoreData
// "Class variables" used in DataStore.sharedDataStore()
private var _instance: DataStore?
private var DataStoreClassLock = NSRecursiveLock()
private let appStoreFilename = "DataStore.sqlite"
private let testStoreFilename = "test_DataStore.sqlite"
@corny
corny / dynv6.sh
Last active April 10, 2024 07:42
Update script for dynv6.com to set your IPv4 address and IPv6 prefix
#!/bin/sh -e
hostname=$1
device=$2
file=$HOME/.dynv6.addr6
[ -e $file ] && old=`cat $file`
if [ -z "$hostname" -o -z "$token" ]; then
echo "Usage: token=<your-authentication-token> [netmask=64] $0 your-name.dynv6.net [device]"
exit 1
fi
@natecook1000
natecook1000 / NSScanner+Swift.swift
Created March 3, 2015 20:13
Swift-friendly NSScanner methods
// NSScanner+Swift.swift
// A set of Swift-idiomatic methods for NSScanner
//
// (c) 2015 Nate Cook, licensed under the MIT license
import Foundation
extension NSScanner {
// MARK: Strings
@phatmann
phatmann / ImageAttachment
Created March 22, 2015 22:23
NSTextAttachment that scales and aligns image
// Created by Tony Mann on 3/22/15.
// Copyright (c) 2015 7Actions. All rights reserved.
//
// Adapted from http://ossh.com.au/design-and-technology/software-development/implementing-rich-text-with-images-on-os-x-and-ios/
import UIKit
class ImageAttachment: NSTextAttachment {
var verticalOffset: CGFloat = 0.0
@Skalman
Skalman / index.php
Created April 20, 2015 23:48
Dynamic RSS feeds from Youtube links
<?php
if (!isset($_GET['url'])) {
?>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Youtube RSS creator</title>
<form>
<p>Create an RSS feed for the videos on the following page:
<p><input name="url" placeholder="E.g. https://www.youtube.com/user/scishow/videos" style="width: 30em">
@robb
robb / Example.m
Last active January 9, 2024 14:38
A macro to convert nullable references to nonnull references while triggering an assert if the expression is actually true. Think of this as unsafe unwrap for Objective-C.
NS_ASSUME_NONNULL_BEGIN
void Log(NSString *foo) {
NSLog(@"%@", foo);
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSDictionary *stuff = @{
@"a": @"Test"
# pragma mark Custom caret
- (void)drawInsertionPointInRect:(NSRect)aRect color:(NSColor *)aColor turnedOn:(BOOL)flag {
aRect.size.width = self.caretWidth;
[super drawInsertionPointInRect:aRect color:aColor turnedOn:flag];
}
// This is a hack to get the caret drawing to work. I know, I know.
- (void)setNeedsDisplayInRect:(NSRect)invalidRect {
invalidRect.size.width += self.caretWidth - 1;
@prasadsilva
prasadsilva / fresh-chrome-with-custom-tz.sh
Last active June 4, 2023 12:54 — forked from stuartsierra/fresh-chrome.sh
Launch new instances of Google Chrome on OS X with isolated cache, cookies, user config and custom Timezone
#!/usr/bin/env bash
# fresh-chrome
#
# Use this script on OS X to launch a new instance of Google Chrome
# with its own empty cache, cookies, and user configuration.
#
# The first time you run this script, it will launch a new Google
# Chrome instance with a permanent user-data directory, which you can
# customize below. Perform any initial setup you want to keep on every
@rnapier
rnapier / helper.swift
Last active February 3, 2018 23:00
Helper functions
import Foundation
/// This is going to be one of those things that for many of you is so obvious that it doesn't
/// require saying. But maybe a few of you have never really done this before either. I've been
/// thinking about nested helper functions.
/// I've used little nested helper functions lots of times. I do this when I want a function, but
/// nothing outside of this scope would ever need it.
func doSomething() {
func inc(x: Int) -> Int { return x + 1 }
@preble
preble / Completion.swift
Created January 20, 2016 23:32
A cancellable completion for Swift.
final class Completion<R> {
private let closure: (R) -> Void
private var cancelled = false
/// `closure` is called upon completion, if not cancelled.
init(closure: (R) -> Void) {
self.closure = closure
}