tag:blogger.com,1999:blog-219569122024-03-13T23:36:21.528+11:00TJ's PlaceA collection of unordered thoughts somehow expressed in English.
<br><br>
gabbpuyTJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.comBlogger39125tag:blogger.com,1999:blog-21956912.post-10751557466321628872013-02-06T19:04:00.002+11:002013-02-06T19:06:55.190+11:00Darpa funds python development for big data<a href="http://www.itworld.com/big-data/340570/python-gets-big-data-boost-darpa" target="_blank">DARPA funds python development for big data</a>TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com0tag:blogger.com,1999:blog-21956912.post-64107248464744099332013-01-11T21:46:00.001+11:002013-01-11T21:51:09.597+11:00National Geographic Photo of the Day using Python<div>
A small snippet of code to get the National Geographic Photo of the Day.</div>
<div>
It uses <a href="http://wwwsearch.sourceforge.net/mechanize/">mechanize</a> and <a href="http://www.crummy.com/software/BeautifulSoup/">beautiful soup 4</a> to help with the scraping.</div>
<div>
<br /></div>
<div>
It also has a function to allow walking backwards to pickup previous photos.</div>
<div>
<br /></div>
<pre class="code"><span class="comment"># -*- coding: utf-8 -*-</span>
<span class="keyword">import</span> os
<span class="keyword">import</span> re
<span class="keyword">import</span> sys
<span class="keyword">import</span> mechanize
<span class="keyword">from</span> bs4 <span class="keyword">import</span> BeautifulSoup
MASTER_URL = <span class="string">"http://photography.nationalgeographic.com/photography/photo-of-the-day/?source=NavPhoPOD"</span>
<span class="keyword">class </span><span class="hilight">POD_Browser</span>(mechanize.Browser):
<span class="string">"""
A browser for pod, with our configuration settings.
"""</span>
<span class="keyword">def</span> <span class="hilight">__init__</span><span class="specialChar">(</span>self, *args, **kwargs<span class="specialChar">)</span>:
mechanize.Browser.__init__(self, *args, **kwargs)
self.set_handle_robots(False)
self.set_debug_redirects(False)
self.set_debug_http(False)
self.set_handle_equiv(True)
self.set_handle_gzip(True)
self.set_handle_redirect(True)
self.open(MASTER_URL)
<span class="keyword">class </span><span class="hilight">Session</span>(object):
<span class="string">"""
A Session.
"""</span>
<span class="keyword">def</span> <span class="hilight">__init__</span><span class="specialChar">(</span>self<span class="specialChar">)</span>:
self.browser = POD_Browser()
<span class="keyword">def</span> <span class="hilight">downloadPhotoOfTheDay</span><span class="specialChar">(</span>self<span class="specialChar">)</span>:
<span class="string">"""
Search the page looking for a Wallpaper link. Not all pages have
Wallpaper link, and we (politely) don't download the image in that
case.
"""</span>
page = self.browser.response().read()
soup = BeautifulSoup(page)
tags = soup.find_all(<span class="string">'a'</span>, text = re.compile (<span class="string">'Download Wallpaper'</span>))
<span class="keyword">for</span> t <span class="keyword">in</span> tags:
filename = t[<span class="string">'href'</span>].split(<span class="string">'/'</span>)[-<span class="int">1</span>]
<span class="comment"># If we've already downloaded the file, don't download it again.</span>
<span class="keyword">if</span> <span class="keyword">not</span> os.path.exists(filename):
filename, _headers = self.browser.retrieve(t[<span class="string">'href'</span>], filename )
<span class="keyword">print</span> filename
sys.stdout.flush()
<span class="keyword">def</span> <span class="hilight">goPrevious</span><span class="specialChar">(</span>self<span class="specialChar">)</span>:
<span class="string">"""
Find the previous link and go back a day
"""</span>
link = self.browser.find_link(text_regex = re.compile(<span class="string">'Previous'</span>))
self.browser.follow_link(link)
<span class="keyword">def</span> <span class="hilight">downloadPriorPhotos</span><span class="specialChar">(</span>self, start = <span class="int">1</span>, num = <span class="int">10</span><span class="specialChar">)</span>:
<span class="string">"""
Download some prior photos.
You can start 7 days back and get 14 days of photos with
start = 7, num = 14
:param start: How many days to go back before starting
:param num: How many days to look at.
"""</span>
<span class="keyword">for</span> x <span class="keyword">in</span> xrange(start):
self.goPrevious()
<span class="keyword">for</span> x <span class="keyword">in</span> xrange(num):
self.downloadPhotoOfTheDay()
self.goPrevious()
<span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:
s = Session()
s.downloadPhotoOfTheDay()
<span class="comment"># If you want to get the last week's worth uncomment this instead.</span>
<span class="comment">#s.downloadPriorPhotos(num = 7)</span>
</pre>
TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com0tag:blogger.com,1999:blog-21956912.post-26608147373195882232012-04-11T16:32:00.000+10:002012-04-11T16:32:32.421+10:00pyWallpaper UpdatedI have committed a much more comprehensive version of pyWallpaper to the subversion repository.<br />
<br />
It is multi-threaded to speed up the wallpaper construction (most of the threads end up being I/O bound, so this is a win in terms of elapsed time).<br />
<br />
Also supports walking subfolders by prefixing paths with a +<br />
<br />
The code is still available at <a href="http://code.google.com/p/pywallpaper/">http://code.google.com/p/pywallpaper/</a>TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com0tag:blogger.com,1999:blog-21956912.post-38466460718301307292011-03-12T17:52:00.003+11:002011-03-12T18:06:33.344+11:00When .999 is actually 1You remember at school (or maybe you're just learning now) when doing fractions, that dividing something by 9 would give you an "infinite" decimal that repeated? For example 4/9 = .444444 on to infinity.<br />
<br />
This means that if you ever see a number that is that way you know it's something divided by 9, so .77777... is 7/9.<br />
<br />
But wait, what about .999999... ? That would be 9/9 which is 1, that can't be right!<br />
<br />
In fact it is, and without any tricks, here's the algebra to show it.<br />
<br />
I will use .999999r to indicate .9 repeater, normally it would be a .9 with a . above the 9, but, finding a font that everyone has that has that proved too tedious :-) I have also made all the steps explicit instead of doing multiple operations at once, just so algebra beginners can see there is no subterfuge going on.<br />
<br />
<i>Let a = .999999r</i><br />
<br />
Multiply both sides by 10 gives<br />
<i>10a = 9.999999r</i><br />
<br />
Subtract 9 from both sides gives<br />
<i>10a - 9 = .999999r</i><br />
<br />
Replace .999999r with a from above<br />
<i>10a - 9 = a</i><br />
<br />
Subtract a from both sides<br />
<i>10a - 9 - a = 0</i><br />
<br />
Add 9 to both sides<br />
<i>10a - a = 9</i><br />
<br />
Simplify<br />
<i>9a = 9</i><br />
<br />
Divide both sides by 9<br />
<i>a = 1</i><br />
<br />
<i>Therefore .999999r = 1</i><br />
<i> </i>TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com1tag:blogger.com,1999:blog-21956912.post-88005545626997460442010-11-18T01:02:00.001+11:002010-11-18T01:02:53.816+11:00Process Explorer gets Tree CPU Usage featureThe feature I've missed most from Process Explorer has been implemented in version 14.<br />
The ability to see the combined CPU usage for a parent and all its children, this is especially useful for things like Chrome, but, now I can roll up a lot of trees of stuff and still see what's making my CPU fans spin up all of a sudden.<br />
<br />
Thanks guys d8)<br />
<br />
<a href="http://blogs.technet.com/b/sysinternals/archive/2010/11/16/update-process-explorer-v14.aspx">http://blogs.technet.com/b/sysinternals/archive/2010/11/16/update-process-explorer-v14.aspx</a>TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com0tag:blogger.com,1999:blog-21956912.post-36939719587855410572010-10-08T05:56:00.000+11:002010-10-08T05:56:33.289+11:005 Fridays, 5 Saturdays, 5 Sundays, 823 years, wrong..The calendar repeats every 11 years, so the maximum this can be is 11 years...<br />
so October in 2021 will be the same as October in 2010 (handy if you want to reuse those calendars), go ahead look on your computer or phone right now.<br />
<br />
However, we have a few months that have 31 days, and we only need one of them to begin on a Friday.<br />
In 2013, March starts on a Friday (and 2024, etc)...<br />
<br />
In 2014, August starts on a Friday (and 2025, etc)... <br />
<br />
There are other months in other years that have 3 days that occur 5 times too, so, it's not special.<br />
<br />
Next time someone tells you something about some weird calendar event, think about the 11 year cycle, and go back/forward 11 years and see if it's true.TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com1tag:blogger.com,1999:blog-21956912.post-86042245061980950712010-10-05T23:34:00.002+11:002010-10-05T23:34:14.794+11:00When...When you "talk" like a LOL Cats caption, I wonder if your parents were too closely related to each other...TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com0tag:blogger.com,1999:blog-21956912.post-67856567021596679612010-09-09T23:40:00.000+10:002010-09-09T23:40:11.215+10:00Random code repoI've created a google project (akm-code) into which I can dump random code projects.<br />
Most of the code in there is finished, but, might be suffering from bit-rot (patches welcome d8)<br />
<br />
You can browse the code here; <a href="http://code.google.com/p/akm-code/source/browse/">http://code.google.com/p/akm-code/source/browse/</a>TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com0tag:blogger.com,1999:blog-21956912.post-50949541590299052562010-08-18T18:24:00.000+10:002010-08-18T18:24:35.644+10:00Serial terminalsMost people forget, that putty and its relations are usable as serial terminals under windows. Putty has built in terminal emulation and you can choose speed and COM port, AND save the profile.<br />
<br />
This is useful for things like Bus Pirate or Arduino use since you can just pull up your profile from the putty interface.TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com0tag:blogger.com,1999:blog-21956912.post-62298156737757675952010-07-26T08:04:00.001+10:002010-07-26T08:04:40.731+10:00Google Code Repo for windows wallpaper codeI've setup a google code repository for the pywallpaper code.<br />
You can download it from there , and get any updates as I make them, or contribute patches.<br />
<br />
<a href="http://code.google.com/p/pywallpaper/">pywallpaper project</a>TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com0tag:blogger.com,1999:blog-21956912.post-62468589206841699392010-07-20T21:30:00.001+10:002010-07-20T22:31:03.314+10:00Set windows wallpaper from python for multiple monitorsThis code will allow you to set a different image per monitor for any combination of monitors. Monitors don't have to be the same size, or setup to be square on for it to work. You can have your third monitor straddling the other two, and the wallpaper will be built to accommodate it.<br />
<br />
You can now specify per-monitor directory lists if you want.<br />
<br />
There are blending and resizing options available too, see the comments.<br />
<br />
I've added a setup.py to make a .exe so that the dos window doesn't pop-up. <br />
<br />
<pre class="code"><span class="comment">#!C:/python25/python.exe</span>
<span class="comment"># Code to rotate or set wallpaper under windows</span>
<span class="comment"># Copyright (C) Andrew K. Milton 2007 - 2010</span>
<span class="comment"># Released under a 2-clause BSD License</span>
<span class="comment"># See: http://www.opensource.org/licenses/bsd-license.php</span>
<span class="comment"># Multi monitor detection based on http://code.activestate.com/recipes/460509/</span>
<span class="comment"># This will handle any configuration of an arbitrary number of monitors,</span>
<span class="comment"># including offset boundaries.</span>
<span class="keyword">import</span> os
<span class="keyword">import</span> sys
<span class="keyword">import</span> time
<span class="keyword">import</span> random
<span class="keyword">from</span> optparse <span class="keyword">import</span> OptionParser
<span class="keyword">from</span> ConfigParser <span class="keyword">import</span> SafeConfigParser
<span class="keyword">import</span> ctypes
<span class="keyword">from</span> ctypes <span class="keyword">import</span> windll
<span class="keyword">from</span> win32con <span class="keyword">import</span> *
<span class="keyword">import</span> win32gui
<span class="keyword">import</span> win32api
<span class="keyword">import</span> win32con
<span class="keyword">from</span> PIL <span class="keyword">import</span> Image, ImageDraw, ImageChops, ImageOps, ImageFilter
<span class="comment"># I recommend you create a pywallpaper.conf file that looks something</span>
<span class="comment"># like this to store the directories in rather than specifying -d</span>
<span class="comment"># multiple times on the command line.</span>
<span class="comment">#</span>
<span class="comment"># NB you can specify paths per monitor. Any monitor number without its</span>
<span class="comment"># own paths will get the global paths. Monitors start at 0 which is always</span>
<span class="comment"># the primary monitor.</span>
<span class="comment">#</span>
<span class="comment"># Some options don't play nicely together.</span>
<span class="string">"""
[global]
Blending = True
BlendRatio = 0.40
Crop = False
Fill = True
Gradient = False
PreRotate = True
[directories]
paths = C:\Documents and Settings\akm\My Documents\My Pictures\gb
C:\Documents and Settings\akm\My Documents\My Pictures\Ralph
[monitor_0]
paths = C:\Documents and Settings\akm\My Documents\My Pictures\Wide Screen
[monitor_1]
paths = C:\Documents and Settings\akm\My Documents\My Pictures\Landscapes
"""</span>
<span class="comment"># If you don't like the little dos window that pops you can use the</span>
<span class="comment"># following as setup.py to create a .exe that won't display the window,</span>
<span class="comment"># makes it a little easier to use as a startup item too.</span>
<span class="string">"""
from distutils.core import setup
import py2exe
options = {
"bundle_files": 2,
"ascii": 1, # to make a smaller executable, don't include the encodings
"compressed": 1, # compress the library archive
"excludes": ['w9xpopen.exe',]
}
setup( windows = ['pyWallpaper.py'],
options = {'py2exe': options},
)
"""</span>
<span class="keyword">class </span><span class="hilight">RECT</span>(ctypes.Structure):
_fields_ = [
(<span class="string">'left'</span>, ctypes.c_long),
(<span class="string">'top'</span>, ctypes.c_long),
(<span class="string">'right'</span>, ctypes.c_long),
(<span class="string">'bottom'</span>, ctypes.c_long)
]
<span class="keyword">def</span> <span class="hilight">dump</span><span class="specialChar">(</span>self<span class="specialChar">)</span>:
f = (self.left, self.top, self.right, self.bottom)
<span class="keyword">return</span> [int(i) <span class="keyword">for</span> i <span class="keyword">in</span> f]
<span class="keyword">class </span><span class="hilight">MONITORINFO</span>(ctypes.Structure):
_fields_ = [
(<span class="string">'cbSize'</span>, ctypes.c_ulong),
(<span class="string">'rcMonitor'</span>, RECT),
(<span class="string">'rcWork'</span>, RECT),
(<span class="string">'dwFlags'</span>, ctypes.c_ulong)
]
<span class="keyword">class </span><span class="hilight">Monitor</span>(object):
<span class="keyword">def</span> <span class="hilight">__init__</span><span class="specialChar">(</span>self, monitor, physical, working, flags<span class="specialChar">)</span>:
self.monitor = monitor
self.physical = physical
self.working = working
self.size = self.getSize(*self.physical)
self.width, self.height = self.size
self.left, self.top, self.right, self.bottom = self.physical
self._left, self._top, self._right, self._bottom = self.physical
self.isPrimary = (flags != <span class="int">0</span>)
self.cTop = self.top
<span class="keyword">if</span> self.cTop < <span class="int">0</span>:
self.cTop = <span class="int">20000</span> + self.cTop
self.cLeft = self.left
<span class="keyword">if</span> self.cLeft < <span class="int">0</span>:
self.cLeft = <span class="int">20000</span> + self.cLeft
self.wLeft = int(self.left)
self.wTop = int(self.top)
self.needsSplit = ( (self.left < <span class="int">0</span> <span class="keyword">and</span> self.right > <span class="int">0</span>) <span class="keyword">or</span>
(self.top < <span class="int">0</span> <span class="keyword">and</span> self.bottom > <span class="int">0</span>) )
<span class="keyword">if</span> self.needsSplit:
self.needVSplit = self.top < <span class="int">0</span> <span class="keyword">and</span> self.bottom > <span class="int">0</span>
self.needHSplit = self.left < <span class="int">0</span> <span class="keyword">and</span> self.right > <span class="int">0</span>
<span class="keyword">def</span> <span class="hilight">addWallpaper</span><span class="specialChar">(</span>self, bgImage, wallpaper<span class="specialChar">)</span>:
<span class="keyword">if</span> <span class="keyword">not</span> self.needsSplit:
bgImage.paste(wallpaper, (self.wLeft, self.wTop))
<span class="keyword">return</span>
<span class="keyword">if</span> self.needVSplit:
height = -self.top
bottom = wallpaper.crop((<span class="int">0</span>, <span class="int">0</span>, self.width, height))
bottom.load()
top = wallpaper.crop((<span class="int">0</span>, height, self.width, self.height))
top.load()
bgImage.paste(top, (self.wLeft, <span class="int">0</span>))
bgImage.paste(bottom, (self.wLeft, bgImage.size[<span class="int">1</span>] - height))
<span class="keyword">else</span>:
width = -self.left
right = wallpaper.crop((<span class="int">0</span>, <span class="int">0</span>, width, self.height))
right.load()
left = wallpaper.crop((width, <span class="int">0</span>, self.width, self.height))
left.load()
bgImage.paste(left, (<span class="int">0</span>, self.wTop))
bgImage.paste(right, (bgImage.size[<span class="int">0</span>] - width, self.wTop))
<span class="keyword">def</span> <span class="hilight">getSize</span><span class="specialChar">(</span>self, left, top, right, bottom<span class="specialChar">)</span>:
<span class="keyword">return</span> [abs(right - left), abs(bottom - top)]
<span class="keyword">def</span> <span class="hilight">__repr__</span><span class="specialChar">(</span>self<span class="specialChar">)</span>:
<span class="keyword">return</span> <span class="string">'extent: '</span> + str(self.physical) + <span class="string">' :: size: '</span> + str(self.size) + <span class="string">' :: primary: '</span> + str(self.isPrimary) + <span class="string">' :: needsSplit '</span> + str(self.needsSplit) + <span class="string">':: '</span> + hex(self.monitor)
<span class="keyword">def</span> <span class="hilight">__cmp__</span><span class="specialChar">(</span>self, other<span class="specialChar">)</span>:
<span class="keyword">if</span> <span class="keyword">not</span> cmp(self.cTop, other.cTop):
<span class="keyword">return</span> cmp(self.cLeft, other.cLeft)
<span class="keyword">return</span> cmp(self.top, other.top)
<span class="keyword">class </span><span class="hilight">Desktop</span>(object):
<span class="keyword">def</span> <span class="hilight">__init__</span><span class="specialChar">(</span>self<span class="specialChar">)</span>:
self.setMonitorExtents()
<span class="comment"># Merge with the desktop background colour</span>
<span class="comment"># Handy to tint your background to your theme.</span>
self.Blending = <span class="keyword">True</span>
<span class="comment"># Amount of picture to bg colour ratio</span>
<span class="comment"># This works well for black...</span>
self.BlendRatio = <span class="float">0.40</span>
<span class="comment"># Render a gradient under the image..</span>
<span class="comment"># I'm not overly happy with the results.</span>
self.Gradient = <span class="keyword">False</span>
<span class="comment"># Crop black/white borders before zooming</span>
<span class="comment"># This doesn't work well with Fill..</span>
self.Crop = <span class="keyword">False</span>
<span class="comment"># Don't just maxpect the image... blow it up so there's no bg colour</span>
<span class="comment"># showing so this will crop parts.</span>
self.Fill = <span class="keyword">True</span>
<span class="comment"># If the aspect ratio is "wrong" for the monitor, rotate it for a</span>
<span class="comment"># better fit first. So portraits rotate for landscape monitors.</span>
<span class="comment"># With per-monitor dirs you can sort your pictures based on aspect</span>
<span class="comment"># ratio if you want.</span>
self.PreRotate = <span class="keyword">True</span>
self.createEmptyWallpaper()
<span class="keyword">def</span> <span class="hilight">createEmptyWallpaper</span><span class="specialChar">(</span>self<span class="specialChar">)</span>:
c = (<span class="int">0</span>, <span class="int">0</span>, <span class="int">0</span>)
<span class="keyword">if</span> self.Blending:
<span class="comment"># Alpha blend the image with the current desktop colour</span>
<span class="comment"># Or black if something goes wrong with getting the desktop colour</span>
<span class="keyword">try</span>:
dc = windll.user32.GetSysColor(<span class="int">1</span>)
c = ((dc & 0xFF ),
(dc & 0xFF00) >> <span class="int">8</span>,
(dc & 0xFF0000) >> <span class="int">16</span>)
<span class="keyword">except</span>:
<span class="keyword">pass</span>
self.bgColour = c
bgImage = Image.new(<span class="string">'RGB'</span>, self.wSize, c)
<span class="keyword">if</span> self.Gradient:
r, g, b = c
width, height = bgImage.size
fh = float(height)
<span class="keyword">if</span> (r + g + b) / <span class="int">3</span> < <span class="int">64</span>:
r1, g1, b1 = (<span class="int">128</span>, <span class="int">128</span>, <span class="int">128</span>)
<span class="keyword">else</span>:
r1, g1, b1 = c
r, g, b = (<span class="int">64</span>, <span class="int">64</span>, <span class="int">64</span>)
rd = r1 - r
gd = g1 - g
bd = b1 - b
rs = float(rd) / fh
gs = float(gd) / fh
bs = float(bd) / fh
draw = ImageDraw.Draw(bgImage)
<span class="keyword">for</span> h <span class="keyword">in</span> range(<span class="int">0</span>, height):
draw.line((<span class="int">0</span>, h, width, h),
fill = (int(r1), int(g1), int(b1)))
r1 -= rs
b1 -= bs
g1 -= gs
self.bgImage = bgImage
<span class="keyword">def</span> <span class="hilight">findMonitors</span><span class="specialChar">(</span>self<span class="specialChar">)</span>:
retval = []
CBFUNC = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong, ctypes.c_ulong, ctypes.POINTER(RECT), ctypes.c_double)
<span class="keyword">def</span> <span class="hilight">cb</span><span class="specialChar">(</span>hMonitor, hdcMonitor, lprcMonitor, dwData<span class="specialChar">)</span>:
r = lprcMonitor.contents
data = [hMonitor]
data.append(r.dump())
retval.append(data)
<span class="keyword">return</span> <span class="int">1</span>
cbfunc = CBFUNC(cb)
temp = windll.user32.EnumDisplayMonitors(<span class="int">0</span>, <span class="int">0</span>, cbfunc, <span class="int">0</span>)
<span class="keyword">return</span> retval
<span class="keyword">def</span> <span class="hilight">calcWallSize</span><span class="specialChar">(</span>self<span class="specialChar">)</span>:
<span class="comment"># Also sets the relative offsets for building the wallpaper...</span>
ms = self.monitors
primaryMonitor = [m <span class="keyword">for</span> m <span class="keyword">in</span> ms <span class="keyword">if</span> m.isPrimary][<span class="int">0</span>]
leftMonitors = [m <span class="keyword">for</span> m <span class="keyword">in</span> ms <span class="keyword">if</span> m.left < <span class="int">0</span>]
rightMonitors = [m <span class="keyword">for</span> m <span class="keyword">in</span> ms <span class="keyword">if</span> m.left >= primaryMonitor.right]
topMonitors = [m <span class="keyword">for</span> m <span class="keyword">in</span> ms <span class="keyword">if</span> m.top < <span class="int">0</span>]
bottomMonitors = [m <span class="keyword">for</span> m <span class="keyword">in</span> ms <span class="keyword">if</span> m.top >= primaryMonitor.bottom]
leftMonitors.sort()
rightMonitors.sort()
topMonitors.sort()
bottomMonitors.sort()
hMonitors = [primaryMonitor,] + rightMonitors + leftMonitors
vMonitors = [primaryMonitor,] + bottomMonitors + topMonitors
width = max([m.right <span class="keyword">for</span> m <span class="keyword">in</span> ms])
height = max([m.bottom <span class="keyword">for</span> m <span class="keyword">in</span> ms])
extraWidth = -min([m.left <span class="keyword">for</span> m <span class="keyword">in</span> ms])
extraHeight = -min([m.top <span class="keyword">for</span> m <span class="keyword">in</span> ms])
width += extraWidth
height += extraHeight
hOff = width
redo = []
<span class="keyword">for</span> m <span class="keyword">in</span> leftMonitors:
m.wLeft = width + m.left
<span class="keyword">if</span> m <span class="keyword">in</span> bottomMonitors:
<span class="keyword">continue</span>
m.right = width
<span class="keyword">for</span> m <span class="keyword">in</span> topMonitors:
m.wTop = height + m.top
<span class="keyword">if</span> m <span class="keyword">in</span> rightMonitors:
<span class="keyword">continue</span>
m.bottom = height
<span class="keyword">return</span> (width, height)
<span class="keyword">def</span> <span class="hilight">getMonitors</span><span class="specialChar">(</span>self<span class="specialChar">)</span>:
retval = []
<span class="keyword">for</span> hMonitor, extents <span class="keyword">in</span> self.findMonitors():
<span class="comment"># data = [hMonitor]</span>
mi = MONITORINFO()
mi.cbSize = ctypes.sizeof(MONITORINFO)
mi.rcMonitor = RECT()
mi.rcWork = RECT()
res = windll.user32.GetMonitorInfoA(hMonitor, ctypes.byref(mi))
data = Monitor(hMonitor, mi.rcMonitor.dump(), mi.rcWork.dump(), mi.dwFlags)
retval.append(data)
<span class="keyword">return</span> retval
<span class="keyword">def</span> <span class="hilight">setMonitorExtents</span><span class="specialChar">(</span>self<span class="specialChar">)</span>:
self.monitors = self.getMonitors()
self.wSize = self.calcWallSize()
<span class="keyword">def</span> <span class="hilight">getDefaultDirs</span><span class="specialChar">(</span>self<span class="specialChar">)</span>:
<span class="keyword">return</span> [<span class="string">r'C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures'</span>,]
<span class="keyword">def</span> <span class="hilight">setWallPaperFromBmp</span><span class="specialChar">(</span>self, pathToBmp<span class="specialChar">)</span>:
<span class="comment">""" Given a path to a bmp, set it as the wallpaper """</span>
<span class="comment"># Set it and make sure windows remembers the wallpaper we set.</span>
result = windll.user32.SystemParametersInfoA(
SPI_SETDESKWALLPAPER, <span class="int">0</span>,
pathToBmp,
SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE)
<span class="keyword">if</span> <span class="keyword">not</span> result:
<span class="keyword">raise</span> Exception(<span class="string">"Unable to set wallpaper."</span>)
<span class="keyword">def</span> <span class="hilight">autoCrop</span><span class="specialChar">(</span>self, im, bgcolor = (<span class="int">0</span>, <span class="int">0</span>, <span class="int">0</span><span class="specialChar">)</span>):
<span class="keyword">if</span> im.mode != <span class="string">"RGB"</span>:
im = im.convert(<span class="string">"RGB"</span>)
im2 = ImageOps.autocontrast(im, <span class="int">5</span>)
bg = Image.new(<span class="string">"RGB"</span>, im.size, bgcolor)
diff = ImageChops.difference(im2, bg)
bbox = diff.getbbox()
<span class="keyword">if</span> bbox:
<span class="keyword">return</span> im.crop(bbox)
<span class="keyword">return</span> im <span class="comment"># no contents</span>
<span class="keyword">def</span> <span class="hilight">maxAspectWallPaper_fill</span><span class="specialChar">(</span>self, image, width, height<span class="specialChar">)</span>:
<span class="comment"># Blow up the image making sure that the smallest image aspect</span>
<span class="comment"># fills the monitor.</span>
rsFilter = Image.BICUBIC
scale = <span class="float">2.0</span>
imWidth, imHeight = image.size
hScale = float(height) / float(imHeight)
wScale = float(width) / float(imWidth)
scale = max(hScale, wScale)
<span class="keyword">if</span> scale < <span class="int">1</span>:
rsFilter = Image.ANTIALIAS
newSize = (int(imWidth * scale), int(imHeight * scale))
newImage = image.resize(newSize, rsFilter)
<span class="keyword">if</span> scale > <span class="int">2</span>:
newImage = newImage.filter(ImageFilter.BLUR)
imWidth, imHeight = newSize
x = int((imWidth - width) / 2.0)
y = int((imHeight - height) / 2.0)
bbox = (x, <span class="int">0</span>, width + x, height + y)
<span class="keyword">return</span> newImage.crop(bbox)
<span class="keyword">def</span> <span class="hilight">maxAspectWallPaper</span><span class="specialChar">(</span>self, image, width, height<span class="specialChar">)</span>:
<span class="comment"># Blow the image up as much as possible without exceeding the monitor</span>
<span class="comment"># bounds.</span>
rsFilter = Image.BICUBIC
scale = <span class="float">2.0</span>
imWidth, imHeight = image.size
hScale = float(height) / float(imHeight)
wScale = float(width) / float(imWidth)
<span class="keyword">if</span> self.Fill:
scale = max(hScale, wScale)
<span class="keyword">else</span>:
scale = min(hScale, wScale)
<span class="keyword">if</span> scale < <span class="int">1</span>:
rsFilter = Image.ANTIALIAS
newSize = (int(imWidth * scale), int(imHeight * scale))
newImage = image.resize(newSize, rsFilter)
<span class="keyword">if</span> self.Fill:
imWidth, imHeight = newSize
x = int((imWidth - width) / 2.0)
y = int((imHeight - height) / 2.0)
bbox = (x, <span class="int">0</span>, width + x, height + y)
newImage = newImage.crop(bbox)
<span class="keyword">return</span> newImage
<span class="keyword">def</span> <span class="hilight">preRotateImage</span><span class="specialChar">(</span>self,image<span class="specialChar">)</span>:
<span class="comment"># Rotate 90 degrees.</span>
im = image.rotate(-<span class="int">90</span>, resample = True, expand = True)
<span class="keyword">return</span> im
<span class="keyword">def</span> <span class="hilight">createWallPaperFromFile</span><span class="specialChar">(</span>self, pathToImage, monitor<span class="specialChar">)</span>:
<span class="comment"># Given a path to an image, convert it to bmp format and set it as</span>
<span class="comment"># the wallpaper</span>
bmpImage = Image.open(pathToImage)
<span class="keyword">if</span> self.PreRotate:
<span class="keyword">if</span> bmpImage.size[<span class="int">0</span>] < bmpImage.size[<span class="int">1</span>]:
bmpImage = self.preRotateImage(bmpImage)
<span class="keyword">if</span> self.Crop:
bmpImage = self.autoCrop(bmpImage, (<span class="int">0</span>,<span class="int">0</span>,<span class="int">0</span>))
bmpImage = self.autoCrop(bmpImage, (<span class="int">255</span>,<span class="int">255</span>,<span class="int">255</span>))
bmpImage = self.maxAspectWallPaper(bmpImage, *monitor.size)
bmpSize = bmpImage.size
xOffset = int((monitor.size[<span class="int">0</span>] - bmpImage.size[<span class="int">0</span>]) / <span class="int">2</span>)
yOffset = int((monitor.size[<span class="int">1</span>] - bmpImage.size[<span class="int">1</span>]) / <span class="int">2</span>)
<span class="keyword">if</span> bmpImage.size != monitor.size:
img1 = Image.new(<span class="string">"RGB"</span>, monitor.size, (<span class="int">0</span>, <span class="int">0</span>, <span class="int">0</span>))
img1.paste(bmpImage, (xOffset, yOffset))
<span class="keyword">if</span> self.Blending:
img2 = Image.new(<span class="string">"RGB"</span>, monitor.size, self.bgColour)
<span class="keyword">return</span> Image.blend(img2, img1, self.BlendRatio)
<span class="keyword">return</span> img1
<span class="keyword">def</span> <span class="hilight">setWallpaperStyleSingle</span><span class="specialChar">(</span>self<span class="specialChar">)</span>:
<span class="comment"># 0x80000001 == HKEY_CURRENT_USER</span>
k = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,<span class="string">"Control Panel\\Desktop"</span>,<span class="int">0</span>,win32con.KEY_SET_VALUE)
win32api.RegSetValueEx(k, <span class="string">"WallpaperStyle"</span>, <span class="int">0</span>, win32con.REG_SZ, <span class="string">"0"</span>)
win32api.RegSetValueEx(k, <span class="string">"TileWallpaper"</span>, <span class="int">0</span>, win32con.REG_SZ, <span class="string">"0"</span>)
<span class="keyword">def</span> <span class="hilight">setWallpaperStyleMulti</span><span class="specialChar">(</span>self<span class="specialChar">)</span>:
<span class="comment"># To set a multi-monitor wallpaper, we need to tile it...</span>
<span class="comment"># 0x80000001 == HKEY_CURRENT_USER</span>
k = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,<span class="string">"Control Panel\\Desktop"</span>,<span class="int">0</span>,win32con.KEY_SET_VALUE)
win32api.RegSetValueEx(k, <span class="string">"WallpaperStyle"</span>, <span class="int">0</span>, win32con.REG_SZ, <span class="string">"0"</span>)
win32api.RegSetValueEx(k, <span class="string">"TileWallpaper"</span>, <span class="int">0</span>, win32con.REG_SZ, <span class="string">"1"</span>)
<span class="keyword">def</span> <span class="hilight">setWallpaperStyle</span><span class="specialChar">(</span>self<span class="specialChar">)</span>:
<span class="keyword">if</span> len(self.monitors) > <span class="int">1</span>:
self.setWallpaperStyleMulti()
<span class="keyword">else</span>:
self.setWallpaperStyleSingle()
<span class="keyword">def</span> <span class="hilight">setWallpaper</span><span class="specialChar">(</span>self<span class="specialChar">)</span>:
self.setWallpaperStyle()
<span class="comment"># Save the new wallpaper in our current directory.</span>
newPath = os.getcwd()
newPath = os.path.join(newPath, <span class="string">'pywallpaper.bmp'</span>)
self.bgImage.save(newPath, <span class="string">"BMP"</span>)
self.setWallPaperFromBmp(newPath)
<span class="keyword">def</span> <span class="hilight">setWallpaperFromFile</span><span class="specialChar">(</span>self, pathToImage<span class="specialChar">)</span>:
<span class="keyword">for</span> monitor <span class="keyword">in</span> self.monitors:
img = self.createWallPaperFromFile(filename, monitor)
monitor.addWallpaper(self.bgImage, img)
self.setWallpaper()
<span class="keyword">def</span> <span class="hilight">setWallPaperFromFileList</span><span class="specialChar">(</span>self, pathToDir, monitor<span class="specialChar">)</span>:
<span class="comment">""" Given a directory choose an image from it and set it as a wallpaper """</span>
<span class="comment"># Image directories often contain Thumbs.db or other non-image</span>
<span class="comment"># files or directories, try a few times to set a wallpaper, and then just give up.</span>
tries = <span class="int">0</span>
done = <span class="keyword">False</span>
filenames = []
files = os.listdir(pathToDir)
<span class="keyword">try</span>:
<span class="comment"># Priorwalls.txt is used so that we don't repeat an image</span>
<span class="comment"># until every other image in that directory has been seen</span>
<span class="comment"># The file is rewritten when necessary.</span>
prevList = open(<span class="string">'priorWalls.txt'</span>, <span class="string">'rb'</span>)
filenames = [l.strip() <span class="keyword">for</span> l <span class="keyword">in</span> prevList.readlines()]
prevList.close()
<span class="keyword">except</span>:
<span class="keyword">pass</span>
files = [os.path.join(pathToDir, f) <span class="keyword">for</span> f <span class="keyword">in</span> files <span class="keyword">if</span> <span class="keyword">not</span> f.endswith(<span class="string">'.db'</span>)]
availChoices = [f <span class="keyword">for</span> f <span class="keyword">in</span> files <span class="keyword">if</span> <span class="keyword">not</span> f <span class="keyword">in</span> filenames <span class="keyword">and</span> <span class="keyword">not</span> f.endswith(<span class="string">'.db'</span>)]
<span class="keyword">if</span> <span class="keyword">not</span> availChoices:
<span class="comment"># This entire directory has been "done" remove them</span>
<span class="comment"># from the previously seen wallpapers and rewrite</span>
<span class="comment"># the cache file without any of these entries.</span>
filenames = [f <span class="keyword">for</span> f <span class="keyword">in</span> filenames <span class="keyword">if</span> <span class="keyword">not</span> f <span class="keyword">in</span> files]
availChoices = files
p = open(<span class="string">'priorWalls.txt'</span>, <span class="string">'wb'</span>)
<span class="keyword">for</span> f <span class="keyword">in</span> filenames:
p.write(<span class="string">"<span class="specialChar">%s</span>\n"</span><span class="specialChar">%</span>(f))
p.close()
files = availChoices
<span class="keyword">while</span> (not done) <span class="keyword">and</span> tries < <span class="int">3</span>:
<span class="comment"># Thumbs.db and other stuff can live in the same Folder</span>
<span class="comment"># So try three times to set a wallpaper before giving up.</span>
<span class="keyword">try</span>:
image = random.choice(files)
filename = image
img = self.createWallPaperFromFile(filename, monitor)
monitor.addWallpaper(self.bgImage, img)
prevList = open(<span class="string">'priorWalls.txt'</span>, <span class="string">'ab'</span>)
prevList.write(<span class="string">"<span class="specialChar">%s</span>\n"</span><span class="specialChar">%</span>(filename))
done = <span class="keyword">True</span>
<span class="keyword">except</span>:
<span class="keyword">import</span> traceback; traceback.print_exc()
<span class="keyword">print</span> >> sys.stderr, filename, <span class="string">"failed"</span>
tries += <span class="int">1</span>
<span class="keyword">return</span> done
<span class="keyword">def</span> <span class="hilight">getMonitorDirs</span><span class="specialChar">(</span>self, monIndex<span class="specialChar">)</span>:
section = <span class="string">'monitor_<span class="specialChar">%d</span>'</span><span class="specialChar">%</span>(monIndex)
<span class="comment"># Check for [monitor_0]</span>
<span class="keyword">if</span> self.config.has_section(section):
<span class="comment"># check for its own paths section</span>
<span class="keyword">if</span> self.config.has_option(section, <span class="string">'paths'</span>):
dirs = self.config.get(section, <span class="string">'paths'</span>).split(<span class="string">'\n'</span>)
<span class="keyword">else</span>:
dirs = self.dirs
<span class="keyword">return</span> dirs
<span class="keyword">def</span> <span class="hilight">setWallPaperFromDirList</span><span class="specialChar">(</span>self<span class="specialChar">)</span>:
<span class="comment">""" Given a list of directories choose a directory """</span>
<span class="keyword">for</span> monNum, monitor <span class="keyword">in</span> enumerate(self.monitors):
imageDir = random.choice(self.getMonitorDirs(monNum))
status = self.setWallPaperFromFileList(imageDir, monitor)
self.setWallpaper()
<span class="keyword">def</span> <span class="hilight">getImageDirectories</span><span class="specialChar">(</span>self<span class="specialChar">)</span>:
<span class="comment"># Set global image directories.</span>
dirs = []
<span class="keyword">try</span>:
dirs = self.config.get(<span class="string">'directories'</span>, <span class="string">'paths'</span>).split(<span class="string">'\n'</span>)
<span class="keyword">except</span>:
<span class="keyword">pass</span>
<span class="keyword">if</span> <span class="keyword">not</span> dirs:
dirs = self.getDefaultDirs()
<span class="keyword">return</span> dirs
<span class="keyword">def</span> <span class="hilight">setWallPaperFromConfigDirs</span><span class="specialChar">(</span>self<span class="specialChar">)</span>:
self.setWallPaperFromDirList()
<span class="keyword">def</span> <span class="hilight">getConfigFileOptions</span><span class="specialChar">(</span>self, options<span class="specialChar">)</span>:
configFile = <span class="string">'pywallpaper.conf'</span>
<span class="keyword">if</span> options.configFile:
configFile = options.configFile
dirs = options.directories
self.config = SafeConfigParser()
self.config.readfp(open(configFile))
<span class="keyword">if</span> self.config.has_section(<span class="string">'global'</span>):
self.Blending = self.config.getboolean(<span class="string">'global'</span>, <span class="string">'Blending'</span>)
self.BlendRatio = self.config.getfloat(<span class="string">'global'</span>, <span class="string">'BlendRatio'</span>)
self.Crop = self.config.getboolean(<span class="string">'global'</span>, <span class="string">'Crop'</span>)
self.Fill = self.config.getboolean(<span class="string">'global'</span>, <span class="string">'Fill'</span>)
self.Gradient = self.config.getboolean(<span class="string">'global'</span>, <span class="string">'Gradient'</span>)
self.PreRotate = self.config.getboolean(<span class="string">'global'</span>, <span class="string">'PreRotate'</span>)
<span class="keyword">def</span> <span class="hilight">getCommandLineOptions</span><span class="specialChar">(</span>self<span class="specialChar">)</span>:
parser = OptionParser()
parser.add_option(<span class="string">"-t"</span>, <span class="string">"--time"</span>, dest=<span class="string">"change_time"</span>,
help = <span class="string">"Change wallpaper time in minutes (0 = change once and exit [default])"</span>,
default = <span class="int">0</span>, type = <span class="string">"int"</span>)
parser.add_option(<span class="string">"-i"</span>, <span class="string">"--image"</span>, dest=<span class="string">"singleImage"</span>, default = None,
help = <span class="string">"Set wallpaper to this image and exit (overrides -d)"</span>)
parser.add_option(<span class="string">"-d"</span>, <span class="string">"--directory"</span>, dest=<span class="string">"directories"</span>, default = [],
action=<span class="string">"append"</span>, type=<span class="string">"string"</span>,
help = <span class="string">"Add an image directory"</span>)
parser.add_option(<span class="string">"-c"</span>, <span class="string">"--config"</span>, dest=<span class="string">"configFile"</span>, default = None,
help = <span class="string">"path to alternate config file (default <working dir>/pywallpaper.conf)"</span>)
parser.add_option(<span class="string">"-w"</span>, <span class="string">"--workingdir"</span>, dest=<span class="string">"cwd"</span>, default=<span class="string">"."</span>,
help = <span class="string">"Working Directory (default .)"</span>)
(options, args) = parser.parse_args()
<span class="keyword">return</span> (options, args)
<span class="keyword">def</span> <span class="hilight">go</span><span class="specialChar">(</span>self<span class="specialChar">)</span>:
options, args = self.getCommandLineOptions()
self.getConfigFileOptions(options)
self.dirs = self.getImageDirectories()
<span class="keyword">if</span> options.cwd <span class="keyword">and</span> options.cwd != <span class="string">'.'</span>:
os.cwd(cwd)
<span class="keyword">if</span> options.singleImage:
self.setWallPaper(options.singleImage)
<span class="keyword">elif</span> <span class="keyword">not</span> options.change_time:
self.setWallPaperFromConfigDirs()
<span class="keyword">else</span>:
sleepTime = options.change_time * <span class="float">60.0</span>
<span class="keyword">while</span> True:
self.setWallPaperFromDirList()
time.sleep(sleepTime)
<span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:
d = Desktop()
d.go()
</pre>TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com1tag:blogger.com,1999:blog-21956912.post-45309390082699107002010-07-18T04:32:00.001+10:002010-07-18T04:43:03.194+10:00Belkin supportEvery problem I submit to Belkin about their wireless routers or WAPs results in the following response. Every single problem is fixed by "reboot the machine."<br />
<br />
None of the problem reports submitted had anything to do with ADSL connections.<br />
<br />
I don't think I'll ever be buying another Belkin wireless product.<br />
<hr /><pre style="font-size:x-small; font-family:Vera Bitstream Mono,Consolas,Courier New,Courier" >Let us assist you with this issue.
In this case, we would suggest you to reset the router to factory settings and re-configure it once and check.
Please follow the steps given below:
- Connect the computer to the "LAN" port on the router and connect the modem to the Internet/"WAN" port, using Ethernet cables.
- Take a paper clip, insert the paper clip in the reset hole of the router and hold it for 15 seconds.
- The power light will flash and then come back "ON" solid, indicating that the router is being restored to factory defaults.
- The corresponding lights on the front of the router should be lit up.
- Log on to the router web interface by typing in http://192.168.2.1, in the address bar of your browser.
- By default, the password is blank.
- Click on "Connection Type" in the left hand column under "Internet WAN" heading.
If the connection type is Dynamic (cable):
- Choose "Dynamic" and then click on "Next".
- Type in your Host Name , if your Internet Service Provider has provided it. Else, leave it blank.
- Click on "Change WAN MAC Address".
- Click on the button "Clone".
- Click on "Apply Changes".
If the connection type is PPPOE (DSL):
- Choose "PPPOE" and click on "Next".
- Enter the user name and password given by your Internet Service Provider.
- Save the settings.
- Click on the "Home" link at the top of the screen.
If the connection is Static:
- Choose "Static" and click on "Next".
- Enter the "IP Address", "Subnet Mask" and "ISP Gateway Address". Click on "Apply Changes".
- It would ask for the "Primary DNS" and "Secondary DNS" information. Enter the required details and click on "Apply Changes".
Note: All the required information would be provided by your ISP.
Internet Status should show "Connected" on the top right hand corner of the web page.
</pre>TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com0tag:blogger.com,1999:blog-21956912.post-50398663155583156022010-04-14T23:48:00.000+10:002010-04-14T23:48:22.845+10:00GPH Wiz and EliteI recently dusted off my misappropriated copy of the newkind source I snarfed while it was available (10 years ago, thank you Mr. Pinder), and ported it to use SDL and then to run on the Wiz (the button mappings are currently a little awkward, but, usable).<br />
<br />
I fixed up some long standing bugs in the code (suns are rendered, it doesn't crash randomly due to -ve array indexes), so it gives me something to do when I'm forced to wait (for anything, a compile to finish, for someone to finish shopping d8)<br />
<br />
It's running very nicely, it's very playable, I've replaced the scanner with the one from the Archimedes version (I also added the bumper sticker, I need to acquire some decent dice images to add the fluffy dice though). The code let you load one via file, but, that's not quite flexible enough to deal with really changing the scanners. The Archimedes one is about 30px shorter than the original one (a lot when you have 320x240 screen size!), but looks sweet.<br />
<br />
I've coverted from PCX-fonts to true-type fonts and made some of the decals transparent. I've removed all the (not-really working) code that tried to deal with different screen resolutions, and have streamlined it to deal with 320x240 (for now). I'm not sold on the "big" font I'm using right now.<br />
<br />
I'm now in the process of restructuring the code to make it a little easier to work on, the original code was controlled with globals and it's kind of ugly to try to map js buttons or mouse buttons to mode-specific key presses.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqVapXiNrD3-z6sd0KzUq2U9J3A6mEH-aaxVE32idUhK3ydPXJ84EnpnSgj6vYtbBoiHot1xIxLQPRQb18s8_CKHTcmok_4KSPkbbVdCAhE1oTgmzairlEcghDHX6nX2aniEV7Eg/s1600/EliteSS.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqVapXiNrD3-z6sd0KzUq2U9J3A6mEH-aaxVE32idUhK3ydPXJ84EnpnSgj6vYtbBoiHot1xIxLQPRQb18s8_CKHTcmok_4KSPkbbVdCAhE1oTgmzairlEcghDHX6nX2aniEV7Eg/s320/EliteSS.png" /></a></div><br />
My ToDo List is (in no particular order):<br />
<ul><li>Find some .ogg or .mp3 music to replace the 2 MIDIs, the wiz doesn't seem to have timidity or anything that SDL can use to play the midis. </li>
<li>Restructure Code to allow nicer event handling.</li>
<li>Add an Icon Bar to allow "Screen Changing" with the stylus instead of buttons.</li>
<li>Add the extra Archimedes ships.</li>
<li>Add convoy, formation, and independent battle logic.</li>
<li>Add "trimble" mission.</li>
<li>Add fluffy dice (as an option perhaps only at a certain ranking). </li>
<li>Add IFS equipment.</li>
<li>Convert to OpenGL instead of original 3D.</li>
<li>Re-add the screen resolution code (in a better fashion) so I can transfer my saved games back/forth and play at a nice resolution when I want to.</li>
</ul>TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com0tag:blogger.com,1999:blog-21956912.post-8830511443345112102010-04-04T20:39:00.001+10:002010-04-04T20:40:32.515+10:00Windows 7 and UTC: Caveat EmptorIF you are running your BIOS Clock at UTC, <br />
AND you are running Windows 7 in your local timezone<br />
AND your local timezone is WEST of UTC, <br />
AND ( Daylight Savings (Ends OR Finishes) <br />
OR the year changes )<br />
THEN your machine will lock up<br />
AND will not boot<br />
AND system restore will not work<br />
AND recovery console will not work<br />
UNTIL midnight UTC is reached (because internally some value goes negative (which is very largely positive for unsigned values)).<br />
<br />
It locks so hard, even trying to boot to safe mode, that the caps lock light won't even come on.<br />
<br />
If you can boot up in a timezone EAST of UTC it comes up OK.TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com0tag:blogger.com,1999:blog-21956912.post-16222040612020089002010-03-06T16:15:00.001+11:002010-03-06T16:15:37.621+11:00Fallout 3 -- Crash FixedI've been swearing at Bethesda Softworks for some time since my Fallout 3 stopped working for no apparent reason, when I upgraded from Vista x64 to Windows 7 x64.<br />
<br />
It failed once before and it turned out to be an nVidia video driver update, and a new update fixed it. However it's been over 6 months now and multiple nVidia updates have failed to fix it.<br />
<br />
I spent some time this weekend debugging it, and discovered it's some kind of issue with Fallout 3 and DisplayLink drivers. I had tried unplugging my Mimo 7" USB auxillary monitor before, and Fallout 3 had still crashed. It turns out, that it was still crashing inside Fallout 3 when it returned from the DisplayLink drivers. I assume there's some monitor iteration or some other call going on, and it's not happy when something comes back with bounds smaller than the main screen.<br />
<br />
Anyhow, if you have issues with Fallout 3 and you have "other" video/monitor drivers, try uninstalling them.TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com2tag:blogger.com,1999:blog-21956912.post-17613253031422209072010-03-06T02:59:00.000+11:002010-03-06T02:59:07.665+11:00Iterative Collatz in Python (with resume)I'm assumming there will be a lot of people looking to play with Collatz soon.<br />
<br />
Here's a non-recursing version that will resume when you restart it.<br />
Given all numbers to 2^58 have already been checked you might be there a while...<br />
<br />
It's trivial to get it to dump a CSV with the steps for graphing, but, this one doesn't do that (but gives you the steps so that you can).<br />
<br />
If you don't know what this is for, it doesn't matter.. (but you can google it...)<br />
<br />
<pre style="font-family: andale mono, courier new; font-size: 10px">import os
def collatz(n):
steps = []
stAppend = steps.append
while n > 1:
stAppend(n)
while not (n & 0x1):
n >>= 1
stAppend(n)
if n == 1:
break
n = n * 3 + 1
return steps
if __name__ == '__main__':
n = 2
if os.access('collatz.prg', os.F_OK|os.R_OK|os.W_OK):
n = int(open('collatz.prg', 'rb').read())
while True:
steps = collatz(n)
open('collatz.prg', 'wb').write(str(n))
print n, len(steps)
n += 1
</pre>TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com0tag:blogger.com,1999:blog-21956912.post-11019520016103807852010-02-26T23:26:00.001+11:002010-02-26T23:28:02.460+11:00Adding a "submit on enter" in ExtJS formpanels.I had to retrospectively setup "submit on enter" to some existing ExtJS forms.<br />
Googling only turned up some fairly unappetizing solutions.<br />
Here's a way using defaults. Just change the getCmp or parametize it if you want, I've left it as a constant for illustration purposes.<br />
Add this to your FormPanel constructor and all your fields will get "submit-on-enter".<br />
If you only want 1 field to have it then just add everything inside the defaults to that 1 field.<br />
<br />
<pre style="font-size:10px; font-family:Andale Mono,Courier New;">defaults:{
enableKeyEvents:true,
listeners:{
specialKey: function(field, el)
{
if(el.getKey() == Ext.EventObject.ENTER)
{
Ext.getCmp('address-search-button').fireEvent('click');
}
}
}
}
</pre>TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com5tag:blogger.com,1999:blog-21956912.post-68381232009781918422010-02-20T05:26:00.004+11:002010-02-26T23:20:01.437+11:00Decode Encrypted CueCat Output With Ugly Python<pre style="font-family:Andale Mono,Courier New;font-size:10px;">import sys; from string import maketrans as m; from binascii import a2b_uu as d
q = lambda x,y: ''.join([chr(c) for c in range(ord(x), ord(y) + 1)])
t = m(q('a','z') + q('A','Z') + q('0','9') + '+-', q(' ','_'))
def u(st): return ''.join([chr(ord(c) ^ 67) for c in d(chr(32 + 3 * len(st) / 4) + st)])
print "ID: %s, Type: %s, Barcode: %s"%(tuple([u(b.translate(t)) for b in sys.stdin.read().split('.')[1:-1]]))
</pre>TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com0tag:blogger.com,1999:blog-21956912.post-31722806399560257152010-02-13T23:59:00.006+11:002010-02-14T02:30:09.114+11:0012 Bar Blues on an Arduino<p>Using a small 8ohm analogue speaker hooked up to pin 11, by strobing the pin, I generate a square wave (a kind of annoying timbre to be honest). <br />
I generate 2 octaves of semitones starting with A-220 and index into it. <br />
The timing is currently inaccurate as the note length for lower notes runs slightly longer (half a pulse width) than higher notes due to how the strobing currently works. It's surprisingly noticeable. I need to work on that to make it more consistent. Probably by using timer interrupts instead of delays. <br />
</p><h4>To do:</h4><p>Alter the volume by using analogWrite() to set the duty cycle of the pin... 255 = loud 0 = off. <br />
I think I can use that mechanism to generate other waveforms, I'll probably try sawtooth next. <br />
Proper ADSR waveforms. <br />
Multichannel output (haw haw).</p><br />
<pre style="font-family: Andale Mono, Courier New; font-size:10px">const int baseFreq = 220; // A
const int numHalfTones = 24; // 2 Octaves
long frequencies[numHalfTones];
long halfFreqs[numHalfTones];
/* 12 semi-tones per octave
| Bf| | | C#| Ef| | |F# |G# |
-+---+ | +---+---+ | +---+---+-
| A | B | C | D | E | F | G | A |
+---+---+---+---+---+---+---+---+
2 octaves:
0 1 2 3 4 5 6 7 8 9 10 11
A Bf B C C# D Ef E F F# G G#
12 13 14 15 16 17 18 19 20 21 22 23
*/
int seq[] = {
3, 7, 10, 12, 13, 12, 10 , 7,
3, 7, 10, 12, 13, 12, 10 , 7,
8, 12, 15, 17, 18, 17, 15, 12,
3, 7, 10, 12, 13, 12, 10 , 7,
10, 14, 17, -1, 8, 12, 15, -1
};
int notes = 40;
long getTimeHigh(int i)
{
return halfFreqs[i];
};
void ToneGen(void)
{
float baseMult;
int i;
int lastTone = baseFreq;
baseMult = pow(2.0 , 0.083333);
for(i = 0; i < numHalfTones; ++i)
{
long frequency = baseFreq;
if(i)
{
frequency = (0.5 + (frequencies[i - 1] * baseMult));
}
frequencies[i] = frequency;
halfFreqs[i] = (0.5 + (1000000.0 / frequency / 2.0));
}
};
void setup(void) {
pinMode(11, OUTPUT);
ToneGen();
Serial.begin(57600);
}
int rest_count = 100;
long duration = (60 * 1000000) / 288;
void playNote(int idx)
{
long tone = 0;
if (idx >= 0)
{
tone = getTimeHigh(idx);
}
long endTime = micros() + duration ;
if (tone > 0)
{
int val = HIGH;
while (micros() < endTime)
{
digitalWrite(11,val);
delayMicroseconds(tone);
val = !val;
}
}
else
{
delay(duration / 1000);
}
digitalWrite(11, LOW);
}
void loop(void) {
analogWrite(11, 0);
for(int i = 0; i < notes; ++i)
{
playNote(seq[i]);
delay(10);
}
}
</pre>TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com0tag:blogger.com,1999:blog-21956912.post-35892947095069387892007-06-08T03:56:00.000+10:002007-06-08T04:01:31.910+10:00Steampunk LCD MonitorTo go with the steampunk keyboard and mouse, the guys over at steampunk workshop have made an absolutely amazing steampunk shell for and LCD-Flat panel.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://steampunkworkshop.com.nyud.net:8080/images/M19.jpg"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px;" src="http://steampunkworkshop.com.nyud.net:8080/images/M19.jpg" border="0" alt="" /></a><br /><br />You can see it being made here <a href="http://steampunkworkshop.com/lcd.shtml">here</a>.TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com0tag:blogger.com,1999:blog-21956912.post-16576673104505662162007-06-07T09:35:00.000+10:002007-06-07T09:41:25.483+10:00How to scan in 3d using milk, lego, and a webcam.<a href="http://www.instructables.com/id/E16Y5T8F22U9YWA/">This instructable</a> shows how to create 3d models using milk, lego and a webcam. I love low-tech solutions, and this ranks right up there.<br /><br />This video shows how it works;<br /><br /><object width="400" height="325"><br /><param value="http://www.youtube.com/v/XSrW-wAWZe4" name="movie"/><br /><param value="transparent" name="wmode"/><br /><embed width="400" height="325" wmode="transparent" type="application/x-shockwave-flash" src="http://www.youtube.com/v/XSrW-wAWZe4"></embed><br /></object>TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com0tag:blogger.com,1999:blog-21956912.post-82308443100839403422007-03-19T20:27:00.000+11:002007-03-19T21:13:39.454+11:00Sendfile Patch for Zope2I've put together a patch for Zope that allows code to use the sendfile system call to transfer data out of Zope.<br /><br />As this requires a file object, it's only available for use from trusted code, so that means inside a Product or an External method.<br /><br />The good news is, that it's fairly easy to write an External method that does something useful like serve contents from a directory.<br /><br />Here's an example external method that serves files from '/shared/images'<br /><pre class="code"><br />import os<br />directory = <span class="string">'/shared/images'</span><br /><br /><span class="keyword">def</span> <span class="hilight">Image</span><span class="specialChar">(</span>self, filename<span class="specialChar">)</span>:<br /> newPath = os.path.join(directory, filename)<br /> <span class="keyword">if</span> <span class="keyword">not</span> os.access(newPath, os.F_OK|os.R_OK):<br /> self.REQUEST.RESPONSE.setStatus(<span class="int">404</span>)<br /> <span class="keyword">return</span> <span class="string">''</span><br /> f = open(newPath, <span class="string">'rb'</span>)<br /> self.REQUEST.RESPONSE.sendfile(f, content_type=<span class="string">'image/jpeg'</span>, other_headers = {<span class="string">'Content-Disposition'</span>, <span class="string">'inline;filename=<span class="specialChar">%s</span>'</span><span class="specialChar">%</span>(filename))<br /> f.close()<br /> <span class="keyword">return</span> <span class="string">''</span><br /><br /></pre>It uses the sendfile wrapper module from <a href="http://tautology.org/software/python-modules/sendfile">here</a>.<br /><br />It gives you a speed up of 2-3 times serving content out of Zope from the filesystem.<br />I also have a patch for ExternalFile to let this use the sendfile patch.<br /><br />You can get the code and the patch from <a href="http://www.zope.org/Members/TheJester/Sendfile%20Patch">zope.org</a>TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com2tag:blogger.com,1999:blog-21956912.post-90707884254913952892007-02-24T08:30:00.000+11:002007-06-08T04:33:36.672+10:00Dick Cheney vs George OrwellIn an article in the Sydney Morning Herald titled <a href="http://www.smh.com.au/news/national/terrorists-aiming-for-empire/2007/02/23/1171734021090.html">Terrorists have ambitions of empire, says Cheney</a> Dick Cheney is reported to have said;<br /><blockquote>[Terrorists' ultimate aim is to establish] "a caliphate covering a region from Spain, across North Africa, through the Middle East and South Asia, all the way to Indonesia -and it wouldn't stop there."</blockquote><br />So this would mean we would see a map almost like this one (courtesty of wikipedia) where the yellow zone would indicate this caliphate;<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://upload.wikimedia.org/wikipedia/commons/thumb/1/1f/1984_Orwell_arrows_2.png/800px-1984_Orwell_arrows_2.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px;" src="http://upload.wikimedia.org/wikipedia/commons/thumb/1/1f/1984_Orwell_arrows_2.png/800px-1984_Orwell_arrows_2.png" alt="" border="0" /></a><br />The problem is, the yellow zones represent the site of the "Perpetual War" in George Orwell's<span style="font-style: italic;"> 1984</span>. In <span style="font-style: italic;">1984</span> the perpetual war is unwinnable (and maybe fabricated), and is one of the mechanisms to to keep the population under control.<br /><br />Amusing isn't it, that an Orwelling dystopia may be upon us?TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com0tag:blogger.com,1999:blog-21956912.post-1821842966281653002007-02-17T01:18:00.000+11:002007-02-18T01:31:26.044+11:00ZopeTrac UpdatedI have updated ZopeTrac to 0.10.3, which makes it work with Trac 0.10.3.<br /><br />You can get it from here; <a href="http://www.zope.org/Members/TheJester/ZopeTrac/ZopeTrac/">here.</a><br /><br />I will try to mimic the Trac release numbers so you can tell what version of Trac it last worked with.TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com0tag:blogger.com,1999:blog-21956912.post-67923189122679865672007-02-13T23:16:00.000+11:002007-02-13T23:17:45.931+11:00Some Advertisers are stupid...<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEw-GvqP4VmylsetJoLySxVEBkgWXBzeJmfcVV2Xu5coRkZGR0fONExhyphenhyphenmG9EDxPgBClPQ2wf9On0G0RjJPdFS7TPPBCZ4gaEvYr0uBRyV0y-PHm1WK6yfM1Qo3ioOodRXdWOdAw/s1600-h/FalseAdvert.jpg"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEw-GvqP4VmylsetJoLySxVEBkgWXBzeJmfcVV2Xu5coRkZGR0fONExhyphenhyphenmG9EDxPgBClPQ2wf9On0G0RjJPdFS7TPPBCZ4gaEvYr0uBRyV0y-PHm1WK6yfM1Qo3ioOodRXdWOdAw/s200/FalseAdvert.jpg" alt="" id="BLOGGER_PHOTO_ID_5030991831649187922" border="0" /></a>Whilst doing a search on how to lodge a false advertising complaint, the following advertisement appeared. Perhaps these people need to be more selective in the terms they want to advertise with.<br /><br />Dumb.TJhttp://www.blogger.com/profile/15256046011166077508noreply@blogger.com0