Tag Archive: Linux


I updated the toggle-work-mode program for a week ago, and now the blog post. You can find it here: http://blog.senth.org/2011/12/toggle-work-mode-turn-off-distracting-things-during-work/

The old invalid text has strike-through, whereas the new is underlined. All scripts are updated.

I have the problem that I don’t go to sleep when I should. If I have a task that I want to finish and it is almost done, I continue with it and suddenly 3—4 hours has gone. This also holds true if I read interesting articles on the Internet; I just want to find more of these articles and learn more about the topic.

In the end, I got tired of lacking the discipline for going to bed in time. I decided I would create a program that forces me to go to bed, i.e. shuts down the computer at a time of my choice (10pm).

I made the program first for Linux, then the program for Windows since my lovely girlfriend thought such a program would be nice to have. The Linux version is a simple script that, at the moment, only works for KDE; there also exists an option to use brute force “shutdown -h now” to shutdown the system, although you will not be able to see any warning messages this way. If anyone implements a version for Gnome, or rather Ubuntu, to use their message system, send a patch and I will update this post :) The Windows version is a bit more complex, you can specify an argument: how long time before you should get messages; if you don’t specify any argument it defaults to 15 minutes. This time is also what the Linux version uses, and cannot be changed in the current version.

I will stop using this program in a month or two. I use it as a push in the right direction, for creating an good habit: going to bed at the same time everyday. Before the program was set to activate on Sunday–Thursday—setting the time to 11pm on Sundays. Last week I changed this to 10pm everyday, as I wanted to keep my habit over the weekends. This does not mean I will actually go to bed at 10pm, it means I shutdown my computer at that time; then, when I’m feeling tired, I go to bed, except on weekends when I might be doing something with my friends.

Linux

The code might not be optimal or pretty—I usually want to write (pretty) code—but it does the job. It takes one required argument, the environment, which can be kde, gnome, or system depending on how you want to display warning messages and in what way you want to turn off the computer. For convenience the code for both the Linux and the Windows version are listed in the end.

Installation

  1. Download the script here: shutdown_15min.tar.
  2. Untar it.
  3. Put the script anywhere.
  4. Decide which time(s) you want the computer to shutdown.
  5. run: “crontab -e” and specify which time(s) you want to use, but decrease the time with 15 minutes since it will display messages for 15 minutes before it actually shutdowns the computer. Consult crontab manual for how to do this. Note, if you want to stop the system using “shutdown -h now” it will need to be run as root, meaning run “sudo crontab -e” instead.

Windows

You do not have to download the code, only the exe file and the library. The program could have been made better, like showing the time left in minutes and seconds when you click on the icon—but I have stopped over-engineering in code, I do what I need to and only more if it does not take a lot of time.

Installation

  1. Download the zip file here: Shutdown Timer.
  2. Unzip.
  3. Move the Shutdown Timer folder to (System drive, probably C:) C:\Program Files (x86)\
  4. Start scheduler, found in programs.
  5. Create a new event.
  6. Decide which time you want to shutdown the computer. Be sure to set the time 15 minutes before (or more/less if you change the time in the next step).
  7. Browse for the program, and enter an optional argument if you want warning messages to popup earlier or later.

Click to see the source code

Do you usually keep your email/chat notifications on during work or study? So did I, until recently.

I have been reading “Eat that Frog” by Brian Tracy for a while (which I strongly recommend everyone to read); in his book he mentions that you should remove distracting elements to work more efficiently. In addition I have been seeing that statement on various blogs about working more efficiently (workawesome.com, lifenotion.com, deepexistence.com, lifeoptimizer.org); after reading that removing distracting elements are really important from all these various sources I decided that I should actually try it. It took me a while to test it though—I didn’t think it drained so much time as it did. But the single reason I didn’t want to turn off “everything” was that I always wanted to be available for others.

Here was my train of thought and a bit of analysis:
Do everyone actually need to be able to contact me directly all the time? Do I need to answer and check email directly? It didn’t take long to figure out that: No, most of the things can actually wait. I should not need to rearrange my time so that it works for everyone else. Note, although I did turn off email notification and chat messaging, people could still call me—meaning if something was really important, that could not wait, they could call me.

The next step was to analyze if it actually took time from studying etc. I thought of all the times I had been interrupted the last week. When I got an email I got an notification in both the smartphone and on my computer; I quickly check it and sometimes had to write a reply message. Being me, a regular yes or no usually don’t suffice and I always proofread my emails, before sending it. This takes time and usually by the time I’m done I’m not in the mood to continue working with what I did before.

For messaging, I am usually contacted regarding questions. Some chats were short—only lasting seconds—whereas others where longer—an hour or two, usually with my girlfriend :P . I don’t blame my girlfriend though for messaging me, I blame myself for having the messaging on so that she could contact me, and that I did not have any status message saying I’m busy.

The conclusion: I lost in average 1.5 hours each day—where some days I lost 4 hours, where some I did only lost a couple of minutes. This was the actual time I lost due to doing other things, in addition to that time I lost momentum and had to rebuild it.

Okay, I loose efficiency when I have notifications and messaging on. How did I solve it?

We begin with the notifications on the phone. I have an Android phone, and there exists a great program called Llama (as the animal). With it you can enable/disable features on the phone depending on some events—in this case I used it when an calendar event begins and ends. I use Google Calendar and I have all my day planned in more or less detail—when I should study, eat, go to the store, play games, and so forth. Combining these two, when an Study or Work calendar event begins, it automatically disables Internet on my phone, meaning I can’t get any email notifications and people can’t contact me through g-talk. When the calender event finishes it turns on Internet again. Very convenient to use.

For programs on the computer, I disabled email notifications altogether. If I get them on my phone, that is enough. Then I made a script (found at the bottom of the page) that kills messaging programs and then starts them again. This has to be done manually, I thought of also using my Google Calendar here, but that would be too much of a hassle, and take too much time. Instead I press an icon, it runs a script and kills the programs, then I press another icon to run the same script but with other parameters to start the programs again. This script can also disable homepages, e.g. Facebook and Google Plus.

It took approximately three hours to implement this script; by the next day I had already regained that “lost” time.

In just those two days I noticed that I was much more concentrated on the work that I did, nothing ever distracted me. I don’t know if I can say that I worked twice as efficient because I did not measure it, but it at least felt that way.

For the others that want the script; I implemented it for Linux, and specifically for Gentoo. If you using another distribution you might need to change some things. The progarm can only handle one user per system, since the programs are specified globally for all users and not locally for each users. I know how to change this and it will only take an hour or two, but I don’t need it so I won’t bother. If you feel that you need that functionality either you can email me that you would like me to implement it, or email a patch to change how the script works :)

UPDATE 2012-02-03: I have fixed this now, some programs did not start correctly when they were started via sudo. No programs starts and dies directly when you run the script, the dns addresses will still be blocked after 0–30s (if nothing else is specified).

You can checkout the script using svn and this address: svn://senth.org/senth/mini-projects/toggle-work-mode/tags/v0.2

Here are the four five script files (all have the same name, but are located in different places), some have the same file, but all are placed in different directories. You shall notice that the file in user home has a weird file name; be sure to rename it to only .toggle-work-mode-settings :)

If you want to use the program (scripts) I suggest downloading them using svn.

Click to see the source code…

As you might know there’s a certain program that comes with the nVidia drivers in linux, nVidia powermizer. It scales the GPU accordingly if you have the computer connected to an AC-adapter or not for laptops. I don’t know how it scales on desktop computers and I wanted more control over the scaling so I created my own script. What I wanted was that the GPU would scale up/down automatically when the load started to increase/decrease respectively. nVidia has a program where you can query the GPU load nvidia-smi, however in recent drivers, support for regular graphics card was removed (why :( ).

After some thinking and tinkering I came up with a solution—maybe not the best, but it works—that scales the GPU depending on if a (demanding) program is running or not; i.e. you specify a list of programs, if any of those are running the GPU will be clocked to high load else the GPU will stay in low load state. You can specify how much—in either percentage or key words—the GPU should scale in each of the two state; you can even overclock it by specifying 110 (percent). There is a thorough description how you configure it in conf.d/nvidia-gpu-scale

Limitations

  • The script can only scale one GPU at the moment. If you have several GPUs you need to modify the script, which you are more than welcome to do.
  • Due to the fact that you need an active display—i.e. an X server running—this script will not modify the clock frequencies if no X server is started. Note if an X server isn’t running it will poll every 30s to check if one is running; if one is it will change state and poll every second for the programs.

Essential files

  • conf.d/nvidia-gpu-scale Configuration for the nvidia-gpu-scale init.d script. In this file you can specify which programs to look for, how much it should clock the GPU to in low load and high load and what GPU and DISPLAY to apply these clocks on. You can find all the necessary information in the file.
  • init.d/nvidia-gpu-scale Initialization script for nvidia-gpu-scale. Available commands are start and stop
  • bin/nvidia-gpu-scale The core program. You should always start/stop the script through init.d/nvidia-gpu-scale start/stop

Installation
I use a gentoo distribution and ‘we’ have a /etc/conf.d/ directory which is a configuration folder for the init scripts. I know this directory doesn’t exist on every distribution but they probably have a similar directory. If you can’t find it, just add the configuration to the top of the init script and that should work fine.

  1. Move bin/nvidia-gpu-scale to /usr/bin/nvidia-gpu-scale
  2. Move init.d/nvidia-gpu-scale to /usr/bin/nvidia-gpu-scale
  3. Move conf.d/nvidia-gpu-scale to /usr/bin/nvidia-gpu-scale, if you have this directory else move it to the corresponding directory.
  4. Make sure both /usr/bin/nvidia-gpu-scale and /etc/init.d/nvidia-gpu-scale has the right modification flags and user privileges. Copy this command if you don’t know for sure: sudo chmod 775 /usr/bin/nvidia-gpu-scale /etc/init.d/nvidia-gpu-scale && sudo chown root:root /usr/bin/nvidia-gpu-scale /etc/init.d/nvidia-gpu-scale
  5. Make sure conf.d has right privileges: sudo chmod 664 /etc/conf.d/nvidia-gpu-scale
  6. Optional If you want the script to autostart run this command (maybe only works in gentoo): sudo rc-update add nvidia-gpu-scale default

N.B! Use nvidia-gpu-scale on your own risk; it could damage your GPU, especially if you overclock it!

You can find the program here: nvidia-gpu-scale 0.1.tar.gz