Skip to content

Instantly share code, notes, and snippets.

View SAW4's full-sized avatar

Sawa SAW4

  • Hong Kong
View GitHub Profile
@SAW4
SAW4 / fading_example.cpp
Created June 11, 2017 19:40
Qt Fading animation : Py vs C++
void MainInterface::ShowPathToCurr() {
TreeNodeButton* NodeButton = qobject_cast<TreeNodeButton*>(sender());
QPropertyAnimation *a;
int i = 1;
for (Node* curr = NodeButton->get_localref(); !curr->activated; curr=curr->prev,++i){
QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
a= new QPropertyAnimation(eff, "opacity");
curr->Widgetptr->setGraphicsEffect(eff);
curr->Widgetptr->setGraphicsEffect(eff);
a->setDuration(1000+i*500);
@SAW4
SAW4 / One_more_example.py
Created June 16, 2017 20:22
Reusable Exception Handling in Python (implement with decorator wrapper)
from functools import wraps
...
...
class MainInterface(QMainWindow):
...
...
# Reusble Exception checking funciton (For file manager, open file)
def fm_handle_stripe(f):
def wrapper(*args, **kwargs):
try:
@SAW4
SAW4 / qaction_and_qmenu.py
Last active June 17, 2017 22:50
How to get QAction from QMenu + easy QSetting
# Create a new Qmenu
self.sqlcfg_menu = QtWidgets.QMenu(self)
# First item here, index 0
icon = QIcon(os.path.join(self.path, "image/File.png"))
self.sqlcfg_menu.addAction(icon, 'my.cnf', lambda: self.sqlConfMan('my.cnf'))
# Second item, index 1
self.sqlcfg_menu.addSeparator()
@SAW4
SAW4 / REMARK.md
Last active June 18, 2017 17:59
Understanding metaclass and Singleton in Python

How to use metaclass to implement Singleton in Python

First, you need to know that instance of metaclass is class,
just like : an instance of class is object, they have similar idea

Then you need to change the rule of metaclass of your class, to let it only allow create the instance once only.
If the class instance is not None (instance is existed), then return the instance, else create new instance of class.

One more important thing, metaclass is type
class is the instance of type (metaclass)
the origin of class is type (I may say that)

@SAW4
SAW4 / revealer_example.lua
Created July 2, 2017 03:07
Lua GTK+ example ( using lgi )
--[[ Gtk.Revealer widget hiding animation with Lua & lgi
intro: revealer use to hide and show widgets with different transitions
demo: create a toolbar, hide/show by using a button(named:testbutton)
--]]
-- Import the module that you need
local lgi = require ('lgi')
local Gtk = lgi.Gtk
@SAW4
SAW4 / howto.md
Last active August 18, 2017 18:01
Linux connect to Windows Printer through Samba

Linux connect to Windows Printer through Samba

The first thing: Install and launch service

Install stuffs
sudo pacman -S samba smbclient cups
Launch required services
sudo systemctl enable smbd nmbd winbindd //nmbd may not required, it used to resolve netbios name
sudo systemctl start smbd nmbd winbindd

Config your printer in CUPS

Go to localhost:631, enter remote printer the address

@SAW4
SAW4 / README.md
Last active July 25, 2017 22:20
Tips for KDE Plasma Application Menu

Tips: How to start Anaconda Natvigator - Plasma Application Menu

Plasma Application Menu provide flexible, user-friendly interface for modifing apps menu, user can run shell script, python script, lua script, binary by one click.
However Plasma Applicaiton Menu do not pass any environment variable by default, you need to do if by yourself :(
Here is a example for launching Anaconda Natvigator.

source /home/user/.zshrc && zsh -c "/home/user/anaconda3/bin/anaconda-navigator"    
@SAW4
SAW4 / README.md
Last active July 27, 2017 15:31
Aria2c WebUI tips, work around with DirectURL setting.

Aria2c WebUI - How to make DirectURL permanent

As mention by author, DircetURL's setting should be set in the file configuration.js
But after many times I tried, its not worked as expected.
So, just have a look to the code ... to see what's happening during WebUI initialization?
Finally I found a temporary solution. In the file js/services/rpc/rpc.js :

...
...
  if (['http', 'https'].indexOf(uri.protocol()) != -1 && uri.host() != 'localhost') {
 configurations.push({
@SAW4
SAW4 / README.md
Created August 4, 2017 21:12
How to change disqus link color?

Tips: How to change disqus link color?

Add the following style to your head tag

<head>
...
...
  <style> 
 #disqus_thread a { 

Customize Chart.js Radar Chart

In dataset, you can see:

backgroundColor: "rgba(128,128,128,0.2)",   /** bgcolor inside the grid */
borderColor: "#4099FF",                     /** color of the link */
pointBackgroundColor: "#4099FF",            /** color of circle point */
pointBorderColor: "#fff",                   /** color of circle's border */
pointHoverBackgroundColor: "#4099FF"
pointHoverBorderColor: "#4099FF"