Skip to content

Instantly share code, notes, and snippets.

View 0x1306a94's full-sized avatar
😶
depressed

0x1306a94 0x1306a94

😶
depressed
  • 11:26 (UTC +08:00)
View GitHub Profile
0 = Success
1 = Operation not permitted
2 = No such file or directory
3 = No such process
4 = Interrupted system call
5 = Input/output error
6 = No such device or address
7 = Argument list too long
8 = Exec format error
@niw
niw / libpng_test.c
Last active November 18, 2024 00:15
How to read and write PNG file using libpng. Covers trivial method calls like png_set_filler.
/*
* A simple libpng example program
* http://zarb.org/~gc/html/libpng.html
*
* Modified by Yoshimasa Niwa to make it much simpler
* and support all defined color_type.
*
* To build, use the next instruction on OS X.
* $ brew install libpng
* $ clang -lz -lpng16 libpng_test.c
@kirsteins
kirsteins / Array -> UnsafeMutablePointer -> Array
Last active June 16, 2024 09:42
Array -> UnsafeMutablePointer -> Array
var initalArray = [1, 2, 3]
let pointer: UnsafeMutablePointer<Int> = UnsafeMutablePointer(initalArray)
let arrary = Array(UnsafeBufferPointer(start: pointer, count: initalArray.count))
@elbeno
elbeno / fix.cpp
Created May 16, 2015 21:58
Fixed-point (Y) combinator in C++
#include <functional>
#include <iostream>
using namespace std;
template <typename F>
struct Y
{
Y(F f) : m_f(f) {}
template <typename T>
import Foundation
extension Dictionary {
mutating public func setValue(val: AnyObject, forKeyPath keyPath: String) {
var keys = keyPath.componentsSeparatedByString(".")
guard let first = keys.first as? Key else { print("Unable to use string as key on type: \(Key.self)"); return }
keys.removeAtIndex(0)
if keys.isEmpty, let settable = val as? Value {
self[first] = settable
} else {
@wxdao
wxdao / open_utun.c
Last active April 13, 2024 18:39 — forked from bringhurst/gist:1693075
How to open utun device in OS X
#include <netinet/in.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/kern_control.h>
#include <net/if_utun.h>
#include <sys/ioctl.h>
#include <sys/kern_event.h>
int open_utun(int num) {
int err;
@endavid
endavid / FontAtlas.swift
Created May 27, 2017 18:03
Signed Distance Field in Metal/Swift
public class FontAtlas: NSObject, NSSecureCoding {
public static var supportsSecureCoding: Bool { get { return true } }
static let atlasSize: Int = 2048 // 4096 runs out of mem...
var glyphs : [GlyphDescriptor] = []
let parentFont: UIFont
var fontPointSize: CGFloat
let textureSize: Int
var textureData: [UInt8] = []
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active November 19, 2024 05:05
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

@kemchenj
kemchenj / CodeTextField.swift
Last active December 11, 2023 07:19
CodeTextField
import UIKit
class CodeTextField: UITextField, UITextFieldDelegate {
let codeLength: Int
var characterSize: CGSize
var characterSpacing: CGFloat
let textPreprocess: (String) -> String
let validCharacterSet: CharacterSet