Friday, July 06, 2018

A new home for my projects and a project update

New Home

I know that there is always an expectation that, if you are a developer of some sort, you store your code into Github (at least that is the first one that comes to people's mind).  I have a Github acct, but, because their private repos are not free, I haven't truly used them for storing my repos.  And considering that Microsoft now owns them, I really won't be using them for my code.

Up until now, I have relied on Bitbucket (currently owned by Atlassian), as it offers unlimited free private and public repos.  We have both Bitbucket and Gitlab at my work (local installs for both).  After all of the increased fanfare for Gitlab (after the Microsoft purchase of Github) and my exposuer to it at work, I have made the switch to store my repos there as well.  Unless they change their policies, I will probably be with them quite a while.  


Project Update:

I did want to say that I have migrated my 'pyblueprint' project over to Gitlab.  Thankfully Gitlab makes the migration to them painless, and it was just a click of a couple of buttons to get the repo moved over.  The 'hard part', if you will (although not really), was fixing my git remote to point to the new repository location.  

I do want to say that I have added support to the project for creating a repository up in Gitlab.  Seeing as how I am now using it, why not.  :)  While testing out the application to ensure everything was still working afterwards, I discovered that my checks were not working.  Why?  Because the maintainers of 'pip' decided that, as of pip 10.0.0, they no longer support pip bing used programatically.  If you drop into IDLE, do an 'import pip' and then do a 'dir(pip)', you will now notice that there are no methods associated (aside from the underscore methods).  This completely broke my checks as I had relied on that useful bit.  No worries though, the checks are fixed and functioning as expected.  

Also, if anyone is using this application (don't know if anyone is) and they would like support for an alternative code repository, please feel free to open an enhancement ticket and I will see about adding support for it.  

That's it for now, happy coding!

Saturday, June 30, 2018

Setting up MELPA for Emacs packages

In my journey to learn emacs, one of the first things that I wanted to do was change the theme so that it was more pleasing to the eye.  Anyone who uses a tool enough knows that if you can personalize it for you, you personalize it. 

So in researching themes ( see the emacs themes site ), I kept seeing references to MELPA, which is an emacs package manager.  Sweet!  Unfortunately, my quest to install the theme I wanted was met with the fact that it is NOT configured to use MELPA by default.  Thus, the reason for this write-up. 

In order to configure emacs to see the MELPA packages, you need to edit your .emacs file in your home directory.  If you have at least opened emacs, this file should exist.  If not, just create it and open it for editing.

To correctly enable MELPA, you will need the following as the first section of the file:

;; load emacs 24's package system. Add MELPA repository.
(when (>= emacs-major-version 24)
  (require 'package)
  (add-to-list
   'package-archives
   ;; '("melpa" . "http://stable.melpa.org/packages/") ; many packages won't show if using stable
   '("melpa" . "http://melpa.milkbox.net/packages/")
   t))
 After you save the .emacs file, you will need to restart emacs if it is already running.  If not, start it up.  Once running, you will need to his what in the emacs world is referred to as M-x.  On a mac, that is Option + the 'x' key.  I don't run Windows, so I really couldn't begin to tell you what it is on there. 

That will drop you into the M-x mini buffer.  There, type 'list-packages'.  In the main window, a columned list should appear.  The 4th column is 'archive' and should have packages that say 'melpa' (as well as 'gnu').  If so, you are good to install the theme you found. 

To install a melpa package, drop back into the M-x mini buffer and type 'package-install'.  This will change the prompt to "Install package: " which will wait for a package name.  The nice thing is that tab-complete works in emacs.  So start typing a package name and hit tab, and a list will appear in the are right above the mini buffer. Once you complete installing the packages you need, go ahead and restart emacs. 

I certainly hope this makes your emacs package installation easier.  :)

Straddling the line between editors

Since I started in Unix/Linux about 20 years ago, I have been a staunch user and supporter of vi.  I have known plenty of people that were emacs aficionados, but haven't really taken the time to learn it to the point of being proficient.  I did look at it a few years ago after starting my current job, but with all of the new things I was learning, I forwent it in favor of the things I actually needed to learn at my job.

Now, 5 1/2 year later, I have decided that I am at a point where I finally have time to learn it.  I know what vi lovers are thinking, "hell no!", and I get that.  I was like that for years.  But, after getting to work for the last 5 1/2 years with a friend that I have now known for 16 years, I have seen him operate pretty seemlessly in emacs, without needing to go to the shell that often.  I have seen some pretty cool features that nicely streamlined his workflow.

Its never easy picking up a new tool, that's for sure, especially when you like the features of your current tool, but sometimes you have to make concessions to go farther.  All that said, don't be surprised if you see emacs related posts here, as I am wanting to share what I am learning.

In closing I will provide the two initial links that I am using to start my journey down the emacs path:

Absolute Beginner's Guide To Emacs
Practical Emacs Tutorial


Hopefully, if you decide to also venture down this road, those will help you as well.  I will say that so far, the Absolute Beginner's Guide has been awesome!!


Saturday, May 05, 2018

Setup WiFi to auto-connect regardless of logged in state (UPDATED)

There are plenty of times where I would like to start up my desktop machine (running Ubuntu 16.04 LTS) and just have it boot and me log into it via SSH so that I can get some work done.  Well, in order to achieve that wish, you need to have your wifi connection auto-connnect at boot time.

To do this, there are some things you need to do:

1.  Go to your wifi connection in the upper right of your screen and click on "Edit Connections".
2.  Once in there, you need to click on your connected wifi ssid and select "Edit".
3.  Go to the "General" tab and select "All users may connect to this network".  (without this, the rest of this is moot and it will not work)

Ok, that is the only gui portion of this setup.  Next:

4.  Create the file /etc/wpa_supplicant.conf and add the content that follows:

ctrl_interface=DIR=/var/run/wpa_supplicant group=wheel
network={
  ssid="your_connection_ssid"
  scan_ssid=1
  key_mgmt=WPA-PSK
  psk="password"
}
In the above code, you will input your ssid that you would like to connect to and also enter your password for the connection.  If you are using an encryption method other than WPA/WPA2, then you will need to reference the man page for wpa_supplicant.conf.  There are plenty of examples to help you out. 

After you have that file all setup, save it.

5.  Issue the following command on the command line, as root or with sudo:

wpa_supplicant -B -i wlp4s0 -c /etc/wpa_supplicant.conf

You should see a message that says something to the effect that wpa_supplicant initialization was successful.

After you have completed those steps, go ahead and reboot the machine and watch the login screen.  If all is correct and right with the configuration, you should see the wifi connection show as connected.  You can test this by ssh'ing to the machine.  Enjoy!


UPDATE:  I took the opportunity to reinstall my Linux system to go from Ubuntu 16.04 LTS to Ubuntu 18.04.  I know its a bit extreme to do a full re-install, but:

1.  An distribution upgrade wasn't yet available
2.  There wasn't anything I couldn't re-setup on the machine
3.  Ubuntu moved away from Unity to the Gnome desktop, so I wanted everything clean and fresh.

I will say this though, auto-connection of the wifi (seeing as how you tell it how to connect during installation) just WORKS with Ubuntu 18.04.  You just have to make sure to install the openssh-server package.

Tuesday, May 01, 2018

How to list available versions of a Pypi package

While working on requirements that someone had for a pypi package, I found myself needing to list out the versions of the package that were available.  I didn't want to have to go to the pypi website, navigate to the package and then figure out how to see the available versions.  So, to the Googles I went.

In order to install a specific version of a package, you would run:

pip install =1.0.0

in order to install version 1.0.0 of said package.  But, if you provide nonsense as the option, like so:

pip install =blah

then what you get back is an error listing all of the available versions for that package:


> pip install mod_wsgi==blah
Collecting mod_wsgi==blah
Could not find a version that satisfies the requirement mod_wsgi==blah (from versions: 4.1.0, 4.1.1, 4.1.2, 4.1.3, 4.2.0, 4.2.1, 4.2.2, 4.2.3, 4.2.4, 4.2.5, 4.2.6, 4.2.7, 4.2.8, 4.3.0, 4.3.1, 4.3.2, 4.4.0, 4.4.1, 4.4.2, 4.4.3, 4.4.4, 4.4.5, 4.4.6, 4.4.7, 4.4.8, 4.4.9, 4.4.10, 4.4.11, 4.4.12, 4.4.13, 4.4.14, 4.4.15, 4.4.16, 4.4.17, 4.4.18, 4.4.19, 4.4.20, 4.4.21, 4.4.22, 4.4.23, 4.5.0, 4.5.1, 4.5.2, 4.5.3, 4.5.4, 4.5.5, 4.5.6, 4.5.7, 4.5.8, 4.5.9, 4.5.10, 4.5.11, 4.5.12, 4.5.13, 4.5.14, 4.5.15, 4.5.16, 4.5.17, 4.5.18, 4.5.19, 4.5.20, 4.5.21, 4.5.22, 4.5.23, 4.5.24, 4.6.0, 4.6.1, 4.6.2, 4.6.3, 4.6.4)
No matching distribution found for mod_wsgi==blah

Good to know its that easy.

Sunday, April 29, 2018

python pip throwing SSL: TLSV1 alert (SOLUTION)

I recently ran into an issue with Python pip, where I attempted to run a 'pip install' of a module and was presented with the following error:
> pip install pymongo
Collecting pymongo
Could not fetch URL https://pypi.python.org/simple/pymongo/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) - skipping
Could not find a version that satisfies the requirement pymongo (from versions: )
No matching distribution found for pymongo

No matter what I did (install, update and even just search the pip repository) I was presented with this same error.  It was certainly a hard, fast stop to whatever I was attempting to do.

But, after some googling and reading of many people's accounts of their trials and tribulations attempting to solve it, I finally found a solution that works.  I happened upon the this posting on StackOverflow, which leads you to the fact that you have to upgrade pip.  Unfortunately, attempting to upgrade it with itself will fail as above.  But, you should instead run the following:

curl https://bootstrap.pypa.io/get-pip.py | python

That upgraded pip directly from the website using its install script.  It is a work around, yes, but one that seems to have worked for me (and apparently others).  Hopefully this solves your issue(s) as well.

**UPDATE: You will need to run the curl command in each virtualenv environment that you have, as each one will have its own installation of python.

Saturday, December 16, 2017

'_remove_dead_weakref' error after upgrading to Ubuntu 17.10

Well, after finally getting my Flask app running and returning data, I upgraded my system to Ubuntu 17.10 (from 17.04).  Today, I tried to start my flask app and was greeted with a bunch of Python error output and the following error:

ImportError: cannot import name '_remove_dead_weakref'

I was baffled as the app worked the day before.  So after some digging around the Googles, I found that the issue was caused by my upgrade to 17.10.

The fix....... delete your virtual environment and rebuild it.  I am not saying delete your project directory, I am saying delete your envs directory (which is where the executables for the virtual environment are.  Some people put it in the same directory.  If you are like me, you have a central location where you keep them. 

You will need to remove that entire directory, rebuild it and then re-run the virtualenv command to create the virtualized environment and then install any modules that you had previously installed (as they get stored in the directory structure you just deleted.  After that, your app and its parts should work fine.

Wednesday, December 13, 2017

Starting Out (and pulling my hair out) with Flask

Recently I started learning the Flask web framework.  Mostly because I have been doing a bunch of Python coding and would like that to bleed over a bit into the web development arena.  The need is not really out of anything work-related, its more of a personal project need.

I can say, though, that getting apache and Flask operating together has certainly added a few grey hairs to my head, mostly in frustration.  There are plenty of resources ( if you search the Googles) for setting up Apache web server and Flask, to work together.  But I have to say that, as great as the resources that are out there, are, there are a few (pertinent) details that were left out of most of them that I will now cover.

First, working in a Virtual Environment does not have all of the same settings as not working in one.  If you look at this link, you will see (near the bottom of the document) that there are a couple of things you have to set in your .wsgi file, to specify the load paths for your virtual environment. 
NOTE: It is important to note that that link is the same root site for the Flask link above.  So they definitely have a lot of documentation on their product.

Now, while the above is important, it didn't solve my issue, which is that on a machine remote to where I am running my Flask app and web server, I was not able to go to http://:5000 (the port Flask runs on) and see the page displayed as expected.  Instead I received a typical error page stating that the page could not be loaded.  This got even more frustrating with each new thing that I tried or modified to get it working.  No matter how seemingly possible of a fix, it didn't work.  Until.....

I found a StackOverflow thread about running a Flask app under the Apache web server.  I read the person's question and went through their code (seeing all the similarities) and there it was... a setting that no other site had mentioned.  Not even the video tutorial I was going through.  It was part of my Flask app's __init__.py file and the part in question looks like this:
app.debug = True
app.run(host='0.0.0.0')
The first line is inconsequential and just turns on debug mode.  The second line was 1/2 different from mine, but crucially different.  I had the app.run() that all the tutorial's had mentioned, but I did not have the host='0.0.0.0' portion.  I put it in, started up Flask (by running the __init__.py file) and VOILA!!!  I had the output that I expected to see in my browser. 

Needless to say, it was certainly a learning experience ( as I now have plenty of notes for running a Flask app with Apache).  Now I can get on with my learning of the Framework since the tedious job of getting the web page serving is now out of the way.  Yay!



Wednesday, March 01, 2017

I give you.... PyBlueprint

About 3 years ago (or so), I created a bash script for starting a new Python project.  I was tired of setting up each new project by hand and wanted a quicker way to do it as a time saver.   That endeavor yielded a script that I have used for the last 3 years.

While the script works fine from a bash perspective, I was not yet happy with it in that state.  So, I embarked on re-writing it in Python.  I didn't get the chance to work full force on it right away, but over the last week or so, I have made an immense amount of progress on it.  So much, that I am ready to announce the project for people to download, play with and hopefully enjoy.

Overview:

PyBlueprint's whole purpose is to create a base project directory for new Python projects.  Some of the features that the script has are:

    - Creates project directory for you and populates it with a base set of files (script, README, etc)
    - Initializes a new git repo (or not, if that is your choice)
    - Create a new Github or Bitbucket repository for you to push your code to

I could be over estimating, but I would say that this project saves me about 5-10 minutes of initial project setup so that I can get to coding my projects quicker.

I know that not everyone works in the same manner and we each have our own requirements.  I just ask that if you are a python developer, please give this a shot and see if it works for you.  If there are suggestions, I am open to them, please just open an issue in the project.

Project Link:  https://bitbucket.org/numberwhun/pyblueprint

UPDATE: I realized a short time ago that I still had the repository set to be private.  I have changed it to be a public repo.  Sorry about that!

Wednesday, September 14, 2016

An Update On Combining PDF Files

Back on January 19th, 2009, I wrote a blog post about combining pdf files into one.  This is something I do now and again with one of my hobbies.
When I wrote the aforementioned article, I was only doing this on a Linux server.  Since then I have become an avid Mac user, as well as continuing my love and infatuation with Linux.  On Mac, you have a plenty of the Linux utilities you are used to, but some take some searching, and even then they may not exist or be ported.
In my quest to find an easy way on Mac OSx to combine PDF files, I did run across one.  It is called, believe it or not, "Combine PDFs".  I know, simple name, but believe me when I say that this GUI tool is pretty awesome!  You simply select the files you want to combine and it then not only shows you the order it is putting the in, but it also allows you to preview each page.
The tool is installed using brew on Mac.  If you don't have brew, you'll have to either install it.  If you don't use brew, you can always try to find it for download.  But, I recommend using brew as its pretty handy for obtaining and installing software packages you need and that aren't available through the app store.
If you do use brew, you can install it with the following command:
  brew install Caskroom/cask/combine-pdfs
After that finishes, you will see it in your applications list, as it is a GUI based application.

Enjoy!

 
Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.