Skip to content

Instantly share code, notes, and snippets.

@GaryLee
GaryLee / qmlapp_trayicon.cpp
Last active March 6, 2017 08:11
Use QML application in tray icon
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QMessageBox>
#include <QAction>
#include <QMenu>
#include <QSystemTrayIcon>
int init_trayicon_app()
{
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
@GaryLee
GaryLee / check-ldconfig.py
Created November 12, 2015 06:48
A python script which check the output of 'ldconfig -p' and see if any library which is not readable for everyone. The output of ldconfig should put into the file which ld_list_file spcified.
#!python
import os, re
ld_list_file = 'ldconfig.list'
pattern = re.compile(r'.*=>\s*(?P<libfile>.*)\s*')
lib_files = map(lambda x: x.groupdict()['libfile'],
filter(lambda x: x,
map(lambda ln: pattern.match(ln),
file(ld_list_file, 'r'))))
@GaryLee
GaryLee / dropbtn.qml
Created November 13, 2015 05:15
QML Button which allow drop file to it.
Button {
id: button1
width: 230
height: 179
text: 'drag file to me'
DropArea {
id: fileDropArea
anchors.fill: parent
onEntered: {
drag.accept (Qt.CopyAction);
@GaryLee
GaryLee / short_code_for_matrix_input.py
Created November 18, 2015 13:52
Short code for matrix input
input_round = lambda: range(int(raw_input('\n')))
input_size = lambda: range(int(raw_input('\n'))+1)
input_coord = lambda round, count: round if count == 0 else raw_input('').split(' ')
print [input_coord(round, count) for round in input_round() for count in input_size()]
@GaryLee
GaryLee / RunAsAdmin.py
Last active March 22, 2024 21:52
Elevate the privilege to Admin. Support both python script and pyinstaller wrapped program. Need ctypes only.
#!python
# coding: utf-8
import sys
import ctypes
def run_as_admin(argv=None, debug=False):
shell32 = ctypes.windll.shell32
if argv is None and shell32.IsUserAnAdmin():
return True
@GaryLee
GaryLee / batch_data_proc.py
Last active November 25, 2015 00:34
Batch data processing example. Two methods included, generator and cmdlet.
#!python
# coding: utf-8
# --------------------------------------------
# Make data for test.
with file('g:\\data.txt', 'w') as fd:
for i in range(1000):
fd.write('%d\n' % i)
fd.close()
STATE_OPEREND = 0
STATE_OPERATOR = 1
def to_rpn(expr):
rpn = ['', '', '']
state = STATE_OPEREND
operend_i = 0
while len(expr) > 0:
ch = expr[0]
@GaryLee
GaryLee / init_fbtft.sh
Created November 28, 2015 10:20
The script to initial LCD on Raspberry which labeled "3.5 inch rpi lcd v3.0" on backside.
# The script to initial LCD on Raspberry which labeled "3.5 inch rpi lcd v3.0" on backside.
# The information is from https://github.com/notro/fbtft/issues/338
sudo modprobe flexfb width=320 height=480 regwidth=16 init=-1,0xb0,0x0,-1,0x11,-2,250,-1,0x3A,0x55,-1,0xC2,0x44,-1,0xC5,0x00,0x00,0x00,0x00,-1,0xE0,0x0F,0x1F,0x1C,0x0C,0x0F,0x08,0x48,0x98,0x37,0x0A,0x13,0x04,0x11,0x0D,0x00,-1,0xE1,0x0F,0x32,0x2E,0x0B,0x0D,0x05,0x47,0x75,0x37,0x06,0x10,0x03,0x24,0x20,0x00,-1,0xE2,0x0F,0x32,0x2E,0x0B,0x0D,0x05,0x47,0x75,0x37,0x06,0x10,0x03,0x24,0x20,0x00,-1,0x36,0x28,-1,0x11,-1,0x29,-3
sudo modprobe fbtft_device debug=3 rotate=90 name=flexfb speed=16000000 gpios=reset:25,dc:24
@GaryLee
GaryLee / hook-openpyxl.py
Created November 30, 2015 06:44
Fix ".constants.json" not found issue when using Pyinstaller to pack openpyxl.
# When you're encountering following error.
# > IOError: [Errno 2] No such file or directory: 'C:\\Users\\username\\AppData\\Local\\Temp\\_MEI502322\\openpyxl\\.constants.json'
#
# This solution tested under Python 2.7.10 and Pyinstaller 3.0.
#
# Put this file to your script folder.
# Add this hook to your distribution by
# > pyinstaller --onefile --additional-hooks-dir=. yourscript.py
#
from PyInstaller.utils.hooks import collect_data_files
@GaryLee
GaryLee / listdrv.py
Created December 2, 2015 02:42
List Windows drives and types by win32file.
#!python
# coding: utf-8
import win32api
import win32file
# Available driver types:
# win32file.DRIVE_UNKNOWN => 0
# win32file.DRIVE_NO_ROOT_DIR => 1
# win32file.DRIVE_REMOVABLE => 2