Skip to content

Instantly share code, notes, and snippets.

View VictorZhang2014's full-sized avatar

Victor VictorZhang2014

View GitHub Profile
@VictorZhang2014
VictorZhang2014 / DecompressCPP
Created March 19, 2017 02:36
Decompress/compress std::string methods was written by C++
#include <zlib.h>
#include <sstream>
/** Compress a STL string using zlib with given compression level and return
* the binary data.
https://panthema.net/2007/0328-ZLibString.html
*/
std::string VLUtilitiesEncoding::compress(const std::string & str, int compressionlevel = Z_BEST_COMPRESSION)
{
z_stream zs; // z_stream is zlib's control structure
@VictorZhang2014
VictorZhang2014 / RSACryptographic.h
Last active August 25, 2021 05:22
RSACryptographic, a set of RSA encryption/decryption for iOS/Mac OS
#import <Foundation/Foundation.h>
@interface RSACryptographic : NSObject
- (void)loadPublicKeyFromFile:(NSString*)derFilePath;
- (void)loadPublicKeyFromData:(NSData*)derData;
- (void)loadPrivateKeyFromFile:(NSString*)p12FilePath password:(NSString*)p12Password;
- (void)loadPrivateKeyFromData:(NSData*)p12Data password:(NSString*)p12Password;
@VictorZhang2014
VictorZhang2014 / RSACryptoGraphy.cs
Created March 29, 2017 11:22
RSACryptoGraphy, a set of methods was written by C#.
/// <summary>
/// Create public key/private key file, actually, the original certificates was modified to a XML file
/// 创建公钥/私钥文件,其实就是把原有的证书的内容修改成XML格式的
/// </summary>
public static void CreateCertificateKeyXML(string path, string key)
{
try
{
FileStream keyxml = new FileStream(path, FileMode.Create);
StreamWriter sw = new StreamWriter(keyxml);
@VictorZhang2014
VictorZhang2014 / RSACryptography.cs
Last active March 31, 2017 06:50
RSACryptography, a set of RSA de/encryt methods who can read the p12 file with a password , and can generate public key in terms of its private key. It was written by C#.
//This file is encrypt/decrypt data in a default way which can not decrypt/decrypt a chunk of data
using System;
using System.Text;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
namespace RSA_CSharp_Example
{
class Program
@VictorZhang2014
VictorZhang2014 / RSACryptography1.h
Last active March 31, 2017 11:28
RSACryptography, a set of RSA encrypt/decrypt methods for a chunk of data in Objective-c/iOS
#import <Foundation/Foundation.h>
@interface RSACryptographic : NSObject
- (void)loadPublicKeyFromFile:(NSString*)derFilePath;
- (void)loadPublicKeyFromData:(NSData*)derData;
- (void)loadPrivateKeyFromFile:(NSString*)p12FilePath password:(NSString*)p12Password;
- (void)loadPrivateKeyFromData:(NSData*)p12Data password:(NSString*)p12Password;
@VictorZhang2014
VictorZhang2014 / VLAudioSessionControl
Created April 8, 2017 03:17
iOS short sound playback , AudioServicesPlaySystemSound and AudioServicesPlaySystemSoundWithCompletion
#import "VLAudioSoundControl.h"
@implementation VLAudioSoundControl
+ (void)RingTone:(NSString *)ringName type:(NSString *)type {
[self pauseBackgroundSoundWithError:nil];
SystemSoundID send_voice_sound_id = 0;
//Load sound file
@VictorZhang2014
VictorZhang2014 / PinyinUtil.m
Last active April 5, 2018 09:09
PinyinUtil for finding the diacritic's position, removing diacritics in a pinyin string or transforming Mandarine to pinyin on iOS platform written by Objective-C
+ (void)test {
NSString *zhua = @"zhuā";
NSString *tong = @"tóng";
NSString *bie = @"biě";
NSString *yi = @"yì";
int zhuaPosition = [self detectDiacriticsPosition:zhua]; // 输出1
NSLog(@"%@%d", zhua, zhuaPosition);
int tongPosition = [self detectDiacriticsPosition:tong]; // 输出2

Keybase proof

I hereby claim:

  • I am victorzhang2014 on github.
  • I am victor_zhang (https://keybase.io/victor_zhang) on keybase.
  • I have a public key ASB-f57gfmokTjmPtHXnWD7aqKhYXneMfovhWxiZFIMBwQo

To claim this, I am signing this object:

@VictorZhang2014
VictorZhang2014 / Singleton.py
Created February 7, 2019 03:30 — forked from tkhoa2711/Singleton.py
A thread-safe implementation of Singleton in Python
import threading
# A thread-safe implementation of Singleton pattern
# To be used as mixin or base class
class Singleton(object):
# use special name mangling for private class-level lock
# we don't want a global lock for all the classes that use Singleton
# each class should have its own lock to reduce locking contention
__lock = threading.Lock()
@VictorZhang2014
VictorZhang2014 / MonitorEvent.cs
Created April 30, 2019 09:28
C# Monitor WMI Events
// https://stackoverflow.com/questions/21731044/is-there-a-way-to-attach-an-event-handler-to-the-list-of-running-processes-in-c
//
static void Main(string[] args)
{
var query = new EventQuery("SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance isa \"Win32_Process\"");
using (var eventWatcher = new ManagementEventWatcher(query))
{
eventWatcher.EventArrived += eventWatcher_EventArrived;
eventWatcher.Start();