Skip to content

Instantly share code, notes, and snippets.

anonymous
anonymous / Trie.swift
Created June 7, 2014 07:23
//
// Trie.swift
// SceneTest
//
// Created by Greg Titus on 6/7/14.
// Copyright (c) 2014 The Omni Group. All rights reserved.
//
// This is essentially the same data structure as OFTrie in OmniFoundation, except that the OmniFoundation version is mutable and ephemeral,
// and this version is immutable and persistent. Every time you add a string to the trie, it replaces all the nodes along the string's path
@tomashanacek
tomashanacek / Fit artboard to selection.sketchplugin
Last active August 29, 2015 14:03
Fit artboard to selection
var currentArtboard = [[[doc currentPage] artboards] firstObject];
var layers = selection;
var bounds = getBoundsForLayers(layers);
for (var i = 0, len = [layers count]; i < len; ++i) {
var layer = [layers objectAtIndex:i];
// Ref: http://iaroslavski.narod.ru/quicksort/DualPivotQuicksort.pdf
template<typename T>
void DualPivotQuickSort(T *lo, T *hi, const std::function<int32_t(const T &, const T&)> &cmp)
{
auto *const hiMinus1 = hi - 1;
if (hi - lo < 3)
{
if (hi != lo && cmp(*lo, *hiMinus1) > 0)
{
// A simple LUT backed index for faster binary search, with LUT partition encoding
// A bloom filter can be attached to it, for when you have many, many values - though in practice
// it is rarely needed, especially if the bits(resolution) is over 16
//
// You need (1 << bits) * sizeof(T::key) for the lut, e.g if T::key is uint32_t, for a 16bits LUT, that's
// 262k. Increasing resolution results in higher lookup efficiency, reducing it results in lower memory requirements
template<typename T>
static __attribute__((always_inline)) constexpr T MSB(const T n, const uint8_t span)
{
static inline uint8_t RHeight(void)
{
// Assuming probability 1/2 of an element appearing in layer i also appearing in layer i + 1
// We can do the usual toss-the-coin dance, or we can just use RNG once and count the trailing zeros.
// Instead of using a loop to count, we can isolate the rightmost 0-bit, turn off all bits and sets that bit to 1, and then
// just compute count of trailing zeros instead.
const auto r = rand();
const auto v = ~r & (r + 1);
const uint8_t tz = __builtin_ctz(v);
var s = context.selection
var v = context.document.currentView()
var r = v.totalRectForLayers(s)
var artboard = [[MSArtboardGroup alloc] initWithFrame:r];
var page = context.document.currentPage();
[page addLayers:[artboard]];
[artboard setGrid:[page grid]];
@bendc
bendc / functional-inheritance.js
Last active July 9, 2016 16:03
Functional inheritance
function car() {
return {
start: function() {
console.log("Engine on.")
},
accelerate: function() {
console.log("Let's go!")
}
}
}
/*
Copyright 2011 Martin Hawksey
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@gonzalo123
gonzalo123 / gist:868939
Created March 14, 2011 09:31
push existing repository to github
cd existing_git_repo
git remote add origin git@github.com:[user]/[reponame].git
git push -u origin master
@bomberstudios
bomberstudios / svgo-sketch.sh
Created April 16, 2015 14:07
SVGo options to clean up Sketch's SVG files without destroying them
svgo --pretty --enable=removeTitle --enable=removeDesc --enable=removeDoctype --enable=removeEmptyAttrs --enable=removeUnknownsAndDefaults --enable=removeUnusedNS --enable=removeEditorsNSData -f folder_with_svg_files