Skip to content

Instantly share code, notes, and snippets.

@landonf
landonf / Unsigned.scala
Created January 5, 2015 21:37
Unboxed unsigned types (including direct unboxed Array[Int] representation)
import scala.language.implicitConversions
object Unsigned {
// No-boxing tag
private type Tagged[T] = { type Tag = T }
type Unsigned[T] = T with Tagged[UTag[T]]
sealed trait UTag[T]
@inline def apply[T] (u: T) : Unsigned[T] = u.asInstanceOf[Unsigned[T]]
#include <stdio.h>
#include <CommonCrypto/CommonKeyDerivation.h>
#include <CommonCrypto/CommonCryptor.h>
#include <assert.h>
#include <dispatch/dispatch.h>
int main (int argc, char *argv[]) {
uint64_t salt = 0;
dispatch_group_t group = dispatch_group_create();
import java.io.IOException
import java.nio.channels.FileChannel
import java.nio.file.{Path, Paths, StandardOpenOption}
import scodec.bits.BitVector
import shapeless.ops.hlist
import scalaz.{-\/, \/, \/-}
type AnalysisScore = Int
//type DataAnalysis[T] = (DataType, AnalysisScore)
@landonf
landonf / 1-asset-info-from-apple.txt
Last active August 1, 2016 21:25
Traffic log of Yosemite performing auto-save to iCloud (as discovered by https://datavibe.net/~sneak/20141023/wtf-icloud/). Unsaved documents are automatically uploaded to iCloud *before* the user has selected where they would like the document to be saved (interestingly, actual file contents are uploaded to S3).
POST /api/client/asset/retrieve/token HTTP/1.1
Host: p29-ckdatabase.icloud.com:443
X-Apple-Request-UUID: AA181E9B-0AD3-4D32-9496-49864F6013D1
Accept: application/x-protobuf
Content-Encoding: gzip
X-CloudKit-UserId: _06d9280ffcc33808080bf05f7c23cfd8
X-CloudKit-ContainerId: com.apple.clouddocs
X-CloudKit-ProtocolVersion: client=1;comments=1;device=1;presence=1;records=1;sharing=1;subscriptions=1;users=1;mescal=1;
X-MMe-Client-Info: <VMware7,1> <Mac OS X;10.10;14A389> <com.apple.cloudkit.CloudKitDaemon/259.2.3 (com.apple.cloudd/259.2.3)>
Accept-Encoding: gzip
@landonf
landonf / pretty_print0.json
Last active August 29, 2015 14:08
Dynamic configuration of Spotlight clients, refreshed by Spotlight semi-regularly. Since the query URLs are server-supplied, they can be modified to include a permanent identifier without triggering any visible client behavior.
"Pretty-printed body of:"
"https://github.com/fix-macosx/yosemite-phone-home/blob/d3da40373841fedbbb6f640a680feb18926a1d82/icloud-user-r0/System/Library/CoreServices/Spotlight.app/Contents/XPCServices/com.apple.metadata.SpotlightNetHelper.xpc/Contents/MacOS/com.apple.metadata.SpotlightNetHelper/20141019T073211Z-auser-%5B172.16.174.146%5D:49225-%5B17.249.89.250%5D:443.log"
{
"enabled": true,
"use_ledbelly": false,
"version": "Parsec2F",
"min_query_len": 1,
"max_cached_queries_len": 1024,
"max_cached_results_len": 8192,
"supported_geo_sources": [
@landonf
landonf / 0_data_prettyprint.json
Created October 19, 2014 23:00
In Yosemite, all Safari web searches are sent to not only the search engine you've selected (e.g., Google, DuckDuckGo), but *also* to Apple, even if you've disabled "Spotlight Suggestions" (System Preferences > Spotlight Suggestions, as per Apple's privacy documentation) and sharing of Usage and Diagnostics data. https://github.com/fix-macosx/yo…
[
{
"timestamp": 0,
"input": "W",
"type": "search_local",
"latency": 0
},
{
"local_results": [
"ddg_search",
@landonf
landonf / 0_completion_post.txt
Last active August 29, 2015 14:07
Data posted to Apple by Spotlight (Bulky JSON payloads have been reformatted for readability). Note the X-Apple-UserGuid -- this appears to remain constant across all requests.
POST /fb?key=andromeda HTTP/1.1
Host: api.smoot.apple.com
Content-Type: application/json
Accept-Charset: utf-8
Connection: keep-alive
X-Apple-ActionSignature: ArFF0Bupz4+n05DZ/5MjOYH6XbRrC98eRfE+8OzUT0wKAAABwAMAAAABAAABAO7FAuqnAwyvZFj4n1tcSQxl42hKlg/915t5zBgrff9a2axEBZXtPF2Tg0rdJIEJJ/r4sMinOShzj3lvY9LmX1ZS76JmJNM0WZLzpat3WBzTmsgwyWUGSwO1ZUCURtaYyd5GryXCOfKyC0EIy8g3ppLlRdg4NOfIH043t/x7dzXjSJnuFZxgjkNtXJjlZtpyhU/1aozZABRHLK6nnPu33ek59bQMDwtQGyPC/3+DBJeujZcVuZI6of22HaV2oVFLz3zXEfEAcfeL5WPLWinnmLN+RZIrONwRmy/64kYbrkDO3P00R96wW6LJBYe63d6vWCrXlWTQeL7DDtwaR29Q0lYAAAAQ7fKDT5fxlqnZiMWRl6sNlQAAAJ8BZJzusSpopU9YFrn8J9VG1D/Ve1QAAACGBQJ/jp+/zKfOoBgaJGgjxWW8VEHM8hOyIUG96CcnUgA2Aqfvvv9nzKjAU05WWJSzGq4jMw5xzBsDlj9oSpM9/8PEHAlDKz2v7hNR3TLlAkH/2GMJgF7ly7dnqPPG4fjEvoT7Pz/bEepVSsboPqm8ztaSvCYoC3xBbXEPPO5AjiH4jeDbKLI=
Accept: application/json
X-Apple-UserGuid: 267af341-df6c-4eed-5e78-a2b8a49a1d1f
User-Agent: (OS X 14A389) Spotlight/916
Content-Length: 5991
@landonf
landonf / TypeClassTag.scala
Created October 14, 2014 20:20
Automatic boxing and unboxing of an instance that conforms to a typeclass, and the typeclass itself.
object example {
import scala.language.higherKinds
object @@ {
case class TypeClassManifest[V, T[_]](value: V)(implicit val typeClass: T[V])
def apply[V, T[_]](instance: V)(implicit T: T[V]) = TypeClassManifest(instance)
implicit def typeClass[V, T[_]] (manifest: TypeClassManifest[V, T]): T[V] = manifest.typeClass
class TupleCodec<A, B> : Codec {
typealias CodecType = (A, B)
// What I'd really like to do here ...
typealias CodecA = Codec where CodecA.CodecType == A
typealias CodecB = Codec where CodecB.CodecType == B
let encA: CodecA
let encB: CodecB
@landonf
landonf / bind-protocol-types.swift
Last active March 28, 2018 08:14
An attempt to use the type inferencer to explicitly bind a protocol's typealias.
protocol TypeBinder {
typealias BoundT
}
class TypeEvidence<T> : TypeBinder {
typealias BoundT = T
func array () -> Array<BoundT> { return [] }
}
class ObserverTyper<T> {