Skip to content

Instantly share code, notes, and snippets.

View cyndibaby905's full-sized avatar

Fred Chen cyndibaby905

  • ByteDance
  • Beijing, China
View GitHub Profile
@cyndibaby905
cyndibaby905 / XCDUUID.m
Created January 27, 2016 08:13 — forked from OliverLetterer/XCDUUID.m
With this gist, I, as a total assembly noob, am trying to understand the XCDUUID runtime hack (https://github.com/0xced/NSUUID/blob/1.0.1/NSUUID.m#L167-L221) to be able to use NSUUID on iOS < 6.0.
@implementation XCDUUID
+ (void) load
{
// query runtime if NSUUID class already exists, if so => done
if (objc_getClass("NSUUID"))
{
return;
}
@cyndibaby905
cyndibaby905 / SmartPointer.h
Last active November 27, 2015 07:48
A standard smart pointer
//
// SmartPointer.h
// MemoryDemo
//
// Created by HangChen on 5/5/15.
// Copyright (c) 2015 HangChen. All rights reserved.
//
#ifndef __MemoryDemo__SmartPointer__
#define __MemoryDemo__SmartPointer__
@cyndibaby905
cyndibaby905 / CHAlertViewController.m
Created November 7, 2014 08:58
Just a demo to show how to use runtime functions to implement UIAlertController in iOS 7 or before.
//
// AppDelegate.m
// RuntimeDemo
//
// Created by hangchen on 11/7/14.
// Copyright (c) 2014 hangchen. All rights reserved.
//
#import "AppDelegate.h"
#import <objc/runtime.h>
@cyndibaby905
cyndibaby905 / build_ffmpeg_android
Created August 5, 2014 07:14
Build ffmpeg on OS X 10.9
此处主要参考 http://harryhsu.logdown.com/posts/198416-build-ffmpeg-on-mac-os-109
根据我的编译过程做了适当修改
1. Download NDK
https://developer.android.com/tools/sdk/ndk/index.html
我下载的版本是android-ndk-r10,不同的版本在下面的build脚中本需要修改的地方大致相同.
2. Download ffmpeg source code
下载 ffmpeg(http://www.ffmpeg.org/download.html)
推荐 git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
- (UIImage *)alteredImageFromSampleBuffer:(CMSampleBufferRef)sampleBuffer
{
// Get a reference to the buffer, lock the address, and get a pointer to its data. Easy peasy.
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(imageBuffer, 0);
void *sourceData = CVPixelBufferGetBaseAddress(imageBuffer);
// Set a bunch of variables we need. The "radius" for the blur kernel needs to be positive and odd. The permute map maps the BGRA channels of the buffer to the ARGB that vImage needs.
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
size_t width = CVPixelBufferGetWidth(imageBuffer);
@cyndibaby905
cyndibaby905 / orientation.m
Created April 23, 2014 02:05
Get device orientation using Accelerometer
CMMotionManager *_motionManager = [[CMMotionManager alloc] init];
_motionManager.accelerometerUpdateInterval = 0.1;
__block UIDeviceOrientation orientationLast = UIDeviceOrientationPortrait;
[_motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
UIDeviceOrientation orientationNew;
if (accelerometerData.acceleration.x >= 0.75) {
orientationNew = UIDeviceOrientationLandscapeRight;
}
else if (accelerometerData.acceleration.x <= -0.75) {
orientationNew = UIDeviceOrientationLandscapeLeft;
@cyndibaby905
cyndibaby905 / NSNUll+ InternalNullExtention.m
Created March 28, 2014 09:23
NSNUll+ InternalNullExtention.m
#define NSNullObjects @[@"",@0,@{},@[]]
@interface NSNull (InternalNullExtention)
@end
@implementation NSNull (InternalNullExtention)
@cyndibaby905
cyndibaby905 / PlayingInfo.m
Created January 20, 2014 09:11
Get iPod's current playing info. Do not use `MPNowPlayingInfoCenter`, since it works only for your current application.
MPMusicPlayerController* player = [MPMusicPlayerController iPodMusicPlayer];
//get now playing item
if (player.playbackState == MPMusicPlaybackStatePlaying) {
MPMediaItem*item = [player nowPlayingItem];
NSLog(@"playing %@",[item valueForProperty:MPMediaItemPropertyTitle]);
}
@cyndibaby905
cyndibaby905 / modalview.m
Last active January 3, 2016 10:59
How to write a modal view
UIViewController* avc = [[UIViewController alloc] init];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(50,50,100,100)];
view.backgroundColor = [UIColor redColor];
[avc.view addSubview:view];
UIWindow* ow = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen].bounds];
ow.windowLevel = UIWindowLevelAlert;
ow.backgroundColor = [UIColor clearColor];
ow.rootViewController = avc;
[ow makeKeyAndVisible];
@cyndibaby905
cyndibaby905 / curl.md
Created January 10, 2014 16:34 — forked from btoone/curl.md

Introduction

An introduction to curl using GitHub's API

The Basics

Makes a basic GET request to the specifed URI

curl https://api.github.com/users/caspyin