Skip to content

Instantly share code, notes, and snippets.

View zhanglongqi's full-sized avatar

Zhang LongQi zhanglongqi

View GitHub Profile
@zhanglongqi
zhanglongqi / callParent
Last active December 22, 2015 00:00
派生类中调用基类成员
//一、基类和派生类具有相同成员时
//第7章中已经说明了一旦继承之后,派生类就具有了基类的公有成员和保护成员,可以直接使用,在外部也可直接访问基类的公有成//员。这一章//要讲解的是如果基类和派生类具有相同名称的成员变量或可以成员函数时,如何区别使用。
//下面例子中,基类和派生类都有成员变量“id”和成员函数“show()”,无论是在派生类的内部还是外部,直接调用的成员都是派生类//的成员,//而基类的成员函数show()未被调用。要调用基类成员,必须在成员函数名前加上范围(类名::),这也适用于基类的成员//变量。
#include <iostream>
#include <string>
using namespace std;
@zhanglongqi
zhanglongqi / Stack-based breadth-first search tree traversal.source.c
Created September 11, 2013 02:17
基于堆栈的广度优先搜索树遍历
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define CCOUNT 7
#define false 0
#define true 1
//typedef char bool;
@zhanglongqi
zhanglongqi / clear_terminal.py
Last active November 28, 2015 10:55
clear terminal in python
absolutely_unused_variable = os.system('cls' if os.name=='nt' else 'clear')
@zhanglongqi
zhanglongqi / float_to_char.c
Created December 13, 2015 14:49
convert float to char, make transmission easier.
#include <stdio.h>
/*
* two ways of converting float to string or char
*
* */
typedef union {
float f;
char c[4];
} my_union_t;
@zhanglongqi
zhanglongqi / import_from_path.py
Last active December 16, 2015 11:24
how to import module from relative path
import os, sys, inspect
# realpath() will make your script run, even if you symlink it :)
cmd_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile( inspect.currentframe() ))[0]))
if cmd_folder not in sys.path:
sys.path.insert(0, cmd_folder)
# use this if you want to include modules from a subfolder
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe() ))[0],"subfolder")))
if cmd_subfolder not in sys.path:
sys.path.insert(0, cmd_subfolder)
@zhanglongqi
zhanglongqi / pyqt_model_view.py
Last active September 22, 2023 00:19
Example of how to use `QDataWidgetMapper` and `QAbstractTableModel` to customize your own widget and your own model.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from PyQt5.QtWidgets import (QWidget, QDataWidgetMapper,
QLineEdit, QApplication, QGridLayout, QListView)
from PyQt5.QtCore import Qt, QAbstractTableModel, QModelIndex
class Window(QWidget):
def __init__(self, parent=None):
@zhanglongqi
zhanglongqi / download_images_from_your_dashboard.py
Created January 26, 2016 06:11
login and download images from your tumblr dashboard
import requests, bs4, os
from lxml import html
page_num = 5
username = 'XXX@XXX.com'
password = 'AAABBBCCC'
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; '
'Intel Mac OS X 10_11_2) '
@zhanglongqi
zhanglongqi / tree_model_pyqt4.py
Last active October 23, 2023 16:40
PyQt tree model
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
longqi 20/Jan/16 22:42
"""
"""
default.txt
"""
"""
@zhanglongqi
zhanglongqi / delegate.py
Created February 1, 2016 09:31
Use QSlider in delegate way.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
longqi 21/Jan/16 14:35
"""
# This is only needed for Python v2 but is harmless for Python v3.
import sip
@zhanglongqi
zhanglongqi / delegate2.py
Created February 1, 2016 09:43
Delegate example
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
longqi 21/Jan/16 15:36
"""#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import sys
from datetime import date