Skip to content

Instantly share code, notes, and snippets.

View ideawu's full-sized avatar
🎯

吴祖洋 ideawu

🎯
View GitHub Profile

OS X 屏幕录制视频转 GIF 动画

本篇文章告诉你如何在 Mac OS X 上用免费的工具来将屏幕录制视频转成 GIF 动画, 这些免费的工具是: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

步骤

首先, 使用系统自带的 "QuickTime Player" 程序来录制屏幕:

@ideawu
ideawu / AVFoundation write read audio file frame by frame
Last active November 4, 2022 20:53
AVFoundation write/read audio file frame by frame
#import <AVFoundation/AVFoundation.h>
#import "Recorder.h"
@interface Recorder()<AVCaptureAudioDataOutputSampleBufferDelegate>{
AVCaptureDevice *audioDevice;
AVCaptureDeviceInput *audioInput;
AVCaptureAudioDataOutput* _audioDataOutput;
dispatch_queue_t _captureQueue;
AVURLAsset *_asset;
@ideawu
ideawu / hid-example.c
Created October 18, 2016 08:15
Hidraw Userspace Example
/*
* 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.
*/
@ideawu
ideawu / keyboard_press.c
Created October 19, 2016 08:25
Linux Command Line Check Keyboard Any Press
#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
@ideawu
ideawu / epoll_latency.c
Last active December 3, 2020 01:30
Test the latency of signal epoll_wait() to return by kill()
#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>
@ideawu
ideawu / quicksort
Last active June 29, 2021 08:29
快速排序QuickSort算法JavaScript实现, 包括 Hoare 和 Lomuto 版本的实现,以及网友实现版本的对比
<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){
@ideawu
ideawu / fsync-bench.cpp
Created May 13, 2020 15:25
fsync benchmark
#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>
@ideawu
ideawu / 计算机入门 - CAS.md
Last active December 2, 2020 04:44
计算机入门: CAS

CAS(Compare And Set) 是一种避免错误地修改数据的手段. 举一个可以使用 CAS 的场景:

某工厂老板通过邮件告诉公司出纳, 要给某供应商打款. 因为工作流程失误, 有两个出纳都进行了打款. 款项被错误地打了两次. 如果工作流程没有问题, 或者公司的出纳只有一位, 依然可能出现打款两次的错误.

要解决这个问题, 可能你已经想到解决方案了: 给这次任务分配一次性的密钥, 拥有密钥的人才能打款, 密钥用完就失效.

CAS 的思路类似. 我们给数据加一把锁, 锁有密码, 只有拥有密码的人才能修改. 特别的, 密码是一次性的, 用过一次就会失效. CAS 一般用整数版本号来表示锁, 修改后, 版本号加1, 原来的锁自然就失效了.

任何一个系统, 如果实现了一次性写锁(密钥), 则这个系统拥有了 CAS 能力.

@ideawu
ideawu / 线性一致性定义.md
Last active December 2, 2020 04:35
线性一致性定义

线性一致性三大约束

  1. 写操作完成后, 后续的读操作一定会返回不早于该次写操作的新值
  2. 如果某一次读操作返回了新值, 则后续的读操作一定会返回不早于该值的新值
  3. 如果两次操作的时间区间有重叠, 则两次操作不区分前后
@ideawu
ideawu / ACID - Atomicity.md
Last active December 3, 2020 05:00
数据库事务原子性
  • 问题: 多个独立的操作, 如何成为一个原子操作?
  • 答案: 依赖一个支持原子操作的地方(单点).

实现方案:

  1. 单点单标记, 指示中间态的数据(资源)的真正状态 - Commit Point
  2. 单点多标记, 保存所有资源的中间状态(需要用原子操作来保存事务涉及的多个资源的状态)
  3. 单点副本, 先在单点修改数据, 再异步地复制数据到最终的目的地 - Redo Log

经典的 2PC: 两阶段修改, 单点提交(确认). 属于方案1 - 单点单标记.