Skip to content

Instantly share code, notes, and snippets.

@zh-se
zh-se / SyncQueue.swift
Created January 24, 2020 08:41
swift synchronized queue
final class SyncQueue<T> {
func push(_ item: T) {
syncQueue.sync {
self.data.append(item)
}
}
func pop() -> T? {
var result: T? = nil
syncQueue.sync {
if data.isNotEmpty {
@zh-se
zh-se / ViewController.swift
Created December 4, 2019 11:25 — forked from bricklife/ViewController.swift
UIPanGestureRecognizer on UIScrollView
//
// ViewController.swift
// PanOnScroll
//
// Created by Shinichiro Oba on 2018/03/08.
// Copyright © 2018 bricklife.com. All rights reserved.
//
import UIKit
@zh-se
zh-se / iterm2-solarized.md
Created October 21, 2018 06:48 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + Oh My Zsh + Solarized color scheme + Meslo powerline font + [Powerlevel9k] - (macOS)

Default

Default

Powerlevel9k

Powerlevel9k

func p_setupTextLayer(text: String) -> CAShapeLayer {
var letters = CGPathCreateMutable()
let font = CTFontCreateWithName("Helvetica-Bold", 72, nil)
let attrs = [kCTFontAttributeName: font]
var attrString = NSAttributedString(string: text, attributes: attrs)
let line = CTLineCreateWithAttributedString(attrString)
let runArray = CTLineGetGlyphRuns(line)
@zh-se
zh-se / gist:28f56ae78feda28c4e1e
Last active August 29, 2015 14:28 — forked from iwasrobbed/gist:5528897
UICollectionView w/ NSFetchedResultsController & NSBlockOperation. Idea originated from Blake Watters (https://github.com/AshFurrow/UICollectionView-NSFetchedResultsController/issues/13)
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
self.shouldReloadCollectionView = NO;
self.blockOperation = [[NSBlockOperation alloc] init];
}
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id<NSFetchedResultsSectionInfo>)sectionInfo
atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type
{
__weak UICollectionView *collectionView = self.collectionView;
// 1. A property has the same name as a segue identifier in XIB
@property (nonatomic) ChildViewController1 *childController1;
@property (nonatomic) ChildViewController2 *childController2;
// #pragma mark - UIViewController
- (void)prepareForSegue:(UIStoryboardSegue *)segue
sender:(id)sender
{
[super prepareForSegue:segue sender:sender];
diafter - dispatch after
@weakify(self);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, $DELAY$ * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
@strongify(self);
NSLog(@"dispatch after");
$END$
});
dthread - dispatch in a new thread
@weakify(self);
----- Esc -----
Quick change directory: Esc + c
Quick change directory history: Esc + c and then Esc + h
Quick change directory previous entry: Esc + c and then Esc + p
Command line history: Esc + h
Command line previous command: Esc + p
View change: Esc + t (each time you do this shortcut a new directory view will appear)
Print current working directory in command line: Esc + a
Switch between background command line and MC: Ctrl + o
Search/Go to directory in active panel: Esc + s / Ctrl + s then start typing directory name
You can add support for Google Protocol Buffers to an Xcode 5 project using Cocoapods by adding the following line to your Podfile.
pod 'GoogleProtobuf', '~> 2.5.0'
This will place the C++ version of the protobuf code into a Pod for your project. It will also add the protoc compiler in the folder Pods/GoogleProtobuf/bin/protoc within your project.
You can create a custom build rule in your project that automatically converts the .proto files into .ph.{h,cc} files. Here is how I did that:
Setup a build rule to "Process Source files with names matching: *.proto Using Custom Script". The script should include the following:
cd ${INPUT_FILE_DIR}