Linux tip of the day: temporarily prevent your screen from going to sleep

I just wrote a quick little script to temporarily prevent my screen from going to sleep. Since this has been bugging me for a while, but I only just thought to actually address it, I figured there may be someone out there who can benefit from it also.

I’m not sure whether only people on Arch Linux have this problem sometimes, or Linux users in general, but if you’ve ever had your screen turn off in the middle of a Skype session (sadly we’re all stuck with that program..) or while watching a video in your browser, or during some other full-screen activity that doesn’t automatically turn off your power saving settings, this might be just what you need.

if [[ $1 =~ ^0$ ]]; then
xset s on +dpms
echo "No longer preventing screen sleep"
killall $(basename $0)
exit 0
elif ! [[ $1 =~ ^[0-9]+$ ]]; then
echo "example: $(basename $0) 60 ==> prevent sleeping for 60 minutes"
echo "example: $(basename $0) 0 ==> revert to default settings"
exit 1
xset s off -dpms
echo "Preventing screen sleep for $1 minutes"
(sleep ${1}m && xset s on +dpms) &

Read More

git undo

In spite of the title of this post, there is no git undo command, but I bet many among us wish there was one (given that it could read our minds)! I for one keep having to look stuff up every time I screw up and have to undo something. Was it reset? revert? checkout --??

Luckily, I found this very handy article in a book about git the other day. If you did a git oops and need to recover, go read the article! But just for my own (and perhaps your) future reference, here are (some of) the different undo commands collected in one small post (dangerous commands may result in losing code if used incorrectly):

# to unstage a file:
git reset HEAD <file>
# to undo changes and go back to the latest commit (dangerous!):
git checkout -- <file>
# to add a file you forgot to stage to the previous commit:
git add <file> && git commit --amend
# to go back x amount of commits (dangerous!):
git reset HEAD~<x>
# to go back x amount of commits and create a new commit:
git revert HEAD~<x>

Do read the article I linked above before messing with your git tree and checkout this one too for more information about the differences between reset and revert.

How to rename a published npm module

Two months ago, I wrote a small plugin for the static site generator Hexo. It allowed users to edit posts more conveniently from the command line so I called it hexo-easy-edit.

Today I added another feature to the plugin, and I realized that the name no longer reflected all that it does. So I renamed the project to hexo-cli-extras. However, this turned out to be a little more involved than I originally thought because of the way npm works.

npm logo

Read More

Do yourself a favor and modularize your .vimrc/init.vim

I spend quite a bit of time reading various blogs and forums frequented by vim/neovim users. Of course the topic of the .vimrc (or init.vim if you’ve switched to the new neovim style) file comes up all the time in such circles and I’ve learned a huge deal from looking at (and stealing parts of) other people’s configuration files.

Organized tools

That said, I am often baffled by the lack of organization in people’s config files. More often than not it’s a total mess, but even when the file has been carefully commented and organized, it’s almost always just one file.

Read More

New Year's resolutions and predictions

Woo, it’s been about two weeks since my last post! Not good, not good.. All I can say is, I enjoyed my time off, but I’m back and feeling great!

So the holidays have come and gone and 2016 is upon us. Time for some New Year’s resolutions and a few educated (?) guesses as to what this year may have in store for web development, JavaScript, Linux and me in particular.

Read More