Skip to content

Instantly share code, notes, and snippets.

@IanKeen
IanKeen / Example_Complex.swift
Last active January 23, 2024 07:53
PropertyWrapper: @transaction binding for SwiftUI to make changes to data supporting commit/rollback
struct User: Equatable {
var firstName: String
var lastName: String
}
@main
struct MyApp: App {
@State var value = User(firstName: "", lastName: "")
@State var showEdit = false
@connorjclark
connorjclark / memory-test.ts
Created May 27, 2020 18:48
memory leak test
import { ChildProcess, spawn } from 'child_process';
import * as puppeteer from 'puppeteer';
const DEBUG = Boolean(process.env.DEBUG);
const CI = Boolean(process.env.CI);
const QUERY = Boolean(process.env.QUERY);
jest.setTimeout((QUERY ? 200 : 100) * 1000);
interface MemorySample {
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active April 26, 2024 10:15
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

@q42jaap
q42jaap / express-async.js
Created April 6, 2017 14:51
A way to allow async await style middleware
import Layer from 'express/lib/router/layer';
const Promise = global.Promise;
/**
* "fixt" express mbt promises. Als een stukje middleware een promise returnt dan moeten errors eigenlijk aan next worden gegeven.
*
* We hadden ook de suffix `Async` kunnen gebruiken om naast de bestaande functies nieuwe te maken. Dat heeft een flink nadeel
* omdat de api op verschillende manieren te benaderen is.
*/
@dgraham
dgraham / copy-to-clipboard.js
Last active March 21, 2019 02:17
Copy attribute value, form input, or element text to the clipboard.
(function() {
function createNode(text) {
var node = document.createElement('pre');
node.style.width = '1px';
node.style.height = '1px';
node.style.position = 'fixed';
node.style.top = '5px';
node.textContent = text;
return node;
}
@alangpierce
alangpierce / BigBingo
Last active May 26, 2022 02:05
BigBingo (as of early July 2014)
Snapshot of Khan Academy's BigBingo A/B testing framework and related code.
Here's a basic overview:
-summarize.py is the most interesting file. It contains all stages of the
summarize task, as well as the publish and archive steps that happen at the
end.
-bq_pipelines.py contains lots of useful pipelines for interacting with
BigQuery. QueryToTableBatchPipeline can run many simultaneous queries, and will
properly handle all batching and retry logic.
-config.py is where all experiment configuraiton lives. For this Gist, I
@traviskaufman
traviskaufman / jasmine-this-vars.md
Last active September 19, 2022 14:35
Better Jasmine Tests With `this`

Better Jasmine Tests With this

On the Refinery29 Mobile Web Team, codenamed "Bicycle", all of our unit tests are written using Jasmine, an awesome BDD library written by Pivotal Labs. We recently switched how we set up data for tests from declaring and assigning to closures, to assigning properties to each test case's this object, and we've seen some awesome benefits from doing such.

The old way

Up until recently, a typical unit test for us looked something like this:

describe('views.Card', function() {
@jkottke
jkottke / gist:8739051
Last active May 7, 2020 10:52
A list of design/writing/coding music recommendations from my Twitter followers
Not sure how to summarize/organize this into something useful. Some can be made into Spotify/Rdio playlists, but others are likely unavailable and some are just URLs to other services. Genre is all over the place as well...lots of ambient and classical, soundtracks, uptempo dancey stuff, rock w/ words, and even Slayer. Not sure all that can be put into one playlist that's useful for anyone. What I'm saying is, good luck!
fantoraygun ‏@fantoraygun 1h
@jkottke some great mixes here: http://musicforprogramming.net/
Andrew ‏@jandrewc 1h
@jkottke "From here we go sublime" by The Field and "Alive 2007" by Daft Punk.
Lenny ‏@lenny_ 1h
@jkottke SomaFM's Groove Salad station
/**
Provides the ability to verify key paths at compile time.
If "keyPath" does not exist, a compile-time error will be generated.
Example:
// Verifies "isFinished" exists on "operation".
NSString *key = SQKeyPath(operation, isFinished);
// Verifies "isFinished" exists on self.