Skip to content

Instantly share code, notes, and snippets.

View VictorZhang2014's full-sized avatar

Victor VictorZhang2014

View GitHub Profile
@VictorZhang2014
VictorZhang2014 / HmacSHA256 Encryption
Last active November 20, 2016 11:27
iOS/C Hmac+SHA256 Encryption
#include <CommonCrypto/CommonDigest.h>
#include <CommonCrypto/CommonHMAC.h>
@interface ZRCommonCryption : NSObject
/**
* 加密方式,MAC算法: HmacSHA256
*
* @param plaintext 要加密的文本
* @param key 秘钥
@VictorZhang2014
VictorZhang2014 / urlEncodeCPP
Created November 20, 2016 11:28
C/C++ URLEncode
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <vector>
void hexchar(unsigned char c, unsigned char &hex1, unsigned char &hex2)
{
hex1 = c / 16;
hex2 = c % 16;
@VictorZhang2014
VictorZhang2014 / URLEncode-Decode
Created November 20, 2016 11:33
C URLEncode/Decode
/**
* @brief URLEncode 对字符串URL编码
*
* @param str 原字符串
* @param strSize 原字符串长度(不包括最后的\0)
* @param result 结果缓冲区的地址
* @param resultSize 结果缓冲区的大小(包括最后的\0)
*
* @return: >0:resultstring 里实际有效的长度
@VictorZhang2014
VictorZhang2014 / zlib-(de)compress(es)-file-content
Created December 18, 2016 14:44
zlib de/compress(es) file content rather than string
#include <stdio.h>
#include <zlib.h>
/*
* A good example for using zlib is correlated de/compress file instead of string
*/
void decompress_one_file(char *infilename, char *outfilename);
void compress_one_file(char *infilename, char *outfilename);
@VictorZhang2014
VictorZhang2014 / Compress-by-zlib
Created December 18, 2016 15:25
Compressing From string to string by zlib. Imported zlib.tbd directly if you're on the MAC.
bool CompressByGZIP(std::string & uncompressedStr, std::string & compressedStr)
{
if (uncompressedStr.length() <= 0) {
return false;
}
compressedStr.resize(uncompressedStr.size() * 1.5 + 12);
/* Before we can begin compressing (aka "deflating") data using the zlib
functions, we must initialize zlib. Normally this is done by calling the
@VictorZhang2014
VictorZhang2014 / BubbleIntersection
Created January 14, 2017 05:01
Bubble Intersection in iOS
@interface MyView : UIView
@property (nonatomic, assign) BOOL isMySelf;
@end
@implementation MyView
- (instancetype)init
{
@VictorZhang2014
VictorZhang2014 / APNs_Main
Created January 14, 2017 15:43
A simplest snippet for Apple Push Notification server in C#. It uses SslStream and X509Certificate2 to push notification.
namespace PushNotification
{
class Program
{
static void Main(string[] args)
{
string filepath = "C://AppPushCertificates.p12";
string pwd = "your certificate passwords";
PushNotification pushNotification = new PushNotification(PushNotificationType.Distribution, filepath, pwd);
PushNotificationPayload payload = new PushNotificationPayload();
@VictorZhang2014
VictorZhang2014 / NSURLSession_SSL_TLS
Created February 9, 2017 09:42
NSURLSession implements SSL/TLS request was written by Objective-C.
#import "ViewController.h"
@interface ViewController ()<NSURLSessionDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
@VictorZhang2014
VictorZhang2014 / NPOIHelper
Created March 4, 2017 11:28
NPOI imports Excel to DataTable and exports DataTable to Excel
using System;
using System.Data;
using System.IO;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
namespace MyNameSpace
{
public static class NPOIHelper
@VictorZhang2014
VictorZhang2014 / UTF8EncodingCPP
Created March 19, 2017 02:34
UTF8 Encoding was written by c++
#include <vector>
#include <codecvt>
std::string VLUtilitiesEncoding::UTF8Encoding(std::string & unencodedStr)
{
if (unencodedStr.length() <= 0) return "";
std::wstring_convert<std::codecvt_utf8<wchar_t>,wchar_t> conversion;
std::wstring wbodyStr = conversion.from_bytes(unencodedStr);
return conversion.to_bytes(wbodyStr);