Skip to content

Instantly share code, notes, and snippets.

@z4none
z4none / main.cpp
Created October 26, 2016 13:18
get application directory
char path[MAX_PATH] = { 0 };
GetModuleFileNameA(NULL, path, MAX_PATH);
strrchr(path, '\\')[0] = '\0';
@z4none
z4none / main.cpp
Last active April 18, 2017 00:05
boost get file path in exe directory
inline string exe_directory(const string & filename)
{
char directory[MAX_PATH] = { 0 };
GetModuleFileNameA(NULL, directory, MAX_PATH);
strrchr(directory, '\\')[0] = '\0';
return filesystem::absolute(
filesystem::path(filename),
filesystem::path(directory)
).string();
@z4none
z4none / main.cpp
Created October 27, 2016 04:12
boost read write ini file
#include <iostream>
#include <boost/filesystem.hpp>
#include <boost/property_tree/ini_parser.hpp>
using namespace boost;
using namespace std;
//
class CIniFile
{
//
@z4none
z4none / main.cpp
Created November 1, 2016 14:04
c++ split string
//
list<string> Split(string s, string delimiter)
{
list<string> result;
unsigned int beg = 0, pos = 0;
while((pos=s.find(delimiter, beg)) != string::npos)
{
result.push_back(s.substr(beg, pos-beg));
beg = pos + delimiter.length();
}
@z4none
z4none / loadScript.js
Created November 25, 2016 07:07
load script
function loadScript(url, onLoaded) {
var loaded = false;
var scriptTag = document.createElement('script');
scriptTag.src = url;
scriptTag.onload = scriptTag.onreadystatechange = function(){
if(!loaded && onLoaded) {
loaded = true;
onLoaded();
scriptTag.onload = scriptTag.onreadystatechange = null;
}
@z4none
z4none / plugin.js
Created December 15, 2016 07:01
jquery plugin template
;(function ($, window, document, undefined) {
var pluginName = 'pluginName', //自定义一个插件名称
defaults = { //定义插件的默认属性
};
function Plugin(element, options) {
this.element = element; //缓存element,让原型链上的方法都可以访问
this.options = $.extend({}, defaults, options); //默认属性和自定义熟悉合并处理
@z4none
z4none / main.cpp
Last active August 12, 2019 07:01
Dialog WinMain
#include <windows.h>
#include "resource.h"
//
INT_PTR CALLBACK DialogProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
@z4none
z4none / main.cpp
Created March 17, 2017 02:37
MFC Create noModal Dialog
CDialogBasedDlg dlg;
if(dlg.Create( CDialogBasedDlg::IDD ))
{
dlg.ShowWindow( SW_HIDE );
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.RunModalLoop();
}
@z4none
z4none / main.cpp
Created May 27, 2017 08:57
ShowHTMLDialog
#include "stdafx.h"
#include <urlmon.h>
#pragma comment(lib, "urlmon.lib")
typedef HRESULT STDAPICALLTYPE MYSHOWHTMLDIALOGFN(HWND hwndParent, IMoniker * pmk, VARIANT * pvarArgIn, TCHAR * pchOptions, VARIANT * pvArgOut);
//
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
@z4none
z4none / record.py
Created May 27, 2017 09:03
pyaudio record
#coding:utf-8
import pyaudio, wave
frame_rate = 8000
sample_count = 512
channel_count = 1
pcm_file = open("1.pcm", "wb+")
audio = pyaudio.PyAudio()