From List Comprehensions to Generator Expressions

September 28, 2014 Leave a comment

From List Comprehensions to Generator Expressions
List comprehensions were added in Python 2.0. This feature originated as a set of patches by Greg Ewing with contributions by Skip Montanaro and Thomas Wouters. (IIRC Tim Peters also strongly endorsed the idea.) Essentially, they are a Pythonic interpretation of a well-known notation for sets used by mathematicians. For example, it is commonly understood that this:

{x | x > 10}

refers to the set of all x such that x > 10. In math, this form implies a universal set that is understood by the reader (for example, the set of all reals, or the set of all integers, depending on the context). In Python, there is no concept of a universal set, and in Python 2.0, there were no sets. (Sets are an interesting story, of which more in a future blog post.)

This and other considerations led to the following notation in Python:

[f(x) for x in S if P(x)]

This produces a list containing the values of the sequence S selected by the predicate P and mapped by the function f. The if-clause is optional, and multiple for-clauses may be present, each with their own optional if-clause, to represent nested loops (the latter feature is rarely used though, since it typically maps a multi-dimensional entity to a one-dimensional list).

more…

Source:
The history of python

Virtualenv

September 27, 2014 Leave a comment

Problem:

I had to work with different versions of django and having system wide installs would not work. I needed a clear demarcation between all versions.

Solution:
virtualenv is a tool to create isolated Python environments.

Source:

http://virtualenv.readthedocs.org/en/latest/virtualenv.html

PulseAudio – No sound on laptop

September 11, 2014 Leave a comment

Problem:
I was having a flaky sound problem. I could reboot my machine and not get any sound when playing videos via vlc or mplayer. Other times it would work. I eventually broke it and even with multiple reboots and prayers I was not getting any sound. Granted this all happened when I started messy around trying to install software that would allow me to convert mp4 videos to simple audio. (Dropped that project though since I now had bigger problems).

Debian Testing initially did not come installed with pulseaudio… I installed this due to skype. That is another issue explained here. So here is how I finally managed to get back my sound.


Solution:

I reinstalled pulseaudio (not sure if you need all these files but I was pretty desparate at this stage and just copying stuff of the internet. See source below.)

As root

apt-get install pulseaudio libao4 paprefs libpulse-mainloop-glib0 pulseaudio-module-jack pavucontrol pulseaudio-module-x11 gstreamer0.10-pulseaudio pulseaudio-utils libasound2-plugins paman pulseaudio-module-gconf libgconfmm-2.6-1c2 pavumeter libglademm-2.4-1c2a pulseaudio-esound-compat libpulse0 libpulse-dev pulseaudio-module-bluetooth pulseaudio-module-zeroconf

Then installed mate-volume-control using synpatic.

From the bash prompt I had a look at my sound settings

$ mate-volume-control

If you still have an issue with pulseaudio then mate-volume-controller will not open up. You will get the following window. It was here that I noticed that my volume was on mute. Once I un-muted, my sound was back.

Extra:

Since I use fluxbox I added mate-volume-control-applet to the startup script.

# Applications you want to run with fluxbox.
# MAKE SURE THAT APPS THAT KEEP RUNNING HAVE AN ''&'' AT THE END.
#
# unclutter -idle 2 &
# wmnd &
# wmsmixer -w &
# idesk &
  nm-applet &
  xscreensaver &
  mate-power-manager &
  mate-volume-control-applet &
  nitrogen --restore &

Source:
http://forums.debian.net/viewtopic.php?t=12497

Skype – No sound/audio when making a test call

September 11, 2014 Leave a comment

Problem:

So finally managed to install skype 4.3 on 64bit Debian Testing. Next hurdle was that I could not make a skype call as the other party could not hear me. Selecting Options->Sound Devices->Make a Test Call would result in nothing getting recorded.

Solution:
Install pulseaudio and mate-volume-controller.

So most noticible effect was that now every time skype starts up you get all the moans and groans, but still “Make a Test Call” does not play back my voice.

In skype go to Sound Devices

Skype Sound Devices

Skype Sound Devices

Click on “Open PulseAudio Volume Control”

Volume Control

Volume Control

Make sure that the internal microphone is not muted. Once I unmuted mine. I redid the skype test call and it played back my voice.

nitrogen – Setting wallpapers

September 7, 2014 Leave a comment

Problem:
Needed to setup a wallpaper on fluxbox and it needed to appear on one or two screens.

Solution:
Installed nitrogen. (Esetroot just did not work nicely for me. YMMV)

(as root) apt-get install nitrogen

Set up your preferred wallpaper using nitrogen.

$ nitrogen

nitrogen

nitrogen


Click “Preferences” and select the folder with the wallpapers. Then pick the wallpaper you want for a fullscreen or selective screens.

Nitrogen settings

$less ~/.config/nitrogen/bg-saved.cfg
[xin_0]
file=/home/rodnee/Pictures/wolves_wide.jpg
mode=0
bgcolor=#000000

[xin_1]
file=/home/rodnee/Pictures/wolves_wide.jpg
mode=0
bgcolor=#000000
.config/nitrogen/bg-saved.cfg (END)

Now all that was left was to configure fluxbox

Add nitrogen –restore to ~/.fluxbox/startup

# Applications you want to run with fluxbox.
# MAKE SURE THAT APPS THAT KEEP RUNNING HAVE AN ''&'' AT THE END.
#
# unclutter -idle 2 &
# wmnd &
# wmsmixer -w &
# idesk &
  xscreensaver &
  mate-power-manager &
  nitrogen --restore &

Added the following two lines to ~/.fluxbox/init

session.screen0.rootCommand:    nitrogen --restore
session.screen1.rootCommand:    nitrogen --restore

That was it.


Update (11th September 2014)

Above settings would work like a charm when I had a monitor plugged in. But the new wall paper would not take effect otherwise. To fix this I simply ran nitrogen again and picked the desired wallpaper. The nitrogen config file now looks like this

$less ~/.config/nitrogen/bg-saved.cfg
[xin_0]
file=/home/rodnee/Pictures/wolves_wide.jpg
mode=0
bgcolor=#000000

[xin_1]
file=/home/rodnee/Pictures/wolves_wide.jpg
mode=0
bgcolor=#000000

[:0.0]
file=/home/rodnee/Pictures/wolves_wide.jpg
mode=0
bgcolor=#000000
.config/nitrogen/bg-saved.cfg (END)

Now my wallpaper is set whether or not a monitor is plugged in.

JLSN – Reconfiguring time zone

August 25, 2014 Leave a comment

Problem:

I needed to change my timezone. Currently using debian testing 7.6 (amd64).

Solution:
As root run

root> dpkg-reconfigure tzdata

Interesting – geek and poke

August 8, 2014 Leave a comment

Understandability

Categories: geek and poke, Interesting
Follow

Get every new post delivered to your Inbox.

Join 37 other followers