Skip to content

Instantly share code, notes, and snippets.

@z4none
z4none / console.cpp
Last active March 21, 2021 16:36
create a console window in a win32 gui application
#include <fcntl.h>
#include <io.h>
//
class EnableConsole
{
FILE * fp;
public:
~EnableConsole()
{
@z4none
z4none / django_mako.py
Last active August 29, 2015 14:23
using Mako template in django
# coding = utf-8
from django.utils.module_loading import import_string
from django.utils.functional import cached_property
from django.template.engine import _dirs_undefined
from django.template.backends.base import BaseEngine
from django.template.backends.utils import csrf_input_lazy, csrf_token_lazy
from django.template.context import _builtin_context_processors
from mako.lookup import TemplateLookup
@z4none
z4none / m2d.py
Created June 26, 2015 00:59
django model to dict (with related model)
from django.forms.models import model_to_dict
authors = []
for author in Author.objects.prefetch_related("books"):
books = [model_to_dict(book, ["name", "price"]) for book in author.books.all()]
author = model_to_dict(author, ["name", "age"])
author["books"] = books
authors.append(author)
# json.dumps(authors)
@z4none
z4none / main.cpp
Last active November 1, 2017 06:35
[Accept drop file] #BCB
// .h
void __fastcall AcceptFiles (TMessage& Msg);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_DROPFILES, TMessage, AcceptFiles)
END_MESSAGE_MAP(TForm)
// .cpp
__fastcall TFormMain::TFormMain(TComponent* Owner)
: TForm(Owner)
@z4none
z4none / main.cpp
Created February 19, 2016 12:16
get file version
//
AnsiString GetFileVersion(AnsiString Path)
{
AnsiString asReturn;
DWORD dwHandle,InfoSize;
InfoSize = GetFileVersionInfoSize(Path.c_str(),&dwHandle);
if(InfoSize == 0) return "";
//将版本信息资源读入缓冲区
char *InfoBuf = new char[InfoSize];
@z4none
z4none / bluetooth.java
Created April 13, 2016 07:54
android check bluetooth
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
// Device does not support Bluetooth
} else {
if (!mBluetoothAdapter.isEnabled()) {
// Bluetooth is not enable :)
}
}
@z4none
z4none / menu.xml
Created April 18, 2016 13:01
showAsAction
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_item_scan"
android:icon="@drawable/ic_scan"
android:title="scan"
app:showAsAction="always">
</item>
@z4none
z4none / MainActivity.java
Created April 18, 2016 13:21
create option menu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.action_menu, menu);
return true;
}
@z4none
z4none / enum.cpp
Created May 25, 2016 02:56
bcb enum files
TSearchRec SearchRec;
int Attr = faAnyFile;
int Ret = FindFirst(FolderPath + "\\*.*", Attr, SearchRec);
while(Ret == 0)
{
if(AnsiString(SearchRec.Name) == "." || AnsiString(SearchRec.Name) == "..")
{
}
@z4none
z4none / main.cpp
Last active October 26, 2016 07:38
one instance
HANDLE mMutexOneInstance;
UINT mMsgLaunched;
mMsgLaunched = RegisterWindowMessage(_T("SOMETHING"));
mMutexOneInstance = ::CreateMutex(NULL, FALSE, _T("MY_APP_ONE_INSTANCE"));
if((mMutexOneInstance != NULL) && (GetLastError() != ERROR_ALREADY_EXISTS))
{
CMyDlg dlg;
dlg.DoModal();