Skip to content

Instantly share code, notes, and snippets.

View nonsensery's full-sized avatar

Alex Johnson nonsensery

View GitHub Profile
@nonsensery
nonsensery / example.swift
Created January 9, 2017 20:08
Swift-Objc try/catch bridge
objc_try_catch({
let exception = NSException(name: "Something went wrong", reason: "not sure", userInfo: [:])
print("raising NSException: \(exception)...")
exception.raise()
}) { exception in
print("... caught NSException: \(exception)")
}
@nonsensery
nonsensery / bigHeads.js
Last active January 15, 2016 23:51
Big Heads for Hangouts
'use strict'
window.bigHeads = window.bigHeads || (function(window, document){
var edgePadding = 10
function makeRect(top, right, bottom, left) {
return { top, right, bottom, left, width: (right - left), height: (bottom - top) }
}
function ftosMaxChars(f, maxChars) {
@nonsensery
nonsensery / Better group hangouts.js
Created January 15, 2016 18:56
Better group hangouts
/*
Sometimes in a group hangout, it's nicer to see everyone all the time,
rather than just the person who is currently "speaking".
The solution is to click on your own thumbnail (so that you are always
the "speaker"), and then zoom and pan the page content so that the
thumbnails fill the whole width of the window. This can be done pretty
easily by applying `translate` and `scale` `transform`s to the body
element.
var bigInt = require('big-integer');
/**
* @class Grains
*
* Computes the number of grains on the squares of a
* chess board, starting with one grain on the first
* square, and doubling with each successive square.
*/
function Grains() {
@nonsensery
nonsensery / 01 Post.jsx
Created April 7, 2015 20:09
React Component Experiments
class Post extends React.Component {
render() {
return (
<article>
<h2>{this.props.title}</h2>
<section>{this.props.children}</section>
</article>
);
}
}
@nonsensery
nonsensery / keybase.md
Created August 20, 2014 18:02
keybase.md

Keybase proof

I hereby claim:

  • I am nonsensery on github.
  • I am nonsensery (https://keybase.io/nonsensery) on keybase.
  • I have a public key whose fingerprint is 6A2B FAF8 5423 68A8 3CCE C636 4700 6A0A 0843 3A5D

To claim this, I am signing this object:

@nonsensery
nonsensery / singleton records.md
Last active August 29, 2015 13:56
Creating singleton records

Here's a pattern I've used for creating unique "singleton" records.

Given a desired tag name, name, and managed object context, context,

  1. Using context, fetch all Tag objects with the desired name, ordered ascending by primary key.
  2. If there is more than one result, return the first one. You're done.
  3. Otherwise, create a new, temporary, (peer) context, tempContext.
  4. Using the temporary context,
  5. Create and insert a new Tag with the desired name, newTag, and save changes.
  6. Fetch all Tag objects with the desired name, ordered ascending by primary key (just like step 1, but using tempContext).
@nonsensery
nonsensery / client-server-sync.md
Last active August 29, 2015 13:56
SVN-like sync

Here's one way that a sync system could support signing in-to and out-of different server-side sync accouts.

Initial sign-in

I'm going to consider every note on every device to be unique, initially, since the only way to have duplicate notes would be to have manually copied them between devices.

Since each local note is unique at this point, signing in to a sync account for the first time just adds all of the local notes to that sync account, and records the unique id assigned by the server (keeping the local unique id as well). The sync account "owns" these notes now, and they will appear on any device that signs in to that account.

Other notes from the sync account are downloaded to the device. Each of these gets a local unique id, just like it had been created on the device (and it keeps the server-assigned id).

@nonsensery
nonsensery / page1.md
Created February 15, 2014 19:35
Splitting model objects into several entities

Some thoughts on this blog post by Brent Simmons

From the original:

A VSNote has more than a dozen properties. But the timeline needs only a few of those, and there would be performance and memory-use gains by using a smaller object. … In Core Data I could create two entities: VSTimelineNote and VSExtendedNote. VSTimelineNote would have a to-one relationship to VSExtendedNote. … [But that] means the data isn’t stored using the most natural representation. The data model would be based on the needs of the UI, which is not a good idea.

Putting aside Core Data for a moment, at issue is that each VSNote contains 8 or 10 attributes that are not needed to display the master list of notes; they are only needed to display the detail view for a note. Ideally, when displaying the list, we could load just the attributes used in the list into memory, and then load the rest when displaying the detail view. But realistically, a few bytes for a timestamp here