Have you ever pasted text from Google Docs onto your blog (WordPress or otherwise) and had to fix wacky formatting? Here is how to quickly strip out all those extra HTML tags using regular expressions with Atom.io, a free text editor.
Links:
Atom, a free text editor available on Windows, Mac, and Linux: http://atom.io
I’ve been on vacation and spend the last two days catching up and not doing a lot of learning, so I’ve been lazy in putting up TIL posts. That is over. (I did, however, push some updates to my Apple Photos Analysis project.) Here is a small collection of things I learned in the last week.
Amending commits
Say you forgot to add a file to your last commit or you made a typo in your commit message. You can amend it!
Make the necessary changes, then do this:
git commit --amend-m"Commit message here"
If you’ve already pushed it to an external repository, you’ll need to force the push since the external repo will look like it is ahead. If branch protection is turned on, you’ll need to make a new commit. Make sure you aren’t overwriting anything important!
Adding data labels to the top of bar charts in Matplotlib
Matplotlib is a great plotting library for Python.
defautolabel(rects):# attach some text labels forrectinrects:height=rect.get_height()plt.text(rect.get_x()+rect.get_width()/2.,5+height,'%d'%int(height),ha='center',va='bottom')rect=plt.bar(xs,counted_hours,color=color)# To use: autolabel(rect)
Saving images in matplotlib
plt.savefig('directory/filename.png')
Counting items that match a regex pattern
defhour_finder(regex,lines):time_counter=0forlinlines:ifre.match(regex,l):time_counter=time_counter+1returntime_counter# To use hour_finder('^8:[0-9]{2,}:[0-9]{2,}sPM',time_csv)
Splitting!
Splitting by a space ' ' and choose the item after the split ([1] because counting starts at 0)