Skip to content

Instantly share code, notes, and snippets.

View lingling2012's full-sized avatar

Kitsion lingling2012

View GitHub Profile
@lingling2012
lingling2012 / encoding-video.md
Last active May 23, 2019 16:40 — forked from glen-cheney/encoding-video.md
Encoding video for the web

Encoding Video

Installing

Install FFmpeg with homebrew. You'll need to install it with a couple flags for webm and the AAC audio codec.

brew install ffmpeg --with-libvpx --with-libvorbis --with-fdk-aac --with-opus
@lingling2012
lingling2012 / MyMsgSend.m
Created February 26, 2014 10:06
Simulate objective c message dispatcher: objc_msgSend
#import <Foundation/Foundation.h>
#import <objc/objc-runtime.h>
static const void *myMsgSend(id receiver, const char *name) {
SEL selector = sel_registerName(name);
IMP methodIMP = class_getMethodImplementation(object_getClass(receiver), selector);
return methodIMP(receiver, selector);
}
void RunMyMsgSend() {
#import <Foundation/Foundation.h>
#import <objc/objc-runtime.h>
void PrintObjectMethods () {
unsigned int count = 0;
Method *methods = class_copyMethodList([NSObject class], &count);
for (unsigned int i = 0; i < count; i++) {
SEL sel = method_getName(methods[i]);
const char *name = sel_getName(sel);
printf("%s\n", name);
@lingling2012
lingling2012 / objc-runtime-sample.m
Created February 26, 2014 09:59
OC Runtime sample - Dynamic Implementation
#import <Foundation/Foundation.h>
#import <objc/objc-runtime.h>
@interface Person : NSObject
@property (copy) NSString *givenName;
@property (copy) NSString *surname;
@end
@interface Person ()
@property (strong) NSMutableDictionary *properties;
@lingling2012
lingling2012 / reverse_string.c
Created February 25, 2014 17:47
左旋转字符串
/**
* 左旋转字符串
*/
#include <stdio.h>
/**
* 方案一
*/
void left_shit_one(char *s, int n) {
char t = s[0];
@lingling2012
lingling2012 / sample_thread_cancel.c
Created October 8, 2013 16:02
Use pthread_cancel, pthread_setcancelstate, pthread_setcanceltype to Cancel a thread.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
void *thread_func(void *arg);
int main(void) {
int rs;
pthread_t thd;
@lingling2012
lingling2012 / gist:5457180
Created April 25, 2013 02:52
check little or big endian.
#include <stdio.h>
int checkEndian(void) {
union {
int i;
char ch;
}c;
c.i = 1;
return (c.ch == 1);
}
@lingling2012
lingling2012 / gist:5429148
Last active December 16, 2015 11:39
piece of code: try to reimplement 'strtok', 'strspn', 'strcspn' in Standard C Library.
/* find index of first s1[i] that matches any s2[]. */
size_t czf_strcspn(const char *s1, const char *s2) {
const char *sc1, *sc2;
for (sc1 = s1; *sc1 != '\0'; ++sc1) {
for (sc2 = s2; *sc2 != '\0'; ++sc2) {
if (*sc1 == *sc2)
return (sc1 - s1);
}
}
return (sc1 - s1); // terminating nulls match.