Skip to main content

Posts

Showing posts from 2017

Atom community packages recommendation for Python development

Below are Atom community packages I installed for Python development. They are covered most of functions u need. Take this post as an backup.  

useful linux commands for pdf editor

pdfunite        pdfunite merges several PDF (Portable Document Format) files in order of their occurrence on command line to one PDF result file. EXAMPLE         pdfunite sample1.pdf sample2.pdf sample.pdf        merges all pages from sample1.pdf and sample2.pdf (in that order) and creates sample.pdf pdftocairo        pdftocairo [options] PDF-file [output-file] DESCRIPTION        pdftocairo  converts Portable Document Format (PDF) files, using the cairo output device of the pop‐pler PDF library, to any of the following output formats: OPTIONS        -png   Generates a PNG file(s)        -jpeg  Generates a JPEG file(s)        -tiff  Generates a TIFF file(s)        -pdf   Generates a PDF file pdfseparate        pdfseparate extract single pages from a Portable Document Format (PDF).        pdfseparate  reads  the  PDF  file PDF-file, extracts one or more pages, and writes one PDF file for each page to PDF-page-pattern, PDF-page-pattern should contain %d.  %d is replaced

How to install 3rd parties modules to Python 3.6

How to work with multiple versions of Python installed in parallel? Python version upgrades quickly, it's caused multiple versions on my Debian OS: Python 2 defaults to 2.7; Python 3 defaults to 3.5, then when I installed Python 3.6. It causes 3rd parties modules import problem in Python 3.6.  Take popular pyperclip as example. When I installed pyperclip module, which is popular one to copy/paste clipboard content, in bash with:  pip3 install pyperclip  It prompts install successful, but prompt error when I import in Python 3.6.  >>> import pyperclip Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> import pyperclip ModuleNotFoundError: No module named 'pyperclip' The reason is the default Python 3 is 3.5 i/o 3.6. Install with pip3 will point to 3.5 directly. So solved it, install as following:  peter@Debian:~$ python3.6 -m pip install pyperclip Docs Refer: https://docs.python.org/3/installin

Solve Chrome doesn't allowed to install crx extension

The latest Chrome doesn't allowed user to install crx extension directly and request to install from Chrome web store, we can decompress the crx file to zip folder or download zip file for instead. Below Tunnel-Switch example will teach you how to pass it: Download Tunnel-Switch zip file:  https://github.com/oylbin/tunnel-switch Decompress zip file Chrome-->more tools-->extensions-->tick 'Developer mode'-->Load unpacked extension Browse to decompress zip folder to load Pass, click option to setup Remarks: For other extensions, when you load it, it'll prompt ''manifest_version'' should be 2 problem, you can refer below manifest.jason file to add red line to try. { " name " : " TunnelSwitch " , " version " : " 1.0.4 " , " manifest_version " : 2 , " description " : " cycle through your proxy settings " , " icons " : { " 128

Upgrade BeautifulSoup4 to compatible with Python 3.6

After upgraded to Python 3.6 from 3.5, I encountered BeautifulSoup (bs4) error, such as 'ImportError: cannot import name 'HTMLParseError'. Seems there's compatible problem for BeautifulSoup 4 version. Solution: Upgrade beautifulsoup 4 version to 4.6.0 Commands: $ pip3 install --upgrade beautifulsoup4 Deep in: Install pip3 command: $ sudo apt install python3-pip

Simulate browser to solve https 403 error

As more and more website use https instead of http, we'll encounter 403 error when get content with requests modules. To solve it, the easiest way is simulating browser to access. OS: Debian 9 Python: 3.5.3 Module: requests setup headers as 1st step: headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3)\            AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36'} then add headers as parameter: res = requests.get(xqurl, headers=headers) Below is my example to get stock price in dictionary from a https website: getStockPriceFromXueqiu.py

Linux command to translate DomainName to IP

To translate Domain name to IP address, there are 2 commands in Linux: 1. dig +short [Domain name] eg: $ dig +short google.com 216.58.197.142 2. nslookup [Domain name] eg:$ nslookup google.com Server:         172.31.0.2 Address:        172.31.0.2#53 Non-authoritative answer: Name:   google.com Address: 172.217.26.14

speedometer: How to check Internet Speed via Terminal?

To check server current Internet speed, not the max speed in terminal/command line, the easiest way is speedometer. Take Ubuntu as example: Install: $ sudo apt install speedometer Usage: $ speedometer -rx eth0 unit conversion: bit=bit B=byte 1 byte=8 bit bps=bit/s MB/S = megabyte per second MiB/s = mebibyte per second 1 meibyte=2**20=1048576 bytes = 1024 kibibytes 1 Mbps=1 Mbit/s = 0.125MB/s =(0.125M/2**20)= 0.1192 MiB/s

Show Caps Lock indicator in Debian

For laptop who lacks of Caps Lock indicator, it's headache to check the button again and again. So, adapt a plugin should be a good idea. For Debian, I select indicator-keylock who was designed for Ubuntu although. You can find details here . Download .deb file on the right side. Right click to install with GDebi Package Installer, then logout to active it as following: Indicator for Lock Keys: An appindicator for showing the status of the keyboard lock keys, including Caps Lock, Num Lock and Scroll Lock. 

Setup Python Environment in Atom

If Atom is your preference text editor and Python 3 is one of your programming language, the blog is for you. It'll show you how to setup Python environment in Atom: edit and run. OS                 : Debian 9 Python          : 3.5 Atom version: 1.16.0 Atom Plugin :  atom-runner & autosave the 1st step is Atom installation, I think it should be done on your PC, otherwise, download .deb file from Atom website  and install it in terminal as following: sudo dpkg -i atom-amd64.deb If problem, fix it with: sudo apt-get install -f  The 2nd step is adjust configuration. Open Atom, select 'Edit'-->'Preferences'-->'Editor': Tick 'Show Indent Guide' Change 'Tab Length' to '4' The 3nd one is adding ' atom-runner ' and 'autosave' plugin. Click 'Packages' under 'Preferences' in above step, then search and install 'atom-runner' and 'autosave'. For 'autosave', clic

Remove a PPA in Debian

Firstly, remove PPA from below directories: /etc/apt/sources.list /etc/apt/sources.list.d/ directory Remark: add sudo as prefix due to permission. eg, 'sudo rm noob*' Then, do an update: $sudo apt update

-bash: python: command not found

OS: Debian 9 Python: 3.5.3 Title error encountered when I add ' #! python3 ' in .py file as 1st line. Seems lost the path. As I installed python 3 already, so check its path with 'which' command: peter@Debian:~$ which python3 /usr/bin/python3 Then replace it with absolute path '#! /usr/bin/python3'. Pass! 

Solved: Pyperclip could not find a copy/paste mechanism for your system.

OS: Debian 9 Python version: 3.5 After import pyperclip module, encounter error message ' Pyperclip could not find a copy/paste mechanism for your system. '. Solution: install xsel utility $ sudo apt install xsel then reboot Python IDLE3, import pyperclip, solved. *************** Install pip/pyperclip: $ sudo apt install python3-pip $ sudo pip3 install pyperclip

How to solve Debian / Chromium ugly font

OS: Debian Stretch Chromium version: 57.0.2987.98 The bad feeling for Debian initial font showing comes since the installation. One word: ugly, especially for Chromium web Browser v.s. Windows. I hesitated to return Ubuntu or switch to Elementary OS. But thanks to Google, I find the solution on Debian Wiki. A decent looking fonts can be setup in Debian by creating a .fonts.conf file to any user account home folder. An example of .fonts.conf which you can add to your user account home folder. You can create it with Gedit, just remind to save as '.' as prefix, under Home folder. After that reboot, then you'll find the changing, perfect for Chromium. Enjoy it~ <?xml version='1.0'?> <!DOCTYPE fontconfig SYSTEM 'fonts.dtd'> <fontconfig> <match target="font"> <edit mode="assign" name="rgba"> <const>rgb</const> </edit> </match> <match target="font">

solve error msg 'Possible missing firmware /lib/firmware/i915/'

OS: Debian Stretch There's error msg as following during upgrade due to lack of Intel Linux Graphics firmware files . Against bin name, download and install files on below page accordingly: Error msg: update-initramfs: Generating /boot/initrd.img-4.9.0-1-amd64 W: Possible missing firmware /lib/firmware/i915/bxt_dmc_ver1_07.bin for module i915 W: Possible missing firmware /lib/firmware/i915/skl_dmc_ver1_26.bin for module i915 W: Possible missing firmware /lib/firmware/i915/kbl_dmc_ver1_01.bin for module i915 W: Possible missing firmware /lib/firmware/i915/kbl_guc_ver9_14.bin for module i915 W: Possible missing firmware /lib/firmware/i915/bxt_guc_ver8_7.bin for module i915 W: Possible missing firmware /lib/firmware/i915/skl_guc_ver6_1.bin for module i915 Download page: https://01.org/linuxgraphics/downloads/firmware Eg: bxt_dmc_ver1_07.bin matches  Broxton/bxt / DMC - Ver 1.07 Instructions: $ tar xf filename . tar . bz2 $ sudo bash  ./ install . sh

Import Microsoft fonts to Debian

OS: Debian Testing (Stretch) As lack of fonts, I can't print the invoice correctly. After check Debian Wiki, there are 2 locations to store fonts:  /usr/local/share/fonts    for Global and all users ~/.fonts                           for current user So, copy Windows fonts to /usr/local/share/fonts: cp    /Windows_fonts_Location/*.*  /usr/local/share/fonts/ Completed.

Debian can't shutdown/reboot immediately due to Unattended-upgrades function

OS: Debian testing ( Stretch ) Recently update, I encounter shutdown/reboot stucking problem: the cursor flashing on the top left corner in black screen. It takes a long time to finish then I need to press the power button to finish it every time. Really boring. First I installed the gnome-power-manager package, not sure remove it accidentally or didn't install from the beginning. Shutdown to check, Debian will show the proceeding message. Then, I found below message: 'Unattended-upgrade in progress during shutdown: A start job is running for unattended upgrades shutdown, (1s in 15 mins)' How come the unattended upgrade? I prefer to auto run upgrade when start and want to close the laptop ASAP. Maybe it's useful for server, just waste of time for laptop. I checked the Debian WIKI for unattended upgrades services and found there are 2 packages involved: unattended-upgrades and apt-listchanges . Check the log file under /var/log/unattended-upgrades/, no record

How to enable extensions in Chromium Version 55.0.2883.75

OS: Debian Stretch Chromium version: 55.0.2883.75 Problem: After updated to above version, Chromium disabled all the extensions installed before with below notice: * External extensions are now disabled by default.  Chromium will only load     extensions that are explicitly specified with the --load-extension command     line option passed into CHROMIUM_FLAGS.  See the chromium-lwn4chrome     package for an example of how to do this.   * You can also use the --enable-remote-extensions command line argument to     chromium, which will bypass this restriction. Solution: Add '--enable-remote-extensions' into default-flags configure file. Add one more line as following: $ sudo gedit /etc/chromium.d/default-flags export CHROMIUM_FLAGS="$CHROMIUM_FLAGS --enable-remote-extensions"

Print file content in Python IDLE

During Python 3 learning in IDLE, I can't find a command/module to show a file content. It's boring to switch between IDLE and terminal, so I write this script to avoid boring open/read. For short type, I use pt as shortname of print. Usage: Import pt pt.pt(file_name) Eg: >>> for pyfile in os.listdir(): pt.pt(pyfile) Source code refer GitHub: https://github.com/catinsunshine/ShowFileInPythonIDLE def pt ( filename ): with open (filename) as f: fc = f.read() print (fc)

Install Teamviewer 12 on Debian 8

OS: Debian 8 testing When I tried to install teamviewer, I failed for amd64.deb version installation. Against help page note, I switched to the i386.deb version: Notes on Multiarch: On newer 64-bit DEB-systems with Multiarch-support (Debian 7)  teamviewer_linux_x64.deb  cannot be installed because the package ia32-libs is not available anymore on these systems. In this case you can use  teamviewer_11.0.xxxxx_i386.deb  instead. In case you get the error “wrong architecture i386” you have to execute the following command lines as an administrator: dpkg --add-architecture i386 apt-get update First try 'apt install' command, but get dependencies problems: peter@PDebian:~/Downloads$ sudo apt-get install ./teamviewer_12.0.71510_i386.deb Reading package lists... Done The following packages have unmet dependencies:  teamviewer:i386 : Depends: libc6:i386 (>= 2.11) but it is not installable                    Depends: libgcc1:i386 but it is not installable