本篇文章告诉你如何在 Mac OS X 上用免费的工具来将屏幕录制视频转成 GIF 动画, 这些免费的工具是: QuickTime, ffmpeg, and gifsicle.
首先, 使用系统自带的 "QuickTime Player" 程序来录制屏幕:
#import <AVFoundation/AVFoundation.h> | |
#import "Recorder.h" | |
@interface Recorder()<AVCaptureAudioDataOutputSampleBufferDelegate>{ | |
AVCaptureDevice *audioDevice; | |
AVCaptureDeviceInput *audioInput; | |
AVCaptureAudioDataOutput* _audioDataOutput; | |
dispatch_queue_t _captureQueue; | |
AVURLAsset *_asset; |
/* | |
* Hidraw Userspace Example | |
* | |
* Copyright (c) 2010 Alan Ott <alan@signal11.us> | |
* Copyright (c) 2010 Signal 11 Software | |
* | |
* The code may be used by anyone for any purpose, | |
* and can serve as a starting point for developing | |
* applications using hidraw. | |
*/ |
#if defined(OS_LINUX) || defined(OS_MACOSX) | |
// Linux (POSIX) implementation of _kbhit(). | |
// Morgan McGuire, morgan@cs.brown.edu | |
static int _kbhit() { | |
static const int STDIN = 0; | |
static int initialized = 0; | |
int bytesWaiting; | |
if (!initialized) { | |
// Use termios to turn off line buffering |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <errno.h> | |
#include <arpa/inet.h> | |
#include <netinet/tcp.h> | |
#include <sys/epoll.h> | |
#include <pthread.h> | |
#include <signal.h> |
<html> | |
<body> | |
<script> | |
// @author: ideawu | |
// @link: http://www.ideawu.net/blog/archives/1021.html | |
var swap_count = 0; | |
var cmp_count = 0; | |
// https://gist.github.com/wintercn/c30464ed3732ee839c3eeed316d73253 | |
function wintercn_qsort(arr, start, end){ |
#include <stdio.h> | |
#include <time.h> | |
#include <sys/time.h> | |
#include <thread> | |
#include <mutex> | |
#include <vector> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
#include <unistd.h> |
CAS(Compare And Set) 是一种避免错误地修改数据的手段. 举一个可以使用 CAS 的场景:
某工厂老板通过邮件告诉公司出纳, 要给某供应商打款. 因为工作流程失误, 有两个出纳都进行了打款. 款项被错误地打了两次. 如果工作流程没有问题, 或者公司的出纳只有一位, 依然可能出现打款两次的错误.
要解决这个问题, 可能你已经想到解决方案了: 给这次任务分配一次性的密钥, 拥有密钥的人才能打款, 密钥用完就失效.
CAS 的思路类似. 我们给数据加一把锁, 锁有密码, 只有拥有密码的人才能修改. 特别的, 密码是一次性的, 用过一次就会失效. CAS 一般用整数版本号来表示锁, 修改后, 版本号加1, 原来的锁自然就失效了.
任何一个系统, 如果实现了一次性写锁(密钥), 则这个系统拥有了 CAS 能力.
实现方案:
经典的 2PC: 两阶段修改, 单点提交(确认). 属于方案1 - 单点单标记.