2023年10月3日 星期二

C++ Notes

 Dijkstra



#include <iostream>
#include <iomanip>
#include <vector>
#include <climits>
#include <queue>
#include <algorithm>


using namespace std;
typedef pair<int, int> paired;


void printMatrix2(int matrix[7][7], string nodes[7])
{

cout << setw(10) << " |";
for (int r=0; r<7; r++)
{
cout << setw(6) << nodes[r] << " |";
}
cout << endl;

for (int r=0; r<70; r++)
{
cout << "-";
}

cout << endl;

for (int r=0; r<7; r++)
{
cout <<setw(8) << nodes[r] << " |";
for (int c=0; c<7; c++)
{
cout << setw(6) << matrix[r][c] << " |";
}
cout << endl;
}
}


vector<int> initDistance(int matrix[7][7], int spos)
{
vector<int> dist;
for (int i=0; i < 7; i++)
{
if (i == spos)
dist.push_back(0);
else
dist.push_back(INT_MAX);
// cout << dist[i] << endl;
}
return dist;
}

void Dijkstra(int matrix[7][7], int spos, string nodes[7])
{
vector<int> parent{-1, -1, -1, -1, -1, -1, -1};
priority_queue<paired, vector<paired>, greater<paired>> visit; // set order rule
vector<int> visited;
vector<int> dist = initDistance(matrix, spos);
visit.push({0, spos});
parent[spos] = spos;

while (!visit.empty())
{
paired current_paired = visit.top();
int current_dest = current_paired.first;
int current_pos = current_paired.second;
visit.pop();
visited.push_back(current_pos);

// cout << "Current pos: " << current_pos << " " << visit.size() << visited.size() << endl;
for (int i=0; i < 7; i++)
{
if (i == current_pos or matrix[current_pos][i] == 0) continue;
else
{
if (find(visited.begin(), visited.end(), i) != visited.end())
continue;
else
{
if (dist[current_pos] + matrix[current_pos][i] < dist[i])
{
dist[i] = dist[current_pos] + matrix[current_pos][i];
visit.push(make_pair(dist[i], i));
parent[i] = current_pos;
}
}
}
}
}
// print result
for (int i=0; i <7; i++)
cout << nodes[i] << " : " << dist[i] << "(" << nodes[parent[i]] << "), ";
cout << endl;
}

int dijkstraMain()
{
string nodes[] = {"A", "B", "C", "D", "E", "F", "G"};
int spos = 0;

int matrix[7][7] = {
{0, 12, 0, 0, 0, 16, 14},
{12, 0, 10, 0, 0, 7, 0},
{0, 10, 0, 3, 5, 6, 0},
{0, 0, 3, 0, 4, 0, 0},
{0, 0, 5, 4, 0, 2, 8},
{16, 7 , 6, 0, 2, 0, 9},
{14, 0, 0, 0, 8, 9, 0}
};

printMatrix2(matrix, nodes);
cout << endl;

Dijkstra(matrix, spos, nodes);

return 0;
}

/* result reference
| A | B | C | D | E | F | G |
----------------------------------------------------------------------
A | 0 | 12 | 22 | 22 | 18 | 16 | 14 |
B | 12 | 0 | 10 | 13 | 9 | 7 | 16 |
C | 22 | 10 | 0 | 3 | 5 | 6 | 13 |
D | 22 | 13 | 3 | 0 | 4 | 6 | 12 |
E | 18 | 9 | 5 | 4 | 0 | 2 | 8 |
F | 16 | 7 | 6 | 6 | 2 | 0 | 9 |
G | 14 | 16 | 13 | 12 | 8 | 9 | 0 |
start form A -> A : 0(A), B : 12(A), C : 22(B), D : 22(E), E : 18(F), F : 16(A), G : 14(A),
*/

2020年3月1日 星期日

wordpress installation

install
sudo apt-get install nginx
sudo apt-get install mysql mysql-client
sudo install php7.2-fpm php7.2-common php7.2-mbstring php7.2-xmlrpc php7.2-soap php7.2-gd php7.2-xml php7.2-intl php7.2-mysql php7.2-cli php7.2-zip php7.2-curl
setup db
create database dbname;
create user ‘username’@’localhost’ identified by ‘password’;
grant all on dbname.* to ‘username’@’localhost’ identified by ‘password’ with grant option;
flush privileges;
download and install wordpress
cd /tmp && wget https://wordpress.org/latest.tar.gz
tar -zxvf latest.tar.gz
sudo mv wordpress /var/www/wordpress
sudo chown -R www-data:www-data /var/www/wordpress/
sudo chmod -R 755 /var/www/wordpress/
sudo nano /etc/nginx/sites-available/wordpress
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/wordpress
setup wordpress
sudo mv /var/www/wordpress/wp-config-sample.php /var/www/wordpress/wp-config.php
get secure key from https://api.wordpress.org/secret-key/1.1/salt
sudo nano /var/www/wordpress/wp-config.php
setup ssl
sudo apt-get install python-certbot-nginx
sudo certbot –nginx -m admin@domainname -d domainname
enter A, Y, 2
server port allow 80 and 443

2019年7月20日 星期六

vmware

vmware:

VMware Workstation and Device/Credential Guard are not compatible. VMware Workstation can be run after disabling Device/Credential Guard.
Disable Windows Defender Credential Guard for a virtual machine

mac change resolution  

在Mac虚拟机里的终端执行下面的命令,执行完之后重启即可 1920*1080分辨率:  
sudo nvram AC20C489-DD86-4E99-992C-B7C742C1DDA9:width=%80%07 
sudo nvram AC20C489-DD86-4E99-992C-B7C742C1DDA9:height=%38%04  

3840*2160分辨率:  
sudo nvram AC20C489-DD86-4E99-992C-B7C742C1DDA9:width=%0F 
sudo nvram AC20C489-DD86-4E99-992C-B7C742C1DDA9:height=%70%08 

解释:  
width=%0F 是宽度的16进制表示,将四个数字倒过来写就是 00 00 0f 00, 相当于十进制的3840 height=%70%08 是高度的16进制表示,将四个数字倒过来写就是 00 00 08 70, 相当于十进制的2160 所以,上面的两条命令执行完之后,分辨率将被设置为 3840*2160, 其他的分辨率依此类推 注意:1.vmware虚拟机对应的vmx文件里面的这部分内容要修改一下,设置一下最大分辨率svga.autodetect = "FALSE"svga.maxWidth = "3840"svga.maxHeight = "2160" 再然后下载VMware15对应的vmtools安装,重启机器然后在看是否生效。
本文来自:Dkukoc,原地址:https://www.dkukoc.com/post/226.html

2019年6月21日 星期五

noip for ubuntu

note for myself

Install noip2 from source

  • cd /usr/local/src/
  • wget http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz
  • tar xf noip-duc-linux.tar.gz
  • cd noip-2.1.9-1/
  • make install
If you get make not found or missing gcc then you do not have the gcc compiler tools on your machine. At https://help.ubuntu.com/community/InstallingCompilers you can find install instructions if you need help.

Configure the Client

As root (or with sudo) issue the below command:
/usr/local/bin/noip2 -C (dash capital C, this will create the default config file)

Create a Systemd service

Create the file /etc/systemd/system/noip2.service and paste the following:
[Unit]
Description=No-IP Dynamic DNS Update Client
Wants=network-online.target
After=network-online.target

[Install]
WantedBy=multi-user.target
Alias=noip.service

[Service]
Type=forking
ExecStart=/usr/local/bin/noip2
Restart=always

Activating

 $ systemctl daemon-reload
$ systemctl status noip2.service
$ systemctl start noip2.service (start immediately)
$ systemctl enable noip2.service (start on boot)
 

            
# Simple No-ip.com Dynamic DNS Updater
#
# By Nathan Giesbrecht (http://nathangiesbrecht.com)
#
# 1) Install binary as described in no-ip.com's source file (assuming results in /usr/local/bin)
# 2) Run sudo /usr/local/bin/noip2 -C to generate configuration file
# 3) Copy this file noip2.service to /etc/systemd/system/
# 4) Execute `sudo systemctl daemon-reload`
# 5) Execute `sudo systemctl enable noip2`
# 6) Execute `sudo systemctl start noip2`
#
# systemd supports lots of fancy features, look here (and linked docs) for a full list:
# http://www.freedesktop.org/software/systemd/man/systemd.exec.html
[Unit]
Description=No-ip.com dynamic IP address updater
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
Alias=noip.service
[Service]
# Start main service
ExecStart=/usr/local/bin/noip2
Restart=always
Type=forking
 

2016年12月27日 星期二

Learning Python is fun!

Python + Pyqt 

Apparently, this is a note for myself to memorize something.

  • big5中文當成字串比對時,才會正確
# -*- coding: utf8 -*-
 
import sys
reload(sys)
sys.setdefaultencoding('utf-8')

  •   Using win's app
import subprocess
 buttonCancel.clicked.connect(eventB)

def eventB():
    appW= subprocess.call(r'C:\Program Files\Autodesk\Maya2013\bin\maya.exe',shell=True )

  •  get all the drives in win
import os
dri_all = [ '%s:' % d for d in dri_all if os.path.exists('%s:' % d)]

  •  Decryption and Encryption
import win32com.client
def encrypt(key,content): # key,content
    EncryptedData = win32com.client.Dispatch('CAPICOM.EncryptedData')
    EncryptedData.Algorithm.KeyLength = 5
    EncryptedData.Algorithm.Name = 2
    EncryptedData.SetSecret(key)
    EncryptedData.Content = content
    return EncryptedData.Encrypt() def decrypt(key,content): # key,content
    EncryptedData = win32com.client.Dispatch('CAPICOM.EncryptedData')
    EncryptedData.Algorithm.KeyLength = 5
    EncryptedData.Algorithm.Name = 2
    EncryptedData.SetSecret(key)
    EncryptedData.Decrypt(content)
    str = EncryptedData.Content
    return str
s1 = encrypt('lovebread', 'hello world')
s2 = decrypt('lovebread', s1)
print s1,s2
# MGEGCSsGAQQBgjdYA6BUMFIGCisGAQQBgjdYAwGgRDBCAgMCAAECAmYBAgFABAgq
# GpllWj9cswQQh/fnBUZ6ijwKDTH9DLZmBgQYmfaZ3VFyS/lq391oDtjlcRFGnXpx
# lG7o
# hello world

  • ComboBox 
using self.comboBox.activated.connect(self.XXX) #self.XXX is the function will be the slot

def XXX(self. idx):  #idx is the singal sended from the comboBox
        print 'singal is:' idx

  • QTreeWidget
       For custom Item

itemList = []
for fileName in os.listdir(os.path.expanduser("~/"):filePath = os.path.join(os.path.expanduser("~/"), fileName) lineCount = sum(1 for line in open(filePath))item = QtGui.QTreeWidgetItem() item.setData(0, 0, fileName) item.setData(1, 0, str(lineCount)) itemList.append(item) 
 
 
 
 

2015年11月10日 星期二

Useful Links For Everthing

https://github.com/JuppOtto/Google-Cardboard/blob/master/Autowalk.cs -----Unity C++

http://danielborowski.com/posts/create-a-virtual-reality-game-for-google-cardboard/  ---Unity






GUI.Label(Rect(430,320,500,500),"<color=green><size=100>Win</size></color>");


GUI.Label(Rect(400,470,500,500),"<color=green><size=35>Your scores : 
</size></color>"+"<color=black><size=35>"+player_script.points+"</size></color>");

2015年1月22日 星期四

三星手機Mega5.8修復

1.變磚的修復

先進入手機挖礦模式,odin刷入對岸國行5件包(I9152ZCUAM3),開完機之後,進入RECOVERY,WIPE使用者資料,再回到挖礦模式,先刷入中華"KERNEL-BRI-I9152ZSUAMG3-1373258692.tar",直接關機,再回到挖礦,刷入"I9152ZSUAMG3_I9152OZSAMG3_I9152ZSUAMG3_HOME.tar.md5",成功後就救回了。



2.Samsung手機的工廠模式(Factory Mode)開啟狀態--修復方式
  (按電源鍵不會出現選單,直接就會關機;鎖螢幕無法適用....)

首先要有root的權限,才能修復此問題。
使用任一個檔案總管軟體,開啟-----/efs/FactoryApp/資料夾下的 factorymode 這個檔案,以文字編輯器把: OFF 改成 ON 然後存檔. 重開機即可(都是大寫英文字母)



2013年1月17日 星期四

Cockroach

There are two of my favorite pictures that I have taken for fun. Most people don't like cockroach so much, me either. But after I saw this picture, I was surprised by the transparent shell they have. Nature is so amazing!

2013年1月15日 星期二

New born spiders

This is a picture about new born spiders!

When I was doing recycling, I saw those new born spiders beside the garbage can. It was my first time to see this amazing scene. I quickly took my macro lens and took many pictures for those new comers. I hope everyone likes it.