Skip to content

Instantly share code, notes, and snippets.

View willard1218's full-sized avatar

Willard, Lin willard1218

View GitHub Profile
@willard1218
willard1218 / SrtSegmentMerger.py
Last active April 6, 2023 13:46
merge srt segment with given time interval
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
This is a Python program for merging subtitle files, which uses the third-party library "srt"(https://github.com/cdown/srt) to parse and compose srt files.
The basic idea of the program is to parse the original srt file into multiple "srt.Subtitle" objects, and then iterate and process these objects.
For adjacent two subtitles, if the time interval between them is less than "MIN_TIME_INTERVALS" (defined in the program as the minimum time interval), they are merged into a new subtitle.
Specifically, the content of the original subtitles is extracted and connected with "separator_operator" (defined in the program as the separator),
and a new "srt.Subtitle" object is created with the new start and end times.
Finally, all the new "srt.Subtitle" objects are merged into a new srt file and output to standard output.
@willard1218
willard1218 / printHexdump.c
Created September 25, 2019 04:07
printHexdump
void printHexdump( char *arr, int size) {
const unsigned int bytesOfType = sizeof( char);
const int numOfItemInRow = (0x10 / bytesOfType);
printf("=================================\n");
int count = 0;
for (int i = 0; i <= size / numOfItemInRow; i++) {
printf("%06x ", i);
for (int j = 0; j < numOfItemInRow && count < size; j++) {
printf("%02x ", 0xff & arr[count++]);
}
@willard1218
willard1218 / convertCharset.cpp
Last active September 29, 2019 10:43
Using iconv to convert charset.
//
// main.cpp
// UnicodeEncoding
//
// Created by willard on 2019/9/25.
// Copyright 2019 willard. All rights reserved.
//
#include <iostream>
#include <iconv.h>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Collections.ObjectModel;
namespace TestPowerShell
@willard1218
willard1218 / xxx.md
Last active June 21, 2019 13:05
xxxxxxxx

字串的顯示問題 (編碼問題)

問題

遇到一個字串顯示不正常的問題,語言設定中文時不會有問題,設定成日文就會。 找到最後發現程式某個地方用到反轉字串,使用了 _tcsrev 來完成。

由於專案比較舊,編碼集是用 MBCS 而不是 Unicode, 當設定成 MBCS 時,_tcsrev 被當作 _mbsrev, 如果文字內容是 "a一b" (BIG5 編碼是 0x61 0xa4 0x40 0x62), 經過 _mbsrev 轉換後,在不同的語言設定下,會有不同的結果:

@willard1218
willard1218 / LineChartRenderer.swift
Last active January 31, 2019 09:16
demo for Vahe Kocharyan
//
// LineChartRenderer.swift
// Charts
//
// Copyright 2015 Daniel Cohen Gindi & Philipp Jahoda
// A port of MPAndroidChart for iOS
// Licensed under Apache License 2.0
//
// https://github.com/danielgindi/Charts
//
@willard1218
willard1218 / wrgr.swift
Last active December 15, 2018 01:49
gregre
//
// main.swift
// ftest
//
// Created by willard on 2018/12/14.
// Copyright © 2018 willard. All rights reserved.
//
import Foundation
inputDict = {'Store_name': 'Los Angeles',
'Sales': '1500',
'XXX' :555}
whereConditions = []
for key, value in inputDict.items():
cond = "%s = '%s'" % (key, value)
whereConditions.append(cond)
whereConditionSql = ' AND '.join(whereConditions)
@willard1218
willard1218 / few.md
Last active June 21, 2018 09:42
fewfw

https步驟

  1. 先將 MyEThttp.cpp::103 改成 http,點綠色按鈕跑一次, 再打開瀏覽器輸入 網址 http://localhost:50175,看到網頁就代表server跑起來了。 網頁內容目前是寫在 MyEThttp.cpp::103 ,是靜態的,單純測試用。

  2. 建立 self-signed 憑證

使用系統管理員身份 打開 PowerShell,   輸入指令 New-SelfSignedCertificate -CertStoreLocation Cert:\LocalMachine\My -FriendlyName "TestCert" -NotAfter (Get-Date).AddYears(10) -Subject "localhost" -DnsName "localhost"

//
// ViewController.swift
// text
//
// Created by willard on 2018/4/2.
// Copyright © 2018年 willard. All rights reserved.
//
import UIKit