Skip to content

Instantly share code, notes, and snippets.

@rsms
rsms / sleeping-barber.m
Created November 10, 2010 19:04
Sleeping barber with GCD (Grand Central Dispatch)
int main (int argc, const char * argv[]) {
dispatch_queue_t waitingChairs = dispatch_queue_create("waitingChairs", 0);
dispatch_queue_t barber = dispatch_queue_create("barber", 0);
dispatch_semaphore_t semaphore = dispatch_semaphore_create(3);
NSInteger ident = 0;
while (++ident) {
if (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW) != 0) {
printf("Customer %d turned away\n", ident);
continue;
}
@rsms
rsms / KVOChangeScope.hh
Created November 25, 2010 01:24
Conveniently mark Key-Value Observable properties as edited in Objective-C++
/*
* KVOChangeScope -- Conveniently mark edits for Key-Value Observations in
* Objective-C++ in custom setters.
*
* Example:
*
* - (void)setFoo:(id)value {
* kvo_scoped_change(foo);
* // your setter code here which might return at any moment
* }
@nakiwo
nakiwo / gist:3179598
Created July 26, 2012 00:46
Xcode4.4 iOS SDKで @yES,@no,array[...],dictionary[...]を使う
// Xcode4.4
// llvm4の機能のうち一部が、
// iOS 5.1 SDK で使えない
// 例
NSNumber *b = @YES; // error
NSArray *array = @[ @1, @2, @3 ];
NSNumber *n = array[1]; // error
@roxlu
roxlu / AudioConverterBrain.cpp
Created May 6, 2016 20:05
Example implementation of using the amazing b8brain audio samplerate converter, https://github.com/avaneev/r8brain-free-src This was used for a real time audio stream converter.
#include <poly/AudioConverterBrain.h>
#include <poly/AudioDataConverter.h>
namespace poly {
AudioConverterBrain::AudioConverterBrain()
:listener(NULL)
{
}
@aki-null
aki-null / gist:1497649
Created December 19, 2011 15:23
Core Text APIを使用した際に起こる行間の問題の回避
NSFont *normalFont = [NSFont systemFontOfSize:12];
CGRect renderFrame = CGRectMake(0, 0, 300, 50); // box to render the text into
static NSLayoutManager *layMan = nil;
if (!layMan) {
layMan = [NSLayoutManager new];
}
CGFloat lineHeight = [layMan defaultLineHeightForFont:normalFont]; // calculate the expected height of a line
NSDictionary *attrDict = [NSDictionary dictionaryWithObject:normalFont andKey:NSFontAttributeName];
@boctor
boctor / BaseViewController.m
Created May 5, 2011 02:08
A base view controller class that when running on the simulator in debug mode, will auto simulate a memory warning every time the view controller's viewDidAppear is called
//
// BaseViewController.m
//
// Created by Peter Boctor on 5/4/11.
//
// Copyright (c) 2011 Peter Boctor
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
@geddski
geddski / nesting.js
Created January 14, 2012 05:08
helper function for nesting backbone collections.
function nestCollection(model, attributeName, nestedCollection) {
//setup nested references
for (var i = 0; i < nestedCollection.length; i++) {
model.attributes[attributeName][i] = nestedCollection.at(i).attributes;
}
//create empty arrays if none
nestedCollection.bind('add', function (initiative) {
if (!model.get(attributeName)) {
model.attributes[attributeName] = [];
@poutyface
poutyface / gist:1223553
Created September 17, 2011 02:25
QEMU: 仮想ボード ARM Cortex-A9 マルチコアで Linux を動かす
モチベーション
---------------
Androidのエミュレータは中でQEMUを使ってる
中で使われているので、Android開発とは直接関係がないけど、
素のQEMUの使い方を知る。
* QEMUの使い方を覚える
* Linuxをエミュレータ環境で動かしてみる
* ARM のクロス環境に慣れてみる
@darkseed
darkseed / Reachability.h
Created August 30, 2011 23:16 — forked from dhoerl/Reachability.h
Reachability (iOS) ARCified
/*
File: Reachability.h
Abstract: Basic demonstration of how to use the SystemConfiguration Reachablity APIs.
Version: 2.2 - ARCified
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
("Apple") in consideration of your agreement to the following terms, and your
use, installation, modification or redistribution of this Apple software
@tily
tily / scaling_isomorphic_javascript_code.ja.markdown
Last active May 1, 2023 09:03
サバクラ両方で動く JavaScript の大規模開発を行うために

サバクラ両方で動く JavaScript の大規模開発を行うために

原文:Scaling Isomorphic Javascript Code (This is just for study, please contact me at tily05 atmark gmail.com if any problem.)

考えてみれば Model-View-Controller とか MVC ってよく聞くよね。実際どんなものか知ってる? 抽象的に言うなら「オブジェクト情報の保持されるグラフィック・システム (つまり、ラスターではないグラフィック。ゲームとか) 上に構築された、表示系を中心としたアプリケーションにおいて、主要な機能どうしの関わりをうまく分離すること」とでも言おうか。もう少し深く考えを押し進めてみれば、これは当然、他のさまざまなアプリケーションにもあてはまる言葉 (bucket term ?) だ。

過去に多くの開発コミュニティが MVC による解決案を提供し、それによってよくあるユースケースにうまく対処し、地位を築くことができた。例をあげるなら、Ruby や Python コミュニティは Rails や Django を作り、MVC アーキテクチャを実現した。