Skip to content

Instantly share code, notes, and snippets.

View donly's full-sized avatar
🎯
Focusing

Tung donly

🎯
Focusing
View GitHub Profile
import Foundation
/**
Set FourCharCode/OSType using a String.
Examples:
let test: FourCharCode = "420v"
let test2 = FourCharCode("420f")
print(test.string, test2.string)
*/
@donly
donly / getMacUUID.swift
Last active April 7, 2022 07:09 — forked from ericdke/getMacUUID.swift
Swift: get the Mac UUID
func getSystemUUID() -> String? {
let dev = IOServiceMatching("IOPlatformExpertDevice")
let platformExpert: io_service_t = IOServiceGetMatchingService(kIOMasterPortDefault, dev)
let serialNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert, kIOPlatformUUIDKey as CFString, kCFAllocatorDefault, 0)
IOObjectRelease(platformExpert)
guard let ser: CFTypeRef = serialNumberAsCFString?.takeUnretainedValue() else { return nil }
if let result = ser as? String {
return result
@donly
donly / sh.sh
Last active February 14, 2023 20:38 — forked from scottopell/sh.sh
Embed SRT file into mp4 with ffmpeg
# got this from http://stackoverflow.com/questions/8672809/use-ffmpeg-to-add-text-subtitles
ffmpeg -i infile.mp4 -f srt -i infile.srt -c:v copy -c:a copy -c:s mov_text -metadata:s:s:0 language=chi outfile.mp4
# confirmed working with the following ffmpeg
# (installed using `brew 'ffmpeg', args: ['with-libvorbis', 'with-libvpx']` )
ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
built with Apple clang version 12.0.0 (clang-1200.0.32.2)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.1_1 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libx
@donly
donly / HCSR04P.ino
Created December 27, 2020 11:01
An Arduino project of HC-SR04+ demo
//HC-SR04+
const int trigpin = D4;
const int echopin = D3;
long duration;
int distance;
void setup(){
pinMode(trigpin,OUTPUT);
pinMode(echopin,INPUT);
Serial.begin(115200);
@donly
donly / Light_and_buzzer.ino
Created December 25, 2020 13:45
Photoresistor and buzzer usage demo
#define BUZZER D6
#define LIGHTD D11
void setup() {
Serial.begin(115200);
Serial.println("setup");
pinMode(BUZZER, OUTPUT);
digitalWrite(BUZZER, HIGH);
@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);
}
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 / 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:
@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 / 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():