Friday, June 16, 2017

Make selinux play nicely with certs

During certs upgrades, I noticed that my new cert was not getting accepted, i.e. my application was unable to read it even though owner and permission were set correctly.
The root cause of the problem was Selinux... it detected that I changed the cert and was preventing it from being read as malicious?

So I had to issue following command for it to accept it.

# restorecon -RvF /etc/pki/tls/private/jira.key
restorecon reset /etc/pki/tls/private/jira.key context unconfined_u:object_r:user_tmp_t:s0->system_u:object_r:cert_t:s0

Thursday, June 15, 2017

Ejecting harddrive should not be this hard...

Ever got annoyed with the message that your external harddrive can't be ejected since something is using it?

Well... I ran into it many many time... and now that I am on my fav mac I decided to find out what was going on vs just force ejecting it.

So... I ran

sudo lsof | grep /Volumes/Ultimate/

where Ultimate is my external harddrive name...

it showed me bunch of stuff to my surprise!

back up.... lsof is a command to show you a list of open files on the disk

# lsof

COMMAND  PID       USER   FD      TYPE     DEVICE  SIZE/OFF       NODE NAME
init       1       root  cwd       DIR        8,1      4096          2 /
Now... I saw bunch of Spotlight commands... so my mac decided to index my ext harddrive... To fix that I selected System Preferences -> Spotlight and added ext harddrive to Privacy pane.

Next I had bunch of BDLDaemon commands... so it appears that it was my BitDefender trying to protect me and scanning my ex harddrive... well... i chose to let it finish just to make sure i did not have any virus, etc on my drive...

The end





Tuesday, June 13, 2017

Pandas DataFrame pretty print

Recently while trying to output dataframe as a part of my logging process, I saw that dataframe, while being relatively small, was broken down over several lines... For ease of the log reading, I wanted to "pretty print" that dataframe.

I end up specifying max width option that allowed for desired output.

    pd.set_option('display.width', 1000)
    print meta_data
    pd.reset_option('display.width')

Monday, June 12, 2017

Troubleshooting your mac...

just a list of what I did before to troubleshoot and fix your mac issues

Restart and hold Shift key to enter Safe Mode

Restart + CMD + R to diagnose your harddrive, update OS, or reinstall OS... or use time machine to get to a prev working state.


Friday, May 26, 2017

How to finding what methods Python object has

[method for method in dir(Python_Object) if callable(getattr(Python_Object, method))

Saturday, May 20, 2017

Create a bootable USB flash media drive from Mac OSX

First download your desired .img / iso file to be written on the drive.
Open a Terminal (under Utilities)
Run the following command to get the current list of devices
diskutil list
Insert your flash media
Run the diskutil list again and determine the device node assigned to your flash media (e.g. /dev/disk2)
Run
diskutil unmountDisk /dev/diskN
then execute
sudo dd if=/path/to/downloaded.img of=/dev/diskN bs=1m
finally run
diskutil eject /dev/diskN
and remove your flash media when the command completes


Monday, May 1, 2017

Validate your download

On many sites that offer some type of downloadable file you can often find a very long number sometimes labeled as SHA1Sum.... what is it and how do you use it?
SHA1Sum is basically a hash taken of the file... the hash is not an encryption or anything of that sorts, but what its purpose is to provide a way to generate hash representation of the file. For example, if you have a text file and you take a hash of it, and then change even one comma in that file, the hash that would be produced would be totally different!
This way you can always validate if two files are identical or not.

So how do you do it?
First, download the file (your_file)

Secondly, generate its hash on you system and save it to the hashstring file
sha1sum your_file > hashstring

Then copy the hash of the file from the website that lists it

Finally, use grep to compare the hash that you produced to that from the site (unless you want to compare it one character at the time)
cat hashstring | grep hash_copied_from_site