Skip to content

Instantly share code, notes, and snippets.

View dr2050's full-sized avatar

Dan Rosenstark dr2050

View GitHub Profile
@dr2050
dr2050 / WorkflowyPlusWithRollovers.js
Created September 13, 2016 18:15
Adds image rollovers to Workflowy. Include images using image prefix like image:https://www.dropbox.com/s/ycrkg2uc7gbi27i/Screenshot%202016-09-13%2014.01.52.png?raw=1
// ==UserScript==
// @name WorkflowyPlus with Rollovers
// @namespace http://confusionstudios.com
// @version 0.2
// @author DR2050
// @match https://workflowy.com/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js
// @require https://code.jquery.com/ui/1.12.0/jquery-ui.js
// @require https://mididesigner.com/lightbox/jquery.colorbox.js
// @grant none
@dr2050
dr2050 / git-backup
Last active October 11, 2016 14:41
put this in your path and run `git backup`
#!/usr/bin/env ruby
if __FILE__ == $0
bundle_name = ARGV[0] if (ARGV[0])
bundle_name = `pwd`.split('/').last.chomp if bundle_name.nil?
bundle_name += ".git.bundle"
puts "Backing up to bundle #{bundle_name} in ~/Dropbox/backup/git-repos"
homeDir = ENV['HOME'] #cannot use ~
`git bundle create '#{homeDir}/Dropbox/backup/git-repos/#{bundle_name}' --all`
end
@dr2050
dr2050 / DRTimer.swift
Last active May 9, 2018 05:33
A drop-in Swift replacement for NSTimer: faster and lighter weight using GCD
// DRTimer.swift
// ConfusionUtilFramework
//
// Created by dan on 5/4/17.
// Copyright © 2017 Confusion Studios LLC. All rights reserved.
//
import UIKit
// a faster timer than NSTimer, drop in replacement for
// just one of the methods... it's not precise but it works...
@dr2050
dr2050 / LockingWithSwiftAndGCD.swift
Created March 20, 2017 20:58
Locking Demo with GCD and Swift (Playground)
import Foundation
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
// CHANGE THIS TO TRUE FOR the lock queue to be used
let useLocks = false
var counter : Int = 0
@dr2050
dr2050 / BinarySearchTests.swift
Last active March 29, 2017 18:57
Binary Search in Swift (as a single-file Unit Test)
// BinarySearchTests.swift
// BinarySearchTests
//
// Created by Dan Rosenstark on 3/27/17.
// Copyright © 2017 Confusion Studios LLC. All rights reserved.
import XCTest
@testable import SwiftAlgos
class BinarySearchTests: XCTestCase {
@dr2050
dr2050 / NSObjectOverrides.swift
Created March 28, 2017 18:40
Overriding NS Method in Swift 3 (Playground Page)
//: [Previous](@previous)
// http://stackoverflow.com/questions/33696489/overriding-ns-methods-in-swift
import UIKit
var str = "Hello, playground"
//: [Next](@next)
extension NSObject {
func NSLocalizedString(key: String, comment: String) -> String {
return "yes we have localized an NSObject"
@dr2050
dr2050 / MergeIntervals.swift
Last active April 1, 2017 20:47
Ye Old Merge Intervals Question, Solved from Scratch (including non-sorted version)
// MergeOverlappingIntervals in Swift 3.1
// Created by Dan Rosenstark on 4/1/17.
// Copyright © 2017 Confusion Studios LLC. All rights reserved.
import XCTest
extension CountableClosedRange {
// returns the more inclusive range or nil if there's no union
func union(with range: CountableClosedRange) -> CountableClosedRange? {
if overlaps(range) {
import UIKit
// Copyright 2017 Dan Rosenstark dr2050.com
// See http://stackoverflow.com/a/28570282/8047, too
class GameLoop : NSObject {
var doSomething: () -> ()!
var displayLink : CADisplayLink!
init(doSomething: @escaping () -> ()) {
// FastTimer.swift
// ConfusionUtilFramework
//
// Created by Dan Rosenstark on 5/4/17.
// Copyright © 2017 Confusion Studios LLC. All rights reserved.
import UIKit
// a faster timer than NSTimer, drop in replacement for
// just one of the methods... it's not precise but it works...
@objc(FastTimer)
@dr2050
dr2050 / git-branch-pick
Last active March 6, 2019 17:01
Choose a Git Branch for any operation
#!/usr/bin/env ruby
#git-branch-pick by Dan Rosenstark
require 'io/console'
# can take a command, default is checkout
command = ARGV[0]
updateSubmodules = false
if !command
command = "checkout"
puts "Using git #{command}.\nYou can choose a different command, e.g., git branch-pick \"branch -D\""