Skip to content

Instantly share code, notes, and snippets.

@chriseidhof
chriseidhof / boilerplate.swift
Last active January 3, 2024 05:54
QuickMacApp
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI
NSApplication.shared.run {
VStack {
Text("Hello, World")
.padding()
.background(Capsule().fill(Color.blue))
@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

@rettuce
rettuce / Sketch_GoogleCloudVision
Created January 13, 2016 11:54
GoogleCloudVision Sketch for openFrameworks.
#include "ofMain.h"
#include "ofxJSON.h"
#include "ofxHttpUtils.h"
struct GData{
public:
string description;
float score;
};
@yuhua-chen
yuhua-chen / Drag-and-drop-uitableviewcell-swift2.swift
Created August 6, 2015 09:12
Demo the drag and drop UITableViewCell in Swift 2.
struct Drag {
static var placeholderView: UIView!
static var sourceIndexPath: NSIndexPath!
}
func handleLongPress(gesture: UILongPressGestureRecognizer) {
let point = gesture.locationInView(tableView)
let indexPath = tableView.indexPathForRowAtPoint(point)
switch gesture.state {
@transat
transat / .bashrc
Last active June 24, 2021 13:30
Nice Git-friendly bash prompt with Monokai colours and different output for command and output. READ the included instructions if you want this to look as it should!
# WEDISAGREE terminal prompt. By Clem.
# Change the 16 colours of your default terminal palette to the following Monokai-inspired colours. Do this in your terminal's profile preferences.
# 1st 8 colours: #1D1F21, #F92672, #A6E22E, #FD971F, #1E90FF, #9458FF, #66D9EF, #EDD400
# Next 8 colours: #B294BB, #CC6666, #F92672, #DE935F, #1E90FF, #74B933, #4277AD, #FFFFFF
# Make sure your background colour is the same as the first colour of your palette: #1D1F21
# And set your text colour to #B694D3 and your bold colour to #DA6234
@brandonb927
brandonb927 / osx-for-hackers.sh
Last active May 2, 2024 03:13
OSX for Hackers: Yosemite/El Capitan Edition. This script tries not to be *too* opinionated and any major changes to your system require a prompt. You've been warned.
#!/bin/sh
###
# SOME COMMANDS WILL NOT WORK ON macOS (Sierra or newer)
# For Sierra or newer, see https://github.com/mathiasbynens/dotfiles/blob/master/.macos
###
# Alot of these configs have been taken from the various places
# on the web, most from here
# https://github.com/mathiasbynens/dotfiles/blob/5b3c8418ed42d93af2e647dc9d122f25cc034871/.osx