Archive for the 'software' Category
Programmer-relevant whitespace in python
A comment was made at #rsparlyredux along the lines that while python’s enforcement of proper indentation stops people from not indenting at all, it also stops them from adding extra indentation, and sometimes extra indentation can be useful for the programmer. IIRC the example was OpenGL, where a common pattern in C is:
gl_start(TRIANGLE); gl_add_vertex(0, 0, 0); gl_add_vertex(0, 1, 0); gl_add_vertex(0, 0, 1); gl_end();
If you tried to do this using python’s standard syntax, it would complain that the indentation of the middle lines is unnecessary. However, you can actually do this in python, by turning the block of code into one logical code line – it’s maybe 5% extra typing when you’re dealing with this edge-case, but I consider that a fair trade for 10% less typing under normal circumstances:
gl_start(TRIANGLE); \ gl_add_vertex(0, 0, 0); \ gl_add_vertex(0, 1, 0); \ gl_add_vertex(0, 0, 1); \ gl_end()
(semicolon to separate multiple statements on one line, backslash to keep the whole thing as one logical line, so internal whitespace is ignored)
Edit: there is an even more pythonic syntax for this sort of thing. I’m not sure the stock GL library has been updated to support the with
statement yet, but in theory:
Edit edit: A lovely Rory had the same thought, and has actually written the code to make it work, see first comment /o/
with gl_start(TRIANGLE): gl_add_vertex(0, 0, 0) gl_add_vertex(0, 1, 0) gl_add_vertex(0, 0, 1)
(gl_end() is called automatically at the end of the `with` block)
Posted November 26th, 2011 by Shish, in software, tech
Dwarf Fortress
One of my dwarves suffered a crippling spinal injury while out hunting for food; he was carried home alive, but unconscious, and has since slipped into a coma with no signs of recovery, lasting a year so far.
If he wakes, he’ll find that he has no living friends or family, and no legs to walk to the social room to make new ones; his entire life will consist of being spoon fed mushroom pulp by the nurses, slowly going insane, and dying of old age.
The alternative is to flood his room so that he drowns in his sleep.
What do I do? :S
(Incidentally, Dwarf Fortress is an incredible game — possibly the only one I know of with enough detail and interacting elements in it for plot to emerge out of nowhere… (Nethack is perhaps a more detailed world, but the AI is pretty limited, with no scope for creating narration-worthy communities))
Posted December 25th, 2009 by Shish, in pimp, software
On linux and hardware
Because the world doesn’t have enough anecdotal evidence already:
On my gaming / media PC (custom built):
Graphics card, NVidia 8600 GT: ubuntu detects my monitor’s native resolution, runs ok using the standard drivers, and pops up a message asking if it should download the accelerated drivers automatically; windows runs at 640×480 until you install accelerated drivers from CD or google.
GPU accelerated h264 decoding: Linux yes, windows no.
Webcam, labtec thing: linux works out of the box; windows requires drivers from CD, and then the drivers crash whenever they’re used (and sometimes when they aren’t)
Extra USB ports: Linux PCMCIA worked in a fraction of a second (it was running faster than I could look at the “connected hardware” screen), windows PCI worked fine after 5 minutes of “you have new hardware!” “It is a PCI card!” “The PCI card has USB ports!” “There are 4 ports!” “Each port is USB!” “The USB version is 2.0!”…
TV capture card, Hauppage PCI thing: Ubuntu works out of the box, windows requires googling for drivers, and those drivers install crappy utility software.
Phone (Sony Ericsson k750i) as a modem: Ubuntu detects that the phone can be used as a modem, and pops up a message asking for phone service login details; windows detects the phone can be used as a modem, haven’t yet figured out how to use it.
Phone as USB storage: Linux works out of the box, windows requires googling for drivers.
Phone as bluetooth remote control for media player: Ubuntu works out of the box, windows works out of the box (No problems, no glitches, no googling for drivers; well done microsoft!)
And for the other PC (IBM thinkcentre):
Graphics (onboard intel 865): Ubuntu 9.04 broke 3D acceleration, all other distros and other versions of ubuntu work out of the box; windows works after googling for drivers
Sound (onboard intel something): Linux works out of the box, including features like disabling onboard speakers when external speakers are plugged in, and disabling external speakers when headphones are plugged in; windows works without advanced features after googling for drivers (and these particular drivers are a bitch to find. I suspect that I might not even have exactly the right ones, hence the feature lack :-/)
Network (onboard intel thing): Linux works out of the box, windows works after googling for drivers… yes. For those who haven’t spotted it, the /network card/ requires downloading drivers using /the network/ :-P
Network (atheros based wifi): Linux works out of the box, windows requires separate drivers
Posted June 26th, 2009 by Shish, in pimp, software, tech
Opera: still awesome
Needing an impromptu web browsing kiosk, I wonder if opera has any options which could be useful; so I try opera –help, and the first thing I see is -kioskhelp. Trying that option, it seems that it has all the features I need built in \o/
It also has a presentation mode, so with a little CSS you can have a web page which works equally well in a browser or as part of a slideshow~
And it’s still smaller and faster than firefox :P
Posted November 7th, 2008 by Shish, in pimp, software
Scaling~
More scaling with Travmap
LightTPD is win. Apache + mod_php + mod_python + mod_perl = 100MB per process, of which there are 10. Lighty does all the same stuff, in a single 30MB process \o/ Switching over has made travmap fast again, leaving a proxied apache behind to run the more complicated, less popular things~
Posted July 25th, 2007 by Shish, in pimp, software
Monty <3
19:57 >>> Mithrandir has joined #cs 19:57 [Monty] Thank goodness, Mithrandir is back! 21:52 [Shish] Monty: why do you never greet me? D: 21:52 [Monty] classics 21:53 [Shish] Monty: you only greet old timers? fair enough... 21:53 [Monty] apache/php job 21:53 [Shish] Monty: get it away from me! 21:53 [Monty] ffs 21:53 [Shish] Monty: no offence, your job offers are appreciated, I just react that way to php... 21:53 [Monty] nobody seems that size screw i hate cb302 21:54 [Shish] Monty: I suppose cb302 could be described as a screw, and I didn't like it either :S 21:54 [Monty] yay! 21:55 * Shish huggles monty for being better at the turing test than several people he knows... 21:55 [Monty] <3 21:55 [Shish] <3
Posted June 5th, 2007 by Shish, in pimp, software
Auto-login & desktop setup
In further automation, I tired of logging in and opening and resizing xterms, so taking bits from the mythtv wiki, I set up my desktop to automatically log me in and start all my usual programs. Of particular note is xterm’s “geometry” option, which allows you to set the position and size from the command line. Also useful is the “class” option, so that those of us with awesome window managers (enlightenment) can set them to remember position / stacking layer / border style / etc, and assign the remembered values to windows with set classes. For example, whenever I start a window with class “xterm_starter” (ie, by running “xterm -class xterm_starter”), enlightenment will notice it, shrink it, and move it to the corner of my screen, ready to start things from~
Posted June 1st, 2007 by Shish, in pimp, software, tech
SLEK
Part one of some notes on automation:
Having tired of keeping ~20 shell accounts up to date with my preferred settings, I made a script to do it. Snippets which other people may find useful are:
Only doing things if an app is installed:
is_installed() { if type -p $1 > /dev/null ; then return 0 else return 1 fi } if is_installed mplayer ; then ... do mplayer specific things ... fi
Outputting large amounts of text from the script into the config file:
cat > ~/.vimrc <<EOD syntax enable set autoindent set autowrite set nocompatible " Use Vim defaults instead of 100% vi compatibility set backspace=indent,eol,start " more powerful backspacing set ruler set foldmethod=marker if v:version >= 700 set spelllang=en_gb set spellfile=~/.vimspell.en_gb.add set spellfile=~/.vimspell.add endif EOD cat > ~/.inputrc <<EOD "\e[A": history-search-backward "\e[B": history-search-forward set completion-ignore-case On #set editing-mode vi set mark-symlinked-directories On EOD cat > ~/.bash_logout <<EOD #!/bin/bash if [ "\$SHLVL" = 1 ]; then [ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q fi EOD chmod +x ~/.bash_logout
Now using those, I have all my important settings stored in one shell script. In order to push settings to another host, I can run “cat slek2.sh | ssh user@host.com”, which doesn’t even create any temporary files on the other side of the connection \o/
(Note: the post title, and the script, are called “slek”, which was originally a typo on “skel”, but then got made into “shish’s linux enhancement kit”. Though it’s also tested and working fine on solaris…)
Posted June 1st, 2007 by Shish, in pimp, software, tech
TravMap’s somewhat-late Birthday
I forget exactly when the project was started, but monitoring started a year ago. Thus I shall reminice:
Originally, a bunch of people in an IRC channel I hang out in decided to play Travian. As there were about 20 of us, keeping track was a pain, so I decided to make a map. This first version of the map was an SVG file drafted in Inkscape, edited by hand, and saved as a PNG image.
Pretty soon I got bored of updating by hand, and started looking for a way to automate things. Thankfully, the travian creators decided to be awesome and give out a dump of part of their database \o/ I put it into a local SQLite database so that it could be searched easily. Seeing as this was just a 5 minute hack that nobody other than myself would ever use or even see, I decided to use PHP to write the front end…
After a couple of weeks of adding features, I noticed that it could be useful to other people, so I posted about it on the forums. It ended up being quite popular, and I got several feature requests~ I also added support for other servers, and from there, to other languages. Having people offer to help with translation has been very motivational — It’s nice to know that people care about the project~
Talking about other languages, an interesting note on culture; when an American server is added, I get bug reports along the lines of “Type: Defect // Priority: Critical // The new server was added 3 hours ago, why is it not on travmap yet?!”. When a European server is added, the report is more like “Type: Enhancement // Priority: Minor // There is a new travian server at s2.travian.foo, please can you add it to your list? Thankyou :)”
Another few weeks later I had broken all my web serving records; I was serving tens of megabytes per day, and my server was melting — getting a P2 200MHz box with 64MB RAM to search through 200MB of database several times a second was painful. Switching to highly indexed MySQL made things better, but still bad. I ended up buying a load more RAM, ending up at 256MB. This was OK for a couple of months, until the database grew to be again too large to fit in memory… It got to the point where it was being queried faster than it could respond, so it got slower, and things stacked up exponentially — load average broke 60 within minutes of apache being started :-/
Eventually I gave up on self hosting, and moved across to dreamhost — thanks to the wonders of overselling, they had tons of spare processing power, memory, and bandwidth. Aside from datacenter problems, they’ve been pretty cool.
Since then, growth has been pretty steady. The database is now over 500MB, going over a hit a second at peak times (That’s quite a lot of traffic, nearing a gig a day now…). I also notice that dreamhost moved me to a different database server without telling me :|
Also I figured that with 10,000 visitors per day, there ought to be some way of making some money out of it — putting up a “please pay for my hosting” link earned me a grand total of $5 ($4.50 once paypal took their cut) from one guy — to this day, the only money I’ve made directly from programming ^_^ About a month ago I put some ads on the site to see how effective they were, and since then I’ve made enough to cover nearly half of that 256MB RAM I bought so long ago — another 3-4 months of the same earnings, and I’ll have got as much money out of the project as I’d put in XD
Overall, it’s been a fun year — I’ve learned lots about caching and optimisation, and how much PHP sucks (I *really* wish I’d written it in something else, I didn’t know it’d get so big…); I haven’t actually played travian for a few months now, I’m just sticking with the project because it’s enjoyable~
I forget how I was going to end my rambling, so I shall do so abruptly. End.
Posted March 15th, 2007 by Shish, in software, stats, tech, web