Skip to content

Instantly share code, notes, and snippets.

@wyyqyl
wyyqyl / base64.cpp
Last active August 29, 2015 14:10
Base64 Encoding and Decoding
std::string base64_encode(const std::string& in) {
BUF_MEM *bptr;
BIO* b64 = BIO_new(BIO_f_base64());
BIO* bio = BIO_new(BIO_s_mem());
bio = BIO_push(b64, bio);
BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL);
BIO_write(bio, in.c_str(), (int)in.size());
BIO_flush(bio);
BIO_get_mem_ptr(bio, &bptr);
@wyyqyl
wyyqyl / type_assertion.go
Created December 4, 2014 15:24
Example of type assertion failure
package main
import (
"fmt"
)
type Aer interface {
DoA()
}
@wyyqyl
wyyqyl / gencert.c
Created December 6, 2014 09:15
Generate cert with openssl
/* This utility generates a self-signed X.509 certificate with an embedded
* DNSSEC chain.
*
* Usage: ./gencert <PEM private key> <DNSSEC chain file> > cert.pem
*/
#include <stdio.h>
#include <openssl/asn1.h>
#include <openssl/bio.h>
@wyyqyl
wyyqyl / port_occupation.cpp
Created December 18, 2014 14:14
Occupy specific ports
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <websocketpp/config/asio_no_tls.hpp>
#include <websocketpp/server.hpp>
#include <boost/shared_array.hpp>
#include <iostream>
typedef websocketpp::server<websocketpp::config::asio> server;
@wyyqyl
wyyqyl / jsoncpp_test_field.cpp
Created December 19, 2014 14:34
test if val["1"]["2"]["3"] is bool
Json::value val;
val = val["1"];
if (val.isNull() || !val.isObject()) {
return false;
}
val = val["2"];
if (val.isNull() || !val.isObject()) {
return false;
}
val = val["3"];
@wyyqyl
wyyqyl / private.xml
Created January 26, 2015 17:08
config for Karabiner
<?xml version="1.0"?>
<root>
<item>
<name>F19 to F19</name>
<appendix>(F19 to Hyper (ctrl+shift+cmd+opt) + F19 Only, send escape)</appendix>
<identifier>private.f192f19_escape</identifier>
<autogen>
--KeyOverlaidModifier--
KeyCode::F19,
KeyCode::COMMAND_L,
@wyyqyl
wyyqyl / ddns.py
Last active May 1, 2019 00:35
Setup DDNS with DNSPOD API
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import socket
import fcntl
import struct
import json
import httplib, urllib
params = dict(
# my customized aliases
alias yyupdate="sudo apt-get update && sudo apt-get dist-upgrade -y"
# alipay build bundle
alias kcart='python build_bundle.py /data/workspace/alipay/android_phone_biosecurity/kcart -DproguardSkip=true'
alias bl='python build.py -Dskipcheck=true -DproguardSkip=true -Dandroid.dex.guard=false'
notes=/data/Dropbox/stackedit/work/`date +%Y`/`date +%b`
note=$notes/`date +%d`.md
@wyyqyl
wyyqyl / shooter.py
Last active November 1, 2016 14:20
Download subtitles from shooter
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import hashlib
import sys
import math
import json
import urllib2
import urllib
private static boolean isWindows() {
return System.getProperties().getProperty("os.name").contains("Windows");
}
public static String exec(String command, long timeout) {
Process ps;
try {
if(isWindows()) {
ps = Runtime.getRuntime().exec("cmd.exe /C " + command);
} else {