Skip to content

Instantly share code, notes, and snippets.

View donly's full-sized avatar
🎯
Focusing

Tung donly

🎯
Focusing
View GitHub Profile
// 添加通知
[[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)
@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];
}
@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 / 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 / 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 / insert_date_2_rst.py
Last active May 10, 2019 18:05
add the missing date directive below slug when using Pelican
#!/usr/bin/env python3
# -*- coding: utf8 -*-
if __name__ == "__main__":
import glob, os, datetime, fileinput
cwd = os.getcwd()
files = [f for f in glob.glob(cwd + os.path.sep + "**/*.rst", recursive=True)]
for f in files:
modifieddate = datetime.datetime.fromtimestamp(os.path.getmtime(f))
if not ':date:' in open(f).read():
@donly
donly / README.md
Created May 11, 2019 02:52
vibrancy theme for macOS VSCode
  1. Install plugin Custom CSS and JS Loader
  2. Open setting.json add lines below
     "vscode_custom_css.imports": ["file:///Users/Don/Documents/vscode/customtheme/vscode-vibrancy.css",
    "file:///Users/Don/Documents/vscode/customtheme/vscode-vibrancy.js"],
    "vscode_custom_css.policy": true,
    "terminal.integrated.rendererType": "dom"
    
  3. CMD + Shift + p, reload custom css and js
  4. Restart VSCode
@donly
donly / enum_description.swift
Created March 9, 2020 07:51
After implementing the description property and declaring CustomStringConvertible conformance, the Enum type provides its own custom representation.
enum Rank: Int, CustomStringConvertible {
case ace = 1
case two, three, four, five, six, seven, eight, nine, ten
case jack, queen, king
func simpleDescription() -> String {
switch self {
case .ace:
return "ace"
case .jack:
import Foundation
let names = ["Dong", "Chris", "Alex", "Ewa", "Barry", "Baniella"]
// 1.Origin
func forward(_ s1: String, _ s2: String) -> Bool { return s1 < s2 }
var orderNames = names.sorted(by: forward)
// 2.Closure writen as entired format
var reverseNames = names.sorted (by: { (s1: String, s2: String) -> Bool in
@donly
donly / buzzer.ino
Last active December 25, 2020 13:48
An Arduino sample running with buzzer
#define BUZZER D6
void setup() {
Serial.begin(115200);
Serial.println("setup");
pinMode(BUZZER, OUTPUT);
digitalWrite(BUZZER,HIGH);
}