Skip to content

Instantly share code, notes, and snippets.

@juri
juri / pairwise.swift
Created April 6, 2018 05:31
Pairwise sequence method for Swift
extension Sequence {
/// `[e1, e2, …, eN]` → `[(nil, e1), (e1, e2), …, (eN-1, eN), (eN, nil)]`
func pairwise() -> UnfoldSequence<(Self.Element?, Self.Element?), ((Self.Element?, Self.Element?)?, Bool)> {
var iter = self.makeIterator()
var next1: Element? = nil
var next2 = iter.next()
return Swift.sequence(first: (next1, next2)) { prevpair -> (Element?, Element?)? in
guard let nv2 = next2 else { return nil }
@juri
juri / separategems.md
Created October 14, 2015 08:17
Separate trees for CocoaPods or other executables installed with gem

Sandboxing gems

The problem: I need to install CocoaPods, but I don't want to litter my system with the various gems it requires.

I tried to use Homebrew Cask, but it broke with my setup where I have Homebrew installed in /opt/brew and no write access to /usr/local.

There's probably a solution that involves RVM or rbenv, but I couldn't don't know those tools and I couldn't find one that was neatly packaged and simply explained.

Keybase proof

I hereby claim:

  • I am juri on github.
  • I am juri (https://keybase.io/juri) on keybase.
  • I have a public key whose fingerprint is D57A 4A7B 4443 A556 1C14 E60D 27B6 AC5C 8198 13E3

To claim this, I am signing this object:

@juri
juri / gist:5677168
Created May 30, 2013 11:09
Parse a GPX file and add extra locations by interpolation. This allows you to slow down a simulated route in Xcode/iOS Simulator.
#!/usr/bin/python
# Interpolate GPX waypoints to slow a simulated route down.
import itertools
import sys
import xml.etree.ElementTree as ET
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
@juri
juri / balanced.el
Created February 4, 2010 17:31
A modified version of balanced.el that allows unbalanced parentheses
;; balanced.el
;;
;; Time-stamp: <2010-02-04 19:30:03 juri>
;; (update this with M-x time-stamp)
;; Provides a modifier to major modes such that ``parenthesis''-type
;; characters usually stay balanced. See the documentation-string for
;; ``balanced-on'' for details. After putting this file somewhere in
;; your load-path, A not-bad thing to do with this package is: