So I’ve been struggling a bit with finding an easy way for me to make my code examples look a little bit prettier when posting.
There’s only so many hours in the day and I just haven’t found the time to really dig into the best tool, theme, CSS, java script or some other cool way to make my code more readable in blog posts.
I recently stumbled across a cool little trick between GITHUB and WordPress that makes this little annoyance go away, at least for the mean time. ***(If you’ve got suggestions or a better way, please post in the comments!)***
Essentially you create a GIST on the GitHub site. A GIST is essentially just another GITHUB repository and they can be cloned, forked, etc… The nice thing is you can actually make the GIST public, allowing others to find your work, or create a secret GIST which means that only those with the URL can access it.
Once you’ve done that, you simply paste the URL into your wordpress blog. As long as you don’t paste it in as clear text and not as a embedded hyperlink. If all you get is the URL, then you probably got it wrong.
But if you got it right….
|''' This function prompts user for IMC server information and credentials and stores|
|values in url and auth global variables'''|
|global url, auth, r|
|imc_protocol = input(|
|"What protocol would you like to use to connect to the IMC server: \n Press 1 for HTTP: \n Press 2 for HTTPS:")|
|if imc_protocol == "1":|
|h_url = 'http://'|
|h_url = 'https://'|
|imc_server = input("What is the ip address of the IMC server?")|
|imc_port = input("What is the port number of the IMC server?")|
|imc_user = input("What is the username of the IMC eAPI user?")|
|imc_pw = input('''What is the password of the IMC eAPI user?''')|
|url = h_url + imc_server + ":" + imc_port|
|auth = requests.auth.HTTPDigestAuth(imc_user, imc_pw)|
|test_url = '/imcrs'|
|f_url = url + test_url|
|r = requests.get(f_url, auth=auth, headers=headers)|
|# checks for requests exceptions|
|except requests.exceptions.RequestException as e:|
|print("Error:\n" + str(e))|
|print("\n\nThe IMC server address is invalid. Please try again\n\n")|
|if r.status_code != 200: # checks for valid IMC credentials|
|print("Error: \n You're credentials are invalid. Please try again\n\n")|
|print("You've successfully access the IMC eAPI")|
Hope this helps someone else!