Skip to content

Instantly share code, notes, and snippets.

View DivineDominion's full-sized avatar

Christian Tietze DivineDominion

View GitHub Profile
@darrensapalo
darrensapalo / rxswift3networkcalltoobject
Last active July 8, 2019 15:20
Swift 3 example of a network request wrapped as an RxSwift Observable and converted into a class object
import Foundation
import RxSwift
let networkQueue = DispatchQueue(label: "com.appName.networkQueue")
class Queue {
var name: String
public init (_ name: String) {
self.name = name
// I have some testing framework in the scope
// Questions below:
// 1. Should the description be like it is here, in first `it`, or with `only` word added:
// "should return Fizz when the number is divisible only by 3"
// That would imply that the number is divisible by 3 only, which is technically not true, as it is divisible
// by 1 as well, and some numbers, e.g. 6, 9, and so on, are divisible by themselves.
it('should return Fizz when the number is divisible by 3', () => {
// 2. Is that name enough, having `any` in it, to be complete in what numbers are producing `fizz`.
// There is also a matter of adding `only` (similar to case #1) having `anyNumberDivisibleOnlyBy3`.
@DivineDominion
DivineDominion / execute.rb
Last active October 29, 2019 08:23
Extract note links from a source note
#!/usr/bin/env ruby
# Avoid all the script configuration and use this convenience script instead!
#
# 1) Put it into the same folder,
# 2) run the script: `ruby _execute.rb PATH/TO/THE_NOTE.txt`
##################
# Configure here #
@JohnAtl
JohnAtl / insert_filename_as_header.rb
Created February 7, 2020 20:25
Code to help with note-link-janitor
#!/usr/bin/ruby
#
# Inserts the file's name as the first header in the file, if it isn't already there.
# Assumes filename begins with a 14 digit zettelkasten ID.
# Original file saved as filename.bak.
#
# As always, caveat emptor. This code could harm your files, so try it on a backup.
#
Dir.glob('*.md') do |filename|
puts "working on: #{filename}"
@pilky
pilky / SourceListTableCellView.swift
Created July 6, 2020 19:06
A source list cell that correct colours the label text of a drag image when selected
class SourceListTableCellView: NSTableCellView {
override var draggingImageComponents: [NSDraggingImageComponent] {
let components = super.draggingImageComponents
guard
self.backgroundStyle == .emphasized, //emphasized = selected
let textField = self.textField,
let newStyle = textField.attributedStringValue.mutableCopy() as? NSMutableAttributedString,
let labelIndex = components.firstIndex(where: { $0.key == .label })
else {
return components
@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
@saf-dmitry
saf-dmitry / apa-reference.txt
Created December 9, 2020 15:43
APA-style reference template for BibDesk
<$publications>
<$pubType=article?>
<$authors.name.@componentsJoinedByCommaAndAnd/>. <$fields.Title.stringByConvertingHyphensToDashes/>. <$fields.Journal.stringByRemovingTeX/>, <$fields.Volume.stringByConvertingHyphensToDashes/><$fields.Number.stringByConvertingHyphensToDashes.parenthesizedStringIfNotEmpty/><$fields.Pages?><$fields.Volume?>:<?$fields.Volume?><$fields.Number?>:<?$fields.Number?>page </$fields.Number?></$fields.Volume?><$fields.Pages.stringByConvertingHyphensToDashes/>, <?$fields.Pages?><$fields.Volume?>, <?$fields.Volume?><$fields.Number?>, </$fields.Number?></$fields.Pages?><$fields.Month.stringByConvertingHyphensToDashes.stringByAppendingSpaceIfNotEmpty/><$fields.Year/><$fields.Note.stringByPrependingFullStopAndSpace/>.
<?$pubType=book?>
<$authors?><$authors.name.@componentsJoinedByCommaAndAnd/><?$authors?><$editors.name.@componentsJoinedByCommaAndAnd/>, <$editors.@count=0?><?$editors.@count=1?>editor<?$editors.@count?>editors</$editors.@count?></$authors?>. <$fields.Title.stringByConvertin
@preble
preble / NSTextStorageSubclass.swift
Created February 9, 2016 04:45
Base subclass of NSTextStorage in Swift
import Cocoa
@objc
class SomeTextStorage: NSTextStorage {
private var storage: NSMutableAttributedString
override init() {
storage = NSMutableAttributedString(string: "", attributes: nil)
super.init()
@ieure
ieure / tiling
Created March 17, 2009 16:52
Code to handle centering and tiling of Emacs frames
;; Functions to work with frames
(provide 'ime-frame)
(defun screen-usable-height (&optional display)
"Return the usable height of the display.
Some window-systems have portions of the screen which Emacs
cannot address. This function should return the height of the
screen, minus anything which is not usable."
@DmitryBespalov
DmitryBespalov / EmbedFrameworksScript.sh
Last active June 11, 2021 21:10
Embed frameworks script
#!/bin/sh
set -e
# set your Frameworks path here
FRAMEWORKS_DIR="${SRCROOT}/../Frameworks/${PLATFORM_NAME}"
echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"