MoonPoint Support Logo


Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals

Advanced Search
Sun Mon Tue Wed Thu Fri Sat
18 19 20 21
22 23 24 25 26 27 28
29 30 31        
OctNov Dec

Sat, Oct 14, 2017 8:59 pm

Text_factory that can support 8-bit bytestrings

I wrote a Python script that will download a webpage, extract a portion of the text displayed on the page and write the extracted portion to an SQLite database. When I ran the script, I saw the message below displayed:

You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.

I had created the following function to establish the connection to the SQLITE 3 database:

def create_connection (db_file):
   """ Create a database connection to an SQL database
       Return connection object or none """
      conn = sqlite3.connect(db_file)
      return conn
   except Exception as e:
   return None

[ More Info ]

[/languages/python] permanent link

Fri, Oct 13, 2017 10:59 pm

Checking the uptime for a Windows system using PowerShell

If you want to determine how long a Microsoft system has been running since it was last rebooted from a command-line interface (CLI), you can do so using PowerShell. You can do so by subtracting the last boot time from the current date and time. The Get-Date cmdlet shows the current date and time and (Get-CimInstance Win32_OperatingSystem).LastBootUpTime shows the last time the system was booted.

PS C:\Users\public\documents> (Get-CimInstance Win32_OperatingSystem).LastBootUpTime

Tuesday, October 10, 2017 9:12:14 PM

PS C:\Users\public\documents> (Get-Date) - (Get-CimInstance Win32_OperatingSystem).LastBootUpTime

Days              : 3
Hours             : 1
Minutes           : 29
Seconds           : 26
Milliseconds      : 717
Ticks             : 2645667172021
TotalDays         : 3.06211478243171
TotalHours        : 73.4907547783611
TotalMinutes      : 4409.44528670167
TotalSeconds      : 264566.7172021
TotalMilliseconds : 264566717.2021

PS C:\Users\public\documents>

You can use the alias GCIM for Get-CimInstance to save some typing, if you wish.

PS C:\Users\public\documents> (GCIM Win32_OperatingSystem).LastBootUpTime

Tuesday, October 10, 2017 9:12:14 PM

PS C:\Users\public\documents>

[/os/windows/PowerShell] permanent link

Wed, Oct 11, 2017 10:20 pm

Error stating Outlook OST file is in use and cannot be accessed

After I rebooted a Windows 10 PC subsequent to a software update on the system, when I attempted to reopen Microsoft Outlook 2016, I saw the message below:

Outlook Data File

Black exclamation
mark in yellow triangle The file C:\Users\jasmith1\AppData\Local\Microsoft\Outlook\ is in use and cannot be accessed. Close any application that is using this file, and then try again. You might need to restart your computer.

[ More Info ]

[/network/email/clients/outlook/2016] permanent link

Tue, Oct 10, 2017 11:31 pm

Wget and curl functionality via PowerShell on a Windows system

If you are accustomed to using the wget or cURL utilities on Linux or Mac OS X to download webpages from a command-line interface (CLI), there is a Gnu utility, Wget for Windows , that you can download and use on systems running Microsoft Windows. Alternatively, you can use the Invoke-WebRequest cmdlet from a PowerShell prompt, if you have version 3.0 or greater of PowerShell on the system. You can determine the version of PowerShell on a system by opening a PowerShell window and typing $psversiontable. E.g., in the example below from a Windows 10 system, the version of PowerShell is 5.1.15063.674.

PS C:\Users\public\documents> $psversiontable

Name                           Value
----                           -----
PSVersion                      5.1.15063.674
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.15063.674
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3

PS C:\Users\public\documents>

If you have version 3.0 or later, you can use wget or curl as an alias for the Invoke-WebRequest cmdlet, at least up through version 5.x. E.g., if I want to download the home page for the website to a file named index.html, I could use the command wget -OutFile index.html at a PowerShell prompt. Or I could use either of the following commands, instead:

curl -OutFile index.html
Invoke-WebRequest -OutFile index.html

[ More Info ]

[/os/windows/PowerShell] permanent link

Mon, Oct 09, 2017 11:13 pm

Checking the version of a Dynamic Link Library (DLL) file

You can check version information for a Dynamic-link Library (DLL) file, i.e., a file with a .dll filename extension, or a executable file, i.e., a .exe file, from a command-line interface (CLI) on a Microsoft Windows system by using the Get-Item cmdlet. E.g.:

PS C:\> (Get-Item C:\Windows\explorer.exe).VersionInfo

ProductVersion   FileVersion      FileName
--------------   -----------      --------
10.0.15063.0     10.0.15063.0 ... C:\Windows\explorer.exe

PS C:\>

If you can't see all of the information, i.e., if you see three dots indicating that not all of the information is displayed, you can append | format-list to the command to have the output displayed in list format.

PS C:\> (Get-Item C:\Windows\explorer.exe).VersionInfo | format-list

OriginalFilename  : EXPLORER.EXE.MUI
FileDescription   : Windows Explorer
ProductName       : Microsoft® Windows® Operating System
Comments          :
CompanyName       : Microsoft Corporation
FileName          : C:\Windows\explorer.exe
FileVersion       : 10.0.15063.0 (WinBuild.160101.0800)
ProductVersion    : 10.0.15063.0
IsDebug           : False
IsPatched         : False
IsPreRelease      : False
IsPrivateBuild    : False
IsSpecialBuild    : False
Language          : English (United States)
LegalCopyright    : © Microsoft Corporation. All rights reserved.
LegalTrademarks   :
PrivateBuild      :
SpecialBuild      :
FileVersionRaw    : 10.0.15063.608
ProductVersionRaw : 10.0.15063.608

PS C:\>

[ More Info ]

[/os/windows/PowerShell] permanent link

Sun, Oct 08, 2017 10:57 pm

Calculating file checksums on an OS X system

If you need to calculate a checksum, aka cryptographic hash value or digital fingerprint, on a Mac OS X system, you can use the md5 command to calculate a MD5 checksum, which is equivalent to the md5sum utility on Linux systems, and the shasum command to calculate Secure Hash Algorithms (SHA). The default value for shasum, if no algorithm is specified, is Secure Hash Algorithm 1 (SHA-1), but you can specify other algorithms, such as Secure Hash Algorithm 2 (SHA-2), e.g. SHA-256, using the -a option. E.g. -a 256 for SHA-256.

[ More Info ]

[/os/os-x] permanent link

Sat, Oct 07, 2017 10:59 pm

Determining the day of year value using Python

I sometimes need to determine the day of the year corresponding to today's date. The day of year starts with January 1 as day 1 and for 2017, December 31 is day 365. You can find sites online that will provide those values, e.g. Day Numbers for 2017 or NOAA's DOY Calendar. Or, on a system with Python installed, e.g., Linux or OS X, you can use the datetime module to obtain the day of the year corresponding to the current date as shown below:

$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> exit()

Since today is October 7 of the year 2017, the day of the year is 280.

If you want to obtain the day of year (DOY) for another date, you can use, month, day).timetuple().tm_yday where year is the relevant year, month is the month, and day is the day of interest. E.g., March 1, 2017 is DOY 60:

>>> import datetime
>>>, 3, 1).timetuple().tm_yday

[/languages/python] permanent link

Fri, Oct 06, 2017 11:15 pm

Viewing DHCP information on an OS X system

If you want to determine the IP address of the DHCP server from which a Mac OS X system received its IP address, subnet mask, etc., you can obtain that information from a command-line interface (CLI), i.e., a Terminal window by using the command ipconfig getpacket interface where interface is the relevant network interface, which will usually be en0 or en1. You can issue the command ifconfig -a in a Terminal window to see the network interfaces on the system and which have IP addresses assigned to them.

getpacket interface-name
Prints to standard output the DHCP/BOOTP packet that the client accepted from the DHCP/BOOTP server. This command is useful to check what the server provided, and whether the values are sensible. This command outputs nothing if DHCP/BOOTP is not active on the interface, or the attempt to acquire an IP address was unsuccessful.

[ More Info ]

[/os/os-x] permanent link

Sun, Oct 01, 2017 10:53 pm

Finding Gmail SMTP entries in Sendmail log files

I wanted to determine how many connections I was receiving per day from Gmail Simple Mail Transfer Protocol (SMTP) servers to my email server running Sendmail on a CentOS Linux system and the IP addresses of the Gmail servers that were sending email to users on my server. So I created a simple Python script to search for lines in the maillog file, /var/log/maillog for any lines containing "relay" and "" on the same line, since the Gmail servers are in Google's domain.

[ More Info ]

[/languages/python] permanent link

Once You Know, You Newegg AliExpress by

Shop Amazon Local - Subscribe to Deals in Your Neighborhood

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo