Skip to content

Instantly share code, notes, and snippets.

View donly's full-sized avatar
🎯
Focusing

Tung donly

🎯
Focusing
View GitHub Profile
@donly
donly / Swift3_Pointer.swift
Last active November 18, 2016 08:08
Using pointer in Swift 3
//: Playground - noun: a place where people can play
import Foundation
var str = "Hello"
let data1 = str.data(using: String.Encoding.utf8)!
data1.withUnsafeBytes { (bytes: UnsafePointer<CChar>) -> Void in
print(bytes.pointee)
let arr = UnsafeBufferPointer(start: bytes, count: 5)
@donly
donly / c_pointer.c
Created November 18, 2016 01:34
C language pointer usage demo
int main(int argc, const char * argv[]) {
/* 指针、引用和取值
int *ptr; // 声明一个 int 指针
int val = 1; // 声明一个 int 值
ptr = &val; // 为指针分配一个 int 值的引用
int deref = *ptr; // 对指针进行取值
int nullVal; // 默认值是 0
int *nullPtr = &nullVal;
printf("Hello, World!\n%p=%d\n%p=%d\n", ptr, deref, nullPtr, nullVal);
@donly
donly / default.custom.yaml
Created July 13, 2016 05:23 — forked from lotem/default.custom.yaml
在Rime輸入方案選單中添加五筆、雙拼、粵拼、注音,保留你需要的
# default.custom.yaml
# save it to:
# ~/.config/ibus/rime (linux)
# ~/Library/Rime (macos)
# %APPDATA%\Rime (windows)
patch:
schema_list:
- schema: luna_pinyin # 朙月拼音
- schema: luna_pinyin_simp # 朙月拼音 简化字模式
@donly
donly / routeOnMap.m
Last active January 20, 2016 07:45 — forked from siqin/routeOnMap.m
Draw route on MKMapView
#pragma mark -
- (void)drawTestLine
{
// test code : draw line between Beijing and Hangzhou
CLLocation *location0 = [[CLLocation alloc] initWithLatitude:39.954245 longitude:116.312455];
CLLocation *location1 = [[CLLocation alloc] initWithLatitude:30.247871 longitude:120.127683];
NSArray *array = [NSArray arrayWithObjects:location0, location1, nil];
[self drawLineWithLocationArray:array];
}
// 添加通知
[[UIDevice currentDevice] setProximityMonitoringEnabled:YES];
if ([UIDevice currentDevice].proximityMonitoringEnabled == YES)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(proximitySensorChange:)
name:UIDeviceProximityStateDidChangeNotification
object:nil];
// 移除通知
if ([UIDevice currentDevice].proximityMonitoringEnabled == YES)
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
switch (error.code) {
case kCLErrorLocationUnknown:
NSLog(@"The location manager was unable to obtain a location value right now.");
break;
case kCLErrorDenied:
NSLog(@"Access to the location service was denied by the user.");
break;
case kCLErrorNetwork:
- (IBAction)openGPS:(id)sender {
if (locationManager == nil) {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest; // 越精确,越耗电!
}
[locationManager startUpdatingLocation]; // 开始定位
}
CLLocationManager *manager = [[CLLocationManager alloc] init];
if (manager.locationServicesEnabled == NO) {
UIAlertView *servicesDisabledAlert = [[UIAlertView alloc] initWithTitle:@"Location Services Disabled" message:@"You currently have all location services for this device disabled. If you proceed, you will be asked to confirm whether location services should be reenabled." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[servicesDisabledAlert show];
[servicesDisabledAlert release];
}
// declare
@property (retain) NSTimer *unregisteredTimer;
// implements
- (IBAction)createUnregisteredTimer:sender {
NSMethodSignature *methodSignature = [self methodSignatureForSelector:@selector(invocationMethod:)];
// declcare
@property (assign) NSTimer *repeatingTimer;
// implements
- (IBAction)startRepeatingTimer:sender {
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.5