tensorflow2.x使用cuda10.2(非常简单)

# 目前tensorflow2.2/2.3官方标配cuda10.1,也是官方在github给出方案,修改cuda软链接即可,非常简单。也不影响pytorch1.5(cuda10.2)的继续使用。

# 前提是你已经正确安装cuda10.2,检查:

nvidia-smi
nvcc -V

# 干正事(重点就这二步):

cd /usr/local/cuda-10.2/targets/x86_64-linux/lib/
ln -s libcudart.so.10.2.89 libcudart.so.10.1

cd /usr/local/cuda-10.2/extras/CUPTI/lib64
ln -s libcupti.so.10.2.75 libcupti.so.10.1

# 检查添加路径:

vim /etc/profile
export CUDA_HOME=/usr/local/cuda-10.2
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64:${CUDA_HOME}/extras/CUPTI/lib64
export PATH=${CUDA_HOME}/bin:${PATH}
source /etc/profile

# 检查GPU:

>python
>>>import tensorflow as tf
>>>tf.__version__
2.2.0
>>>tf.test.is_gpu_available()
True
>>>tf.config.list_physical_devices('GPU')
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU'),
 PhysicalDevice(name='/physical_device:GPU:1', device_type='GPU'),
 PhysicalDevice(name='/physical_device:GPU:2', device_type='GPU'),
 PhysicalDevice(name='/physical_device:GPU:3', device_type='GPU')]

大功告成!

nohup python train_tf_model.py > log.txt 2>&1 &
watch -n 0.1 -d nvidia-smi     #每隔0.1秒刷新一次
tailf log.txt

tensorboard --logdir=callbacks --host=xxx.xx.xxx.xx 服务器地址

摘录自https://blog.csdn.net/sinat_20174131/article/details/106807448

SQLite C# version

SQLite C# version
If the first program, we check the version of the SQLite database.

Program.cs

using System;
using System.Data.SQLite;

namespace Version
{
    class Program
    {
        static void Main(string[] args)
        {
            string cs = "Data Source=:memory:";
            string stm = "SELECT SQLITE_VERSION()";

            using var con = new SQLiteConnection(cs);
            con.Open();

            using var cmd = new SQLiteCommand(stm, con);
            string version = cmd.ExecuteScalar().ToString();

            Console.WriteLine($"SQLite version: {version}");
        }
    }
}

添加spyder(通过PIP安装)的图标到收藏夹

本操作是在Ubuntu 20.04 下

cd /usr/share/applications
sudo gedit spyder.desktop
 
然后把下列复制到gedit中
 
[Desktop Entry]
Encoding=UTF-8
Name=Spyder3
Comment=The Python IDE
Exec=/usr/local/bin/spyder  ''spyder 路径
Icon=/home/你的用户名/spyder3.png  ‘’下载图片的路径
StartupNotify=True
Terminal=False
Categories=Development;Science;IDE;Qt;
Type=Application
StartupNotify=True
MimeType=text/x-python;
X-AppStream-Ignore=True

然后搜索spyder

记录excel(有密码)打不开,用python 还原。

记录excel(有密码)打不开,用python 还原。

from win32com.client import DispatchEx


def read_excel_password(filename, password):
    excel = DispatchEx("Excel.Application")  # 启动excel
    excel.Visible = False  # 去掉可视化
   
    demo = excel.Workbooks.Open(filename, UpdateLinks=False, ReadOnly=False, Format=None, Password=password)  # 打开文件并将密码传入

    #xlSheet_1 = demo.Worksheets(1)  # 打开第一个sheet
    demo.SaveAs("d:\\aaa.xls")  # 另存为
   
    #print(xlSheet_1.Cells(5, 4).Value)  # 打印第一个sheet的第一行一列数据
   
    demo.Close(True)  # 关闭文件
   
if __name__ == '__main__':
    filename = "E:\\xxx.xls"
    password = "xxx"
    read_excel_password(filename, password)

手机上的缓存,.m3u8.sqlite文件转换为视频文件

<?php
//设置源和目标文件路径
$path_soc = 'C:\Users\qinyu\Desktop\SQLite样本\';
$path_des = 'C:\Users\qinyu\Desktop\SQLite样本\';

$filesArr = getDirContent($path_soc);
$key = "";
$ts_encode_con = "";
$filesnum = sizeof($filesArr);
for($i = 0; $i < $filesnum; $i++ ){
    $allnum = $i + 1;
    echo '提取解密进度:' . $allnum . '/' . $filesnum . "\r\n";
    $db = new SQLite3($path_soc . $filesArr[$i]);
    $results = $db->query('select VALUE FROM caches where key like \'%get_dk%\'');
    while ($row = $results->fetchArray()) {
        $key = $row[0];
    }
    $results = $db->query('select key FROM caches where key like \'%start%\'');
    while ($row = $results->fetchArray()) {
        $a = strstr($row[0], "&end", true);
        $a = strstr($a, "start=");
        $idArr[] = str_replace("start=", "", $a );
    }
    sort($idArr);
    for($j=0; $j < sizeof($idArr); $j++) {
        $text = "select VALUE FROM caches where key like '%start={$idArr[$j]}&end=%'";
        //echo $text . "\r\n";
        $results = $db->query($text);
        while ($row = $results->fetchArray()) {
            $ts_encode_con .= $row[0];
        }
    }
    $db->close();
    $result = $path_des . $filesArr[$i] . '.ts';
    $result = str_replace(".m3u8.sqlite", "", $result);
    decode($ts_encode_con, $key, $result);
    unset($idArr);
    unset($ts_encode_con);
}
function getDirContent($path){
    if(!is_dir($path)) return false;
    $arr = array();
    $data = scandir($path);
    foreach ($data as $value) if($value != '.' && $value != '..'){
        $arr[] = $value;
    }
    return $arr;
}
function decode($con, $key, $result){
    $f = fopen($result, 'wb');
    fwrite($f, decrypt($con, $key));
    fclose($f);
}
function decrypt($string, $key)
{
    $decrypted = openssl_decrypt($string, 'AES128', $key, OPENSSL_RAW_DATA);
    return $decrypted;
}
?>

上面的代码,修改前两行的源文件夹和目标文件夹路径就可以用了,使用效果:

视频太大的时候,把1024的内存调大就可以了,比如10240

转:https://www.qinyuanyang.com/post/250.html

Walkthrough – Automatic Update Process for Outlook Add-in Solutions

Introduction
This article answers the question often asked about Outlook Add-In plug-in: Once an Outlook Add-In solution is deployed on the client computer, how can any future revisions to the solution automatically be made available to the client computer seamlessly? This article attempts to provide end-to-end steps on how the Update Process for Outlook Add-Ins Solutions needs to be handled once the application is deployed on the end-user machine.

Scenario
Normally an application is deployed on the client computer in two ways: One is using the “setup” (using either Microsoft’s or third party setup projects) or using the “publish” or more popularly known as “Click-once”.

As you can see, there are definite reasons why you need to choose one over the other. Click-once is appealing as this method can be used to publish the application and the updates can be made automatically at the end user. But using this method, an application that requires registry entries cannot be deployed. The traditional method can be used to make registry entries but the automatic updates are difficult unless the auto-updater component is custom developed.

The method explained here uses a combination of both the methods to achieve registry updates during the installation and also to push the updates seamlessly to the end user.

Prerequisites
Before we begin, Visual Studio 2005 Tools for Office (VSTO) needs to be installed to create custom add-ins for Outlook in Visual Studio 2005. This article does not address the pre-requisites to develop the Outlook Add-In.

Using the code
Step 1: Create a simple Outlook Add-In project using VS2005.
In Microsoft Visual Studio .NET 2005, open the New Project dialog box, open Visual C#, select Office and click Outlook Add-in.

  • Rename the project as TestOutlookAddin and click OK. As you would expect, Visual Studio creates a project called TestOutlookAddin and it also
    automatically creates a setup project (TestOutlookAddinSetup). This setup project helps in installing the add-in on the client’s computer.
  • Under Outlook folder in Solution Explorer, open ThisApplication.cs and add logic to create a Top Menu Item under ThisApplication_Startup event procedure. Refer to the attached sample application for details.
  •  // Get the Outlook menu bar.
        _menuBar = this.ActiveExplorer().CommandBars.ActiveMenuBar;

     // Get the index of the Help menu on the Outlook menu bar.
       _helpMenuIndex = _menuBar.Controls[_MENU_BEFORE].Index;

     // Add the top-level menu right before the Help menu.
       _topMenu =
         (Office.CommandBarPopup)_menuBar.Controls.Add(
                   Office.MsoControlType.msoontrolPopup,
                   Type.Missing,
                   Type.Missing,
                   _helpMenuIndex,
                   true);

    // Set the Caption from App.Config
       _topMenu.Caption =
         System.Configuration.ConfigurationManager.AppSettings
                           ["TopMenuCaption"];

    // Make the new Menu Item visible
      _topMenu.Visible = true;
  • Add an application configuration file to the Outlook-Addin project TestOutlookAddin. In this article, we would drive the caption name and position for the new Menu item from the App.Config file.
  • key="MenuBeforeLocation" value="Help" />
    key="TopMenuCaption" value="Demo" />
  • In Solution Explorer, right-click the TestOutlookAddin project node and click on Add Reference on the shortcut menu. Select System.Configuration under the .NET tab and click OK.
  • In Solution Explorer, right-click the TestOutlookAddin project node and click on Rebuild on the shortcut menu to rebuild the project.
  • Step 2: Publish the Outlook Add-in project Solution files – TestOutlookAddin
    Use the Publish Wizard under Properties to deploy the solution files to a location on a Server that would enable automatic updates to the application on the client computer. This follows the manifest approach that gives more flexibility in maintaining and updating the application without touching the registry again.

  • In Solution Explorer, right-click the TestOutlookAddin project node and click on Properties on the shortcut menu.
  • Select Publish on the left pane. Make sure the Checkbox ‘Automatically increments revision with each release’ is checked.
  • Use either of the two methods to Publish the solution. This would copy the revised assemblies, application manifest and configuration manifest to the published location.
  • Method 1

  • After selecting Publish on the left Pane as illustrated above, choose Publishing Location (Web site or file path) that would allow automatic updates to the application on the client computer.
  • You may choose either File System, Local IIS or Remote Site . If you choose Remote Site option, the FrontPage Server Extensions need to be enabled on the Server.
  • Click on the Publish Now button.
  • Method 2 – Using the Publish Wizard

  • In Solution Explorer, right-click the TestOutlookAddin project node and click on Publish on the shortcut menu.
  • Specify the centralized location to publish this application. Click on the Browse button to choose either File System, Local IIS or Remote Site . If you choose Remote Site option, the FrontPage Server Extensions need to be enabled on the Server.
  • Click on Next button. Click on Finish to publish your application.
  • You may have noticed that when the Add-in project TestOutlookAddin was created in VS2005, the automatically created setup project TestOutlookAddinSetup contains the Primary output from TestOutlookAddin. Thus the necessary published information like location and version number are available when you rebuild TestOutlookAddinSetup and subsequently in the Windows Installer (.msi) file that will be distributed to your Clients.

    Step 3: Add Prerequisites to the Setup Project – TestOutlookAddinSetup
    Once your Outlook Add-In application is published onto a centralized location, it is time to build the Setup project and distribute it to your Clients as a Windows Installer (.MSI) file. You will now modify the Setup project to check for basic prerequisites.

  • In Solution Explorer, right-click the TestOutlookAddinSetup project node and click on Properties on the shortcut menu.
  • Click on the prerequisites button and make sure the Create setup program to install prerequisite components is checked.
  • Check the .NET Framework 2.0 prerequisite from the list.
  • Specify the install location for prerequisites accordingly. In the sample application, the ‘Download prerequisites from the same location as my application’ is checked.
  • Click OK twice to exit the Properties Page.
  • Step 4: Add Launch Conditions to the Windows Installer (.msi) file

    In this article, we check only two basic prerequisites namely, Visual Studio 2005 Tools for Office Runtime and the Office primary interop assemblies.

  • In Solution Explorer, right-click the TestOutlookAddinSetup project node, point to View on the shortcut menu and click Launch Conditions.
  • To add a launch condition for the Visual Studio 2005 Tools for Office Runtime

  • In the Launch Conditions editor, right-click Requirements on Target Machine, and then click Add Windows Installer Launch Condition.
  • Select the newly added search condition, Search for Component1 and rename to VSTO Runtime.
  • Right click on the above search condition and select the Properties Window. In the Properties window, type {D2AC2FF1-6F93-40D1-8C0F-0E135956A2DA} into the ComponentId property and change the value of Property to CHECK_VSTO_RUNTIME.
  • Select the newly added launch condition, (Condition1) and rename it to Display VSTO Runtime Message.
  • In the Properties window, change the value of the Condition property to CHECK_VSTO_RUNTIME and leave the InstallURL property blank.
  • Change the value of the Message property to ‘The Visual Studio 2005 Tools for Office Runtime is not installed on this Computer’.
  • To add a launch condition for the Outlook 2003 Primary Interop Assembly

  • In the Launch Conditions editor, right-click Requirements on Target Machine, and then click Add Windows Installer Launch Condition.
  • Select the newly added search condition, Search for Component1 and rename the search condition to Outlook 2003 Primary Interop Assemblies.
  • Right click on the above search condition and select Properties Window. In the Properties window, type {14D3E42A-A318-4D77-9895-A7EE585EFC3B} into the ComponentId property and change the value of Property to CHECK_OUTLOOK2003_PIA.
  • Select the newly added launch condition, (Condition1) and rename it to Display PIA message.
  • In the Properties window, change the value of the Condition property to CHECK_OUTLOOK2003_PIA and leave the InstallURL property blank.
  • Change the value of the Message property to ‘The Office 2003 Primary Interop Assemblies have not been installed on this Computer’.
  • Step 5: Installing the Add-in Solution

  • In Solution Explorer, right-click the TestOutlookAddinSetup project node and click on Rebuild on the shortcut menu to rebuild your solution. This would create the Windows Installer file TestOutlookAddinSetup.msi.
  • To install the solution on your development machine using VS2005, in Solution Explorer, right-click the TestOutlookAddinSetup project node and click Install on the shortcut menu.
  • To install the solution on the Client computer, distribute the Windows Installer file TestOutlookAddinSetup.msi to your client and install the same.
  • The installation creates the necessary registry entry for the application Add-In on the Client Computer when all prerequisites are met.
  • Note: It is important to note that the Add-In project TestOutlookAddin was published to some location prior to the installation of the Add-In solution on the client computer.
  • Step 6: Look for the impact of the Add-in in Outlook
    The attached sample application adds a new menu item to Outlook just before the HELP menu. If the installation was successful, the next time Outlook is opened, you should see the new Menu item Demo on the top.

    Step 7: Test the automatic Update Process
    Now that your application has been deployed on your client computer, changes that you make to your solution on the development server should be automatically made available on the Client computer. VSTO uses a concept similar to the ClickOnce to achieve this. In the attached sample application we shall change the caption of the Menu item in the app.config.

  • In the attached sample application TestOutlookAddin, change the Value of the field TopMenuCaption in App.config to DemoRevision.
  • In Solution Explorer, right-click the TestOutlookAddin project node and click on Publish on the shortcut menu.
  • Important: Do not change the location of the Publish at this stage. The local application manifest file on the Client computer contains the published Location and version information that would enable the automatic updating process. If the location needs to be changed for some reason, you will have to distribute the Windows Installer file to your clients for re-installation.

    Step 8: Looking for the desired changes in Outlook
    Close and re-open the Outlook application on the client computer to see the impact of the new changes to the Add-In application. The new Menu item on the top would have the revised text DemoRevision instead of Demo.

    Note: You did not rebuild or re-install your setup application TestOutlookAddinSetup this time.

    The following events take place when Outlook is re-opened:

  • The VSTO Runtime uses the information in the application manifest on the client computer to locate the deployment manifest.
  • The version of the deployment manifest is checked against the version of the application manifest on the client computer. If the version of the deployment manifest on the server is newer than the application manifest on the client computer, the new assemblies and the new application manifest are downloaded automatically.
  • The local copy of the application manifest is overwritten with the latest version.
  • When the user starts Outlook the next time, the new assemblies are executed on the client computer and the changes are reflected in the Outlook application.
  • Summary
    This article demonstrates that once the Outlook Add-In project is deployed on the client computer using the Microsoft Installer (.msi) file created in the setup project of VS2005, further updates to the application can be automatically made available on the Client Computer by using the Publish option of the Add-In project in VS2005. As long as the path to the local application manifest is the same, no further changes in the registry entries are needed for this Add-in. The Publish option will accommodate all updates from here.

    VBA调用javascript(一)

    函数接口

    Function execJSFunc(filePath, funcName)
        Dim code
        Open filePath For Input As #1
        Do While Not EOF(1)
            Line Input #1, tmpCode
            code = code & tmpCode & Chr(13)
        Loop
        Close #1
     
        Set JS = CreateObject("ScriptControl")
        JS.Language = "JScript"
        JS.AddCode code
        Dim result
        result = JS.run(funcName, ThisWorkbook)
        execJSFunc = result
    End Function

    调用封装

    Sub run(funcName)
        Dim path, fileName, pos, result
        path = ThisWorkbook.path
        pos = InStr(4, ThisWorkbook.Name, ".", 1)
        pos = Len(ThisWorkbook.Name) - 4
        fileName = Mid(ThisWorkbook.Name, 1, pos - 1)
        path = path + "" + fileName + ".js"
        result = execJSFunc(path, funcName)
        Debug.Print result
    End Sub

    调用示例

    Sub 按钮1_Click()
        run("hello")
    End Sub

    test.js源码

    function hello(workbook) {
        var sheets = workbook.sheets;
        sheets("Sheet1").range("a3").value = 55555;
        return workbook.sheets.count;
    }

    在x64 OFFICE中使用ScriptControl控件的方法

    Sub Test()  
        Dim oSC As Object  
        Set oSC = CreateObjectx86("MSScriptControl.ScriptControl") ' create ActiveX via x86 mshta host  
        Debug.Print TypeName(oSC) ' ScriptControl  
        With oSC  
            '操作oSC  
        End With  
        CreateObjectx86 , True ' close mshta host window at the end  
    End Sub
    Function CreateObjectx86(Optional sProgID, Optional bClose = False)  
        Static oWnd As Object  
        Dim bRunning As Boolean  
        #If Win64 Then  
            bRunning = InStr(TypeName(oWnd), "HTMLWindow") > 0  
            If bClose Then  
                If bRunning Then oWnd.Close  
                Exit Function  
            End If  
            If Not bRunning Then  
                Set oWnd = CreateWindow()  
                oWnd.execScript "Function CreateObjectx86(sProgID): Set CreateObjectx86 = CreateObject(sProgID): End Function", "VBScript"  
            End If  
            Set CreateObjectx86 = oWnd.CreateObjectx86(sProgID)  
        #Else  
            Set CreateObjectx86 = CreateObject("MSScriptControl.ScriptControl")  
        #End If  
    End Function
    Function CreateWindow()  
        Dim sSignature, oShellWnd, oProc  
        On Error Resume Next  
        sSignature = Left(CreateObject("Scriptlet.TypeLib").GUID, 38)  
        CreateObject("WScript.Shell").Run "%systemroot%\syswow64\mshta.exe about:""about:<head><script>moveTo(-32000,-32000);document.title='x86Host'</script><hta:application showintaskbar=no /><object id='shell' classid='clsid:8856F961-340A-11D0-A96B-00C04FD705A2'><param name=RegisterAsBrowser value=1></object><script>shell.putproperty('" & sSignature & "',document.parentWindow);</script></head>""", 0, False  
        Do  
            For Each oShellWnd In CreateObject("Shell.Application").Windows  
                Set CreateWindow = oShellWnd.GetProperty(sSignature)  
                If Err.Number = 0 Then Exit Function  
                Err.Clear  
            Next  
        Loop  
    End Function

    pip 源切换至国内镜像

    使用 pip 安装软件时,使用国内镜像可以大大提高下载速度

    常用国内镜像
    https://pypi.tuna.tsinghua.edu.cn/simple/ # 清华大学
    https://mirrors.aliyun.com/pypi/simple/ # 阿里云
    https://pypi.douban.com/simple/ # 豆瓣
    https://pypi.mirrors.ustc.edu.cn/simple/ # 中国科学技术大学
    https://pypi.hustunique.com/ # 华中科技大学
    永久使用
    在用户的根目录下创建 .pip 文件夹,新建 pip.conf 文件
    示例:

    cd ~
    mkdir .pip
    cd .pip
    vim pip.conf

    在文件中写入要使用的镜像
    示例:
    使用清华镜像

    [global]
    index-url = https://pypi.tuna.tsinghua.edu.cn/simple
    [install]
    trusted-host = https://pypi.tuna.tsinghua.edu.cn

    Ubuntu下更新NVIDIA显卡驱动导致的重启无法进入操作系统

    在外网上搜索一番后,终于找到了症结所在:Ubuntu内核bug导致gdm3和nvidia驱动冲突,使得gdm3无法正常启动图形界面,而gdm不断尝试启动的后果就是屏幕的闪烁。

    解决方法

    sudo apt purge gdm gdm3 # 卸载gdm和gdm3
    sudo apt install gdm3 ubuntu-desktop    # 重新安装gdm3
    systemctl restart gdm       # 重新启动gdm3服务

    如果还是进不了。
    看到登录界面,在右下角选Ubuntu wayload.