Archive for January, 2010

Python script to learn Chinese tones

Thursday, January 28th, 2010

I wrote a script to learn to distinguish between the Chinese tones. It’s not very useful without the corresponding multimedia (ie: recordings I got my gf to make), but maybe with script in hand, others can easily make their own such multimedia?

The script plays a sound, eg ‘dianhua’, then presents two possibilities for the user to choose between, eg the dianhua meaning ‘stippled painting’, or the dianhua meaning ‘telephone’.

There are three parts to the script:
- testdiff.py : the script, in Python
- testdiff.xml: configuration file, where you specify each test, the sounds for each test, and a corresponding text description
- the sound files, in a subdirectory ‘sounds’

Sample configuration file:

<root>
<tests>
<test>
<choice sound="几点.mp3" text="几点 jī diăn (what time is it?)" />
<choice sound="机电.mp3" text="机电 jī diàn (electrical machine)" />
</test>
<test>
<choice sound="忌惮.mp3" text="忌惮 jì dàn (fear)" />
<choice sound="鸡蛋.mp3" text="鸡蛋 jī dàn (egg)" />
</test>
</tests>
</root>

testdiff.py python script, gpl v2:

#!/usr/bin/python

# Copyright Hugh Perkins 2010
# hughperkins@gmail.com http://manageddreams.com
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
#  more details.
#
# You should have received a copy of the GNU General Public License along
# with this program in the file licence.txt; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-
# 1307 USA
# You can find the licence also on the web at:
# http://www.opensource.org/licenses/gpl-license.php
#
# ======================================================================================
#

import sys
import os
from elementtree.ElementTree import ElementTree
import random
import subprocess
import time

def playSound( soundfilepath ):
	popen2 = subprocess.Popen(['playsound',soundfilepath], stdout=subprocess.PIPE)
	popen2.wait()

def runTest():
	print "Next test:"

	config = ElementTree(file='testdiff.xml')
	numtests = 0
	for test in config.findall('/tests/test'):
		numtests = numtests + 1

	testnum = random.randint(0, numtests - 1 )

	chosentest = None
	numtests = 0
	for test in config.findall('/tests/test'):
		if numtests == testnum:
			chosentest = test
		numtests = numtests + 1

	numchoices = 0
	for choice in chosentest.findall('choice'):
		numchoices = numchoices + 1

	testchoice = random.randint(0, numchoices - 1 )

	numchoices = 0
	for choice in chosentest.findall('choice'):
		#print str(numchoices) + ' ' + choice.get('text')
		if testchoice == numchoices:
			soundfilepath = 'sounds/' + choice.get('sound')
			choicetext = choice.get('text')
		numchoices = numchoices + 1

	playSound(soundfilepath)

	numchoices = 0
	for choice in chosentest.findall('choice'):
		print str(numchoices) + ' ' + choice.get('text')
		numchoices = numchoices + 1

	gotchoice = False
	while not gotchoice:
		print "Your choice? ('r' to repeat sound)"

		userchoice = sys.stdin.readline().strip().lower()
		if userchoice == str(testchoice):
			gotchoice = True
			print "Yes! : " + choicetext
			print ""
			playSound(soundfilepath)
		elif userchoice == 'r':
			playSound(soundfilepath)
		else:
			gotchoice = True
			print "In fact: " + choicetext
			print ""
			playSound(soundfilepath)
			done = False
			while not done:
				print 'r to replay correct answer, b to play both, n for next'
				userchoice = sys.stdin.readline().strip().lower()
				if userchoice == 'r':
					playSound(soundfilepath)
				if userchoice == 'b':
					for choice in chosentest.findall('choice'):
						print choice.get('text')
						soundfilepath = 'sounds/' + choice.get('sound')
						playSound(soundfilepath)
				elif userchoice == 'n':
					done = True

while True:
	runTest()
	time.sleep(1)

I might turn it into a webpage, and try to generate some ad-revenue, but most likely I won’t :-P

Note that the code above is pretty dreadful, but it works, which is the goal, since I want to one day be able to hear the difference in the tones in Chinese.

(PS if you ask me nicely, and I know you, I might consider providing you with some of the corresponding multimedia, but I’m not that keen on just plastering my gf’s voice all over the web, what with ‘my voice is my password’ becoming more popular and so on….)

Debian: fixed x-fonts on my installation

Thursday, January 28th, 2010

Just a minor detail really, but after installing debian squeeze using debootstrap, my x-fonts were really ugly.

It turns out that an appropriate way to clean them up was:
- install ttf-bitstream-vera, and set the system fonts to use this font
- in ‘appearance’ set ‘subpixel smoothing’, ‘slight’ hinting
- personally I use 10-point fonts, and 96dpi, which seems to give a reasonable compromise between information density, and readability, on an Eeepc 901, for me

Idea: artificial heart

Monday, January 25th, 2010

It seems to me that the basic technology of pumping heart around that the heart does is not actually that hard?

Of course, it needs to be fairly reliable, but that is what redundancy is for: just have two or three of them.

Another issue: how to maintain the hearts as and when they break down. Potential solution: have a flap, a door, that opens on the front of one’s chest, so that one can access the various hearts. Sort of like the electrical panel in one’s house.

Another issue: power… pumping blood around probably needs a *lot* of power. How much? Probably should check that. I feel that mobile phone batteries could probably deliver a fair amount of power. Give each of the two or three redundant hearts its own battery, and then there is redundance. Just open the panel to swap in and out a fresh one.

What about if someone forgets to charge up the batteries?

Initially, an alarm could sound to warn them, then as the battery becomes lower, the heart could slow down, ultimately slowing down to a rate just enough to prevent the person dieing, but they might collapse to the street, unable to move, effectively forcing them to be given medical treatment, ie replacement of batteries. This seems to me to be a better option than just stopping the heart after the batteries have been completely emptied!

Wouldn’t it be easy to murder someone by simply taking out the batteries? Sure, but it’s easy to murder someone anyway by just pressing on their windpipe, or slipping a knife into their heart, and yet generally we manage to survive 24 hours a day without such incidents impinging on our lives.

I suppose one issue to consider would be making the heart faster during fast exercise. A couple of thoughts:
- one could of course make the heart sensitive to adrenaline, but that’s complicated, maybe expensive, I don’t know how easy this is?
- otherwise, one could just make the heart go constantly the same speed. if someone does too much exercise, they’ll feel faint, but they’re not going to die from feeling faint, though they might collapse, probably workable
- and, one could just add the ability to control manually the speed of the heart. One button for faster one for slower.

Right, after writing this, I’ve googled and found a wikipedia article about artificial hearts.

It seems they exist. The concepts above do not seem to be being applied though:
- the hearts are only implanted singly, with no redundance
- they are not considered a permanent solution to heart failure
- power supply is from external packs via a transduction coil, which is fine I suppose
- there is no way to easily slot in and out a new heart when the old one breaks down

Whatever happened to: artificial organs?

Monday, January 25th, 2010

When I was a kid, I remember reading a book predicting things that would happen in the future.

One of the things was the Space Shuttle. Done.

One was something like a Gameboy. Done.

One thing that looked very plausible was artificial organs. What happened to those?

Or put it another way: I watched Dirty Dancing last night, and then I checked on the internet, and found that Patrick Swayze died of cancer of his pancreas last September.

I started to think: if we could make an artificial pancreas, then we could just have ripped out his old pancreas, put in a new artificial one, and bang, no more cancer!

Ditto for lung cancer, and so on.

It seems that such organs are not necessarily that complicated? At least: a heart: it’s just a pump. How hard is that? A pump does not sound like high-technology to me? Yes, it needs to be fairly reliable, and we’d need to think a bit about the power source, but compared to dieing…

I think maybe one issue is that there are not enough people needing any specific organ, that there are not the same economies of scale as for for example mobile phones.

For example, artificial kidneys do exist: they are called dialysis machines, and they’re about the size of a refridgerator, big and bulky and expensive.

I started to think that maybe if everyone needed a dialysis machine then they might be the same size and price as a mobile phone by now, but they’re not needed by everyone, and so the economies of scale do not exist.

Also, I started to think that maybe it’s cheaper just to transplant some dead person’s organ instead, and maybe that slows down the development of artificial organs?

Random idea: if we didn’t have transplant technology, if it was illegal, or considered unethical for some reason, maybe artificial organ technology would be much more advanced?

Sort of like how mines in England were always flooding, and that drove the development of the steam engine, which ultimately led to railways. In Rome, their mines did not fill up with water – it doesn’t rain so much there – and they never invented railways. I’m sure it’s a lot more complicated than that, but the point I’m trying to make is that sometimes having additional challenges sometimes catalyse a technology that can later be used for something else.

If we could replace every organ in our body with artificial ones, at will, then a huge number of cancers would no longer be the issue they are today.

Idea: webcam with eye-contact

Thursday, January 21st, 2010

Idea: webcam with eye-contact

Background: currently, when using video chat using web cams, there is I feel no real eye-contact: either the user looks at the web-cam, and cannot see the other person on the screen, or else looks at the screen, but then the other person sees them looking down, away from the webcam.

It could be really useful to create a webcam that allows eye-contact, by making the screen behave exactly like a window, into which each people can look, and make real eye-contact.

One way to do this could be to make a hole in the middle of the screen, but that sounds expensive and impractical, and will create an artifact in the middle of the screen.

There is a way to provide for eye-contact on a webcam, using a webcam that is not set in the middle of the screen.

- first, we use a 3d webcam to create a 3d video of the person’s head, in real-time
- next, we apply a simple rotational transform to rotate the 3d image so that it appears as though it was filmed from the centre of the screen
- lastly, we can project this image onto a 2d plane, and transmit the 2d video

As a possible future enhancement, given sufficient bandwidth, we could transmit the underlying 3d data, and the other person could visualize it using 3d glasses at the other end.

In both implementations, the computer screen can behave like a window into the other person’s world, permitting a real and intimate virtual connection with the other person.

Idea: make it easy for people to create 3d models of their house

Thursday, January 21st, 2010

Idea: make it easy for people to create 3d models of their house
- for Google Earth specifically
- and other similar software

Possible inputs:
- photos of the house
- aerial photo from Google Earth (copyright issues?)
- tweaks by end-user
- tweaks by an expert specialist in tweaking (not very scalable, in fact, not scalable, but could be useful, at least initially)

Revenue:
- ads on free site
- or, per-usage fee

Idea: make it easy for people to create avatars that look exactly like themselves

Thursday, January 21st, 2010

Idea: make it easy for people to create avatars that look exactly like themselves
- for SecondLife
- for Counter-Strike et al

Possible inputs:
- photos of the person
– naked?
– with clothes?
– maybe just from clothes
– in different standardized poses?
– facilitates processing significantly
- tweaks by end-user
- tweaks by an expert specialist in tweaking (not very scalable, in fact, not scalable, but could be useful, at least initially)

Libraries/middleware:
- what libraries/middleware are out there for this?

Revenue:
- ads on free web-site
- or, per-usage fee

Idea: create a program that can generate porn photos or videos

Thursday, January 21st, 2010

Idea: create a program that can generate porn photos or videos, using high-quality computer graphics.

The porn photos or videos could be created:
- according to user-provided specifications/requirements/configuration
- randomly, perhaps with interaction from the user to specify certain vague preferences

Possible inputs:

Static inputs/body form:
- standard ‘beautiful’ body form
- muscle data?
- ways that bodies can vary?
- skin color
- height
- obesity/body fat ratio
- muscularity/fitness
– assume muscularity distributed evenly across body?
– maybe depends on ‘method’ used to gain muscle, ie
– swimming, vs
– walking, vs
– running, vs …
- hair color
– let the user choose? random from artist-defined selection? use previous picks by other users as basis for random selection?
- hair style
– hard to do by computer
– probably need to update a range of template hair styles at least once a year
– probably using an artist
- lip color
– pretty easy to do, though maybe need an artist to pick a range of colors, or let the user choose
- clothing…
… very variable
… but some standard configurations:
– jeans + t-shirt
– jean shorts + t-shirt
– stripper look (leotard et al, different colors)
– secretary look: black skirt (variable length, texture), black tights, black shoes (variable high-heels)
– everyday casual look
– …
- different racial configurations: asian/chinese, asian/thai, asian/japanese, european/english, american, european/french, european/spanish, european/hungarian, russian, indian, …

Dynamic inputs / pose / motion:
- happiness, with virtual situation?
- openness to virtual viewer?
- sexual openness to virtual viewer?

Location:
- bed :-P
- park
- bar
- living room
- beach
- …

Program environment:
- standalone exe?
- create avatars within SecondLife or similar?
- website?
– interactive?
– daily generated images?
- compatible with 3d technology/glasses?

Data sources:
- existing photos, suitably abstracted/tweaked/averaged, to remove ability to trace initial input?
– issues with copyrights on original photo?
– ways to determine which original photos were used?
– things specific to an individual:
– macro things: dimensions of cheek-bones etc
– can be averaged out, or tweaked randomly
– micro things: individual spots, blemishes, scars etc
– can be averaged out or manually removed
– new ones can be added

Libraries / middleware?
- what libraries / middleware / databases are out there for this?

Competition:
- SecondLife
- real-life porn
- other people doing the same thing

How to obtain a competitive advantage:
- do it ‘really well’…
- the random aspect: quantity / potentially low-cost, compared to drawing by hand, scalability
- the cg aspect: potentially more legal / lower-cost, compared to using real-life models
- the interactive/on-demand aspect: personalization (auto-personalization according to recorded tastes of viewer?)

Differences between real-life models:
- generally I feel it can be more interesting to view different models, rather than simply variation on the same underlying model
- Why?
– different underlying people?
– different poses of same model doesn’t make that much difference to me personally (but to others?)
– dress makes some difference to me personally but not as big as changing underlying model (but to others?)
– different attitudes/faces?
– would all artificial girls look like one girl, to me? to others?
– I don’t think so, after playing briefly with the volleyball game with hot japanese chicks in

Other team-members that could be required:
- artists
- animation experts
- traditional porn directors/creators
- medical experts / doctors

Thoughts:
- interaction with ways of creating avatars in SecondLife?
- interaction with ways of creating avatars generally?
- interaction with ‘Avatar’, the film, technology
- advantages/ comparison with using real models:
– potentially more ethical: few ethical issues with exploitation of models
– potentially cheaper
– potentially more legal, since no need to interact with real models, and the associated ethical issues with such
potential negative effects:
– loss of work for models and cameramen who feel that working on these videos is their best option for living the best life possible
- interaction with a game / strip-poker environment?
– comparison with that volleyball game with hot japanese chicks in
– SecondLife et al
– strip-poker games? (I think they usually use real models though)
- collaboration with artists / animation specialists / medical experts?
- psychological aspect of using real-life models?
– personally I think there is a lot of fantasy / imagination involved even when viewing real-life models
– since they are generally being coerced by money, not doing it just for the pleasure of seeing their naked body exposed sexually for random guys around the world…
– plus the whole being-filmed thing is fairly industrial/cold I feel, in cold warehouses, with lots of people around, etc …
– could improve psychological aspect by integrating into some loose game etc
– I thought some of the girls in ‘The World Ends with You’ were really amazingly hot, even though:
– they were not even videos, simply crappy drawings
– maybe because:
– they had personalities, strong interesting ones, they felt to me like real people
– difficult to do this randomly, compute generated though…
– but maybe easier to create short stories, than to do the actual art/graphics itself, and also few legal issues, compared to filming real-life models

Product ideas

Thursday, January 21st, 2010

I’ve had a bunch of ideas for products over the years.

I’ve never had the marketing skill, or contacts, to successfully figure out how to monetarize them.

I think I will just put them out there, and either no-one will notice them, in which case, who cares that they’re out there?, or maybe people will notice them, and maybe I can get some traffic and associated ad revenue?

I am of course available to provide implementation for some of these ideas. You could of course get other people to do the implementation. Why use me? Well, since they’re my ideas, my emotional investment, passion, to get them working could be higher, and coming up with the ideas could show some technical creativity that could be potentially useful to workaround any issues during the implementation phase.

I have not applied for patents on any of these ideas, nor are there any working prototypes at this stage, in general.

Except where noted, these are my own ideas, though it’s absolutely possible that other people have thought of the same, or similar, ideas, and may have patents on them.

Notification / systray icon for wpa_supplicant

Sunday, January 3rd, 2010

network-manager-gnome didn’t seem to work with me for wep for some reason.

plus it’s not compatible with doing things from the commandline.

wpagui does exist, but it does way more than I want, and without the things I do want.

So I wrote my own. It sits in the notification tray.

If you right-click, you can do ‘activate wifi’ and ‘deactivate wifi’, which turns on the wifi networking, or turns it back off. When it turns it on, it runs dhclient on the detected wifi interface, after activating the wpa_supplicant on that interface.

If you left-click, you can see the list of available networks, and which one is connected, if any.

The mouseover text is the current wpa_supplicant state, and the currently connected network, if any.

Here’s the code. Just paste into a script, and run. You need to use sudo unfortunately, use at your own risk, your mileage may vary…:

#!/usr/bin/python

# Copyright Hugh Perkins 2009
# hughperkins@gmail.com http://manageddreams.com
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
#  more details.
#
# You should have received a copy of the GNU General Public License along
# with this program in the file licence.txt; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-
# 1307 USA
# You can find the licence also on the web at:
# http://www.opensource.org/licenses/gpl-license.php
#
# ======================================================================================
#

import os
import sys
import gtk
import time
import subprocess

class MyTray(object):
   def __init__(self):
      self.statusIcon = gtk.StatusIcon()
      self.menu = gtk.Menu()
      self.getstatus()
      self.showstatus()
      self.popupmenu = gtk.Menu()
      menuitem = gtk.MenuItem('Activate wifi')
      menuitem.connect('activate', self.activateWifi, None )
      self.popupmenu.append( menuitem )
      menuitem = gtk.MenuItem('Disable wifi')
      menuitem.connect('activate', self.disableWifi, None )
      self.popupmenu.append( menuitem )
      self.statusIcon.connect('activate', self.activate_cb, self.menu )
      self.statusIcon.connect('popup-menu', self.popupmenu_cb, None )
      self.statusIcon.set_visible(True)
      self.statusIcon.set_visible(1)
      gtk.main()

   def activateWifi( self, widget, data = None ):
      popen = subprocess.Popen(['gnome-terminal', '-x', '/sbin/wpa_cli', 'reconnect'], stdout = subprocess.PIPE)
      popen.wait()
      popen = subprocess.Popen(['gnome-terminal', '-x', '/sbin/dhclient', self.interface], stdout = subprocess.PIPE)
      popen.wait()
      self.getstatus()
      self.showstatus()

   def disableWifi( self, widget, data = None ):
      popen = subprocess.Popen(['gnome-terminal', '-x', '/sbin/wpa_cli','disconnect'], stdout = subprocess.PIPE)
      popen.wait()
      self.getstatus()
      self.showstatus()

   def activate_cb(self, widget, data = None ):
      self.getstatus()
      self.showstatus()
      self.menu.show_all()
      et = gtk.get_current_event_time()
      self.menu.popup(None, None, gtk.status_icon_position_menu, 1, et, self.statusIcon )

   def popupmenu_cb(self, widget, button, time, data = None ):
      self.popupmenu.show_all()
      self.popupmenu.popup(None, None, None, 3, time )

   def showstatus(self):
      self.statusIcon.set_from_stock(gtk.STOCK_NO)
      if self.wpa_state == 'COMPLETED':
         self.statusIcon.set_from_stock(gtk.STOCK_CONNECT)
      self.statusIcon.set_tooltip(str(self.wpa_state) + ' ' + str(self.ssid) )
      self.menu = gtk.Menu()
      for net in self.availablenets:
         if net != '':
            netname = net.split('\t')[4]
            if netname == self.ssid:
               menuItem = gtk.ImageMenuItem(gtk.STOCK_CONNECT, netname)
               menuItem.set_label(netname)
               self.menu.append(menuItem)
            else:
               menuItem = gtk.MenuItem(netname)
               self.menu.append(menuItem)

   def getstatus(self):
      popen = subprocess.Popen(['/sbin/wpa_cli','status'], stdout = subprocess.PIPE)
      popen.wait()
      (stdout,stderr) = popen.communicate(None)
      self.ssid = None
      self.wpa_state = None
      self.interface = None
      for line in stdout.split('\n'):
         if line.startswith('Selected interface'):
            self.interface = line.split("'")[1]
            print self.interface
         key = line.split('=')[0]
         if key == 'wpa_state':
            self.wpa_state = line.split('=')[1]
         if key == 'ssid':
            self.ssid = line.split('=')[1]

      popen = subprocess.Popen(['/sbin/wpa_cli','scan_results'], stdout = subprocess.PIPE)
      popen.wait()
      (stdout,stderr) = popen.communicate(None)
      self.availablenets = stdout.split('\n')[2:]

mytray = MyTray()

It’s pretty short. Probably fairly easy to customize for your own purposes?

Edit: uses 15.8meg of memory :-O That’s insane… I’d better check why that is…

Thirty times more memory than my Commodare Amiga 500 had; and it could run Populous!