f.lux and redshift: Solutions for computer induced eye strain and sleep disorder

Night-time exposure to blue light keeps people up late. Experimental research suggests that an average person reading on a tablet for a couple hours before bed may find that their sleep is delayed by about an hour. In 2012, the American Medical Association’s Council on Science and Public Health made this recommendation:

Recognizes that exposure to excessive light at night, including extended use of various electronic media, can disrupt sleep or exacerbate sleep disorders, especially in children and adolescents. This effect can be minimized by using dim red lighting in the nighttime bedroom environment.

F.lux

f.lux adjusts colors in a way that greatly reduces the stimulating effects of blue light at night. f.lux changes the color temperature of your display. Natural light is more blue, while most artificial light (including candlelight) is warmer. Incandescent bulbs, which we’re all used to, become more red in tone when you dim them. But newer LEDs and CFLs don’t – this includes the backlight on your monitor.

The term color temperature is a way to numerically describe how much red or blue light is illuminating a room. Color temperature is measured in Kelvins, and is determined by the kind of light you’re using. Confusingly, warmer (more red) light sources are described in lower degrees Kelvin. Compared to indoor lighting, daylight is cool – very blue. A candle is around 1800K, while a sunny day might be 6000K. An overcast day is more blue, so it might be around 7000K. Most computer monitors display around 6500K. If you are using incandescent task lights behind your computer, those are around 3000K.

During the daylight hours, f.lux keeps your monitor relatively cool with a default color temperature of 6500K. Your brain tends to associate blue light with daylight. At night, f.lux dials down the color temperature to a warmer, more yellow glow (3400K). You can also choose from presets:
Ember: 1200K
Candle: 1900K
Warm Incandescent: 2300K
Incandescent: 2700K
Halogen: 3400K
Fluorescent: 4200K
Daylight: 5500K
or adjust the settings to another specific preference. In general, the yellower the light, the less straining it is on your eyes. f.lux support kelvin color between 2000-10000K.

The best way to set f.lux is to adjust it in the environment you usually work in during the day and night. First, bring up a blank white text screen and adjust the color temperature of your display by trying to match the color of a white wall in the room. Once they match in both lighting environments, you’re on your way to much happier eyes.

Installing f.lux on Ubuntu 13.10

sudo add-apt-repository ppa:kilian/f.lux
sudo apt-get update
sudo apt-get install fluxgui

How to use

Find latitude and longitude of your location using http://justgetflux.com/map.html
Syntax:

xflux -l <latitude> -g <longitude> -k <color temparatature in Kelvin, default 3400>

Example:

$ xflux -l 23.70 -g 90.40
--------
Welcome to xflux (f.lux for X)
This will only work if you're running X on console.

Your location (lat, long) is 23.7, 90.4

Your night-time color temperature is 3400
It's night time. Your screen is changing now.
Going to background: 'kill 24712' to turn off.

Turn off f.lux

$sudo killall xflux

Redshift

You can also check out Redshift which is an open source application that does the same thing, its development was inspired by f.lux. As of Jan 4, 2014 the current version is 1.8.

Installing redshift 1.8 on ubuntu 13.10:

1. Download and extract redshift 1.8 in desired folder.
2.

./configure
make
sudo make install

3. Create redshift.conf in ~/.config folder, example is given here, also providing my one below:

; Global settings for redshift
[redshift]
; Set the day and night screen temperatures
temp-day=5700
temp-night=3600

; Enable/Disable a smooth transition between day and night
; 0 will cause a direct change from day to night screen temperature. 
; 1 will gradually increase or decrease the screen temperature
transition=1

; Set the screen brightness. Default is 1.0
;brightness=0.9
; It is also possible to use different settings for day and night since version 1.8.
brightness-day=0.8
brightness-night=0.5
; Set the screen gamma (for all colors, or each color channel individually)
gamma=0.8
;gamma=0.8:0.7:0.8

; Set the location-provider: 'geoclue', 'gnome-clock', 'manual'
; type 'redshift -l list' to see possible values
; The location provider settings are in a different section.
location-provider=manual

; Set the adjustment-method: 'randr', 'vidmode'
; type 'redshift -m list' to see all possible values
; 'randr' is the preferred method, 'vidmode' is an older API
; but works in some cases when 'randr' does not.
; The adjustment method settings are in a different section.
;adjustment-method=randr
adjustment-method=vidmode

; Configuration of the location-provider:
; type 'redshift -l PROVIDER:help' to see the settings
; ex: 'redshift -l manual:help'
[manual]
lat=23.7
lon=90.4

; Configuration of the adjustment-method
; type 'redshift -m METHOD:help' to see the settings
; ex: 'redshift -m randr:help'
; In this example, vidmode is configured to adjust screen 1. 
; Note that the numbering starts from 0, so this is actually the second screen.
[vidmode]
screen=N
;[randr]
;screen=N

4. run redshift

$/usr/local/bin/redshift &

Some awesome linux command line tricks on bash

1. Runing the last command as Root

 sudo !! 

(!! repeats the last command)

2. Run your previous command with replacing “foo” with “bar”

^foo^bar

Example:

$ ehco foo bar baz
bash: ehco: command not found
$ ^ehco^echo
foo bar baz

Or alternatively you can use the below command:

!!:gs/foo/bar

3. the command-line equivalent of the back button

cd -

(It’s worth mentioning that ‘cd’ takes you to your home directory)

4. Insert arguments from you last bash command

ESC + ‘.’

Inserts the last arguments from your last bash command. It comes in handy more than you think.

cp file /to/some/long/path

cd ESC + '.'

5. bulk rename

Example:

$ ls
this_has_text_to_find_1.txt
this_has_text_to_find_2.txt
this_has_text_to_find_3.txt
this_has_text_to_find_4.txt

$ rename 's/text_to_find/been_renamed/' *.txt
$ ls
this_has_been_renamed_1.txt
this_has_been_renamed_2.txt
this_has_been_renamed_3.txt
this_has_been_renamed_4.txt

6. Renaming/moving files with suffixes quickly:

cp /home/foo/realllylongname.cpp{,-old}

This expands to:

cp /home/foo/realllylongname.cpp /home/foo/realllylongname.cpp-old

7. List only subdirectories in the current one

 ls -d */

8. Reverse search

^R reverse search. Hit ^R, type a fragment of a previous command you want to match, and hit ^R until you find the one you want. Then you don’t have to remember recently used commands that are still in history.

9. Selected bash keyboard shortcuts

Ctrl-U – Cuts everything to the left
Ctrl-W – Cuts the word to the left
Ctrl-Y – Pastes what’s in the buffer
Ctrl-A – Go to beginning of line
Ctrl-E – Go to end of line

10. Running a second command with the same arguments as the previous command

use ‘!*’ to repeat all arguments or ‘!:2’ to use the second argument. ‘!$’ uses the final argument.

$ cd /home/user/foo

cd: /home/user/foo: No such file or directory

$ mkdir !*

mkdir /home/user/foo

11. Get an ordered list of subdirectory sizes

This piece of code lists the size of every file and subdirectory of the current directory, much like du -sch ./* except the output is sorted by size, with larger files and directories at the end of the list. Useful to find where all that space goes.

du -sk ./* | sort -n | awk 'BEGIN{ pref[1]="K"; pref[2]="M"; pref[3]="G";} { total = total + $1; x = $1; y = 1; while( x > 1024 ) { x = (x + 1023)/1024; y++; } printf("%g%s\t%s\n",int(x*10)/10,pref[y],$2); } END { y = 1; while( total > 1024 ) { total = (total + 1023)/1024; y++; } printf("Total: %g%s\n",int(total*10)/10,pref[y]); }'

12. Use ALT+. to insert last parameter

In bash (or anything using libreadline, such as mysql) press ALT+. to insert the last used parameter from the previous line.

Eg:

$ vim some/file.c
$ svn commit ALT+.

Ref:

1. shell-fu.org top 25 commands
2. commandlinefu.com all-time greats
3. snipt.net public snipts

Vim tip: How to fix Python exception IndentationError

The problem is usually with mixup in tabs and spaces –

Solution 1

1. Apply following command in Vim to highlight tabs, spaces and other whitespace differently.

:set listchars=tab:>-,trail:-,eol:$ list

2. Apply the following to set correct width

:set shiftwidth=4 tabstop=4 expandtab 

3. running

:retab

to fix the problem,Vim automatically fixes all indentation space and tab mix ups.

Solution 2

1. set ‘list’, so that you can see the whitespace and change.

Have the following mapping in .vimrc for this:

nnoremap    <F2> :<C-U>setlocal lcs=tab:>-,trail:-,eol:$ list! list? <CR>

2. Ensure ‘expandtab’ is reset, check using following command –

:verbose set ts? et? 

3. To expand all leading spaces (wider than ‘tabstop’), use retab.

retab takes a range, so specify % to mean “the whole file”.

:set tabstop=4      " To match the python file
:set noexpandtab    " Use tabs, not spaces
:%retab!            " Retabulate the whole file