Skip to content

Instantly share code, notes, and snippets.

@CaptainJH
CaptainJH / pyTest.py
Last active April 14, 2018 05:20
PyQT5 fonts and HWND sample
import sys
import ctypes
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtGui import QFontDatabase, QFont, QFontMetrics, QImage, QPainter, QPen
from PyQt5.QtCore import Qt, QRectF
if __name__ == '__main__':
app = QApplication(sys.argv)
@CaptainJH
CaptainJH / bringToFront.cpp
Created August 26, 2014 06:25
Bring window to the top front accepting user input by code
void SetForegroundWindowInternal(HWND hWnd)
{
if (!::IsWindow(hWnd)) return;
BYTE keyState[256] = { 0 };
//to unlock SetForegroundWindow we need to imitate Alt pressing
if (::GetKeyboardState((LPBYTE)&keyState))
{
if (!(keyState[VK_MENU] & 0x80))
{
@CaptainJH
CaptainJH / NamedPipe.cpp
Created August 20, 2014 07:13
How to use windows named pipe
#include <Windows.h>
#include <tlhelp32.h>
#include <psapi.h>
#include <iostream>
#include <utility>
#include <string>
#include <array>
#include <vector>
#include <random>
@CaptainJH
CaptainJH / FFMpeg_player.cpp
Created June 15, 2014 11:35
a basic FFmpeg player based on SFML
//
// a basic FFMpeg video player
// FFMpeg 2.2.2
// SFML 2.1
// XCode 5.1.1
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
@CaptainJH
CaptainJH / SendMail.py
Last active November 10, 2015 07:46
Send Mail by Python
print("Begin SendMail")
# Import smtplib for the actual sending function
import smtplib
# Import the email modules we'll need
from email.mime.text import MIMEText
textfile = "/Users/JHQ/Desktop/msg.txt"
# Open a plain text file for reading. For this example, assume that
@CaptainJH
CaptainJH / mutex_condition.cpp
Last active August 29, 2015 14:01
C++ Multithreading
#include <thread>
#include <mutex>
#include <condition_variable>
std::mutex g_mut;
std::condition_variable g_newMsgCondition;
void AddNewDlgMessage(const std::wstring& t)
{
@CaptainJH
CaptainJH / routine.sh
Last active August 29, 2015 14:00
parse webpage then download file, the decompress them
#!/bin/bash
echo "=======ExportUserReport bash==========="
Root="http://10.130.19.139/19659/"
Root2="http://10.164.7.76/19659/"
DateBegin=$1
TargetRoot="F:/UserReport/"
d=$DateBegin
while true; do
echo $d
@CaptainJH
CaptainJH / Iterate days
Last active August 17, 2023 09:42
Output date string in C++
/// iterate from fromD(like "2014-04-02") to toD("2014-05-02")
std::string tpStr = fromD;
do {
//std::cout << tpStr << std::endl;
ParseIntoUserInfoDB(tpStr, root, order);
std::tm tm;
std::stringstream ss(tpStr + " 0:0:1");
ss >> std::get_time(&tm, "%Y-%m-%d %H:%M:%S");
auto tp = std::chrono::system_clock::from_time_t(std::mktime(&tm));
@CaptainJH
CaptainJH / read_file_line_by_line.cpp
Last active August 29, 2015 13:59
Read all the files in certain folder and parse the files
bool getline(FILE* f, std::string& line)
{
line.clear();
char c = 0;
do {
c = fgetc(f);
if (c == EOF)
@CaptainJH
CaptainJH / cairo_snippet.cpp
Last active August 29, 2015 13:57
some cairo code snippet in cinder
// draw window background
// before this ctx should be created first in every rendering frame, like this:
// cairo::Context ctx(cario::createWindowSurface())
void renderScene(cairo::Contect& ctx)
{
// clear the context with our radial gradient
cairo::GradientRadial radialGrad( getWindowCenter(), 0, getWindowCenter(), getWindowWidth() );
radialGrad.addColorStop( 0, Color( 1, 1, 1 ) );
radialGrad.addColorStop( 1, Color( 0.6, 0.6, 0.6 ) );