====== Coding ====== profile for RobM on Stack Exchange, a network of free, community-driven Q&A sites * [[:coding:version_control]] --- Documents my attempt to switch from SVN to GIT, or at least learn to use both * [[coding:utilities]] --- Collection of scripts I've come to rely on * [[coding:vim:source_nav]] --- Notes on browsing source-code with VIM Anything code related I want to retain. ===== Finished / Useable ===== ==== USB Implementation ==== Definitely the most popular page on my site, my [[project|Final Year Project]] was an ambitious plan to create a Game Boy Advance <-> PC communications link that worked via USB. The project was a success, created using hobbyist electronics (a MicroChip(tm) PIC-chip and a more specialised by easily-obtained USB bus-interfacing chip). This basically involved assembling some hardware and then implementing the USB specification in a firmware which ran on this hardware. All my code and notes area available, but by far the most popular area are the [[/downloads/Project%20Report.pdf|project report]] and it's [[/downloads/Project%20Report%20Disc%20content.zip|accompanying disc content]] (complete source trees and such), the [[/project/usb#master_schematic_pdiusbd12_amp:pic16f877|master schematic]] for the hardware and my [[/project/journal0|project journal]] (which, though unorganised and hard to read, is very worth while when searching for answers about USB development). So, if you are considering working on a USB device as a hobby or perhaps as an academic project, you may find some useful information in my [[/project|USB project]]. //At the time of writing (Feb 2006) my project report is being downloaded 35 times **per day** on average. ^_^// ==== TV Series Renamer ==== I've written a rather lovely (PERL) script to rename my TV & Anime series either by copying'n'pasting from a website which lists the episode titles (such as [[http://anidb.info|AniDB]] or [[http://www.tv.com|TV.com]]), by providing the script with the URL of the appropriate page on one of these sites, or by leaving it to search the sites it supports on your behalf and using whatever result it gets. There are many examples of how this works and how to use this script on it's page. Check it out: [[coding/File Renamer]]. ==== Flash Menu ==== I made a nifty Flash menu system for ChrisWhiteConservative.com((Note I don't take an active interest in UK politics, as I'm not allowed to vote, on account of being a foreigner of Dutch nationality)), it's so easy to use that I simply had to put it up here. It was my first serious attempt of creating some ActionScript in Flash, and it worked quite well. There is some commented code to do nifty colour effects, but I didn't use them in the end. The menu data is fed to the script from a text file by the name of ''menu.txt'', which is placed in the root of the site (this can easily by altered in the ActionScript to be what ever you want). The menu from the site I made was as follows: menu= Welcome! Information News;http://www.bbc.co.uk Theme People Meet Chris Video and Interview Biography Gallery Policies Personal Local National Interactive Forum;http://www.phpbb.com Quiz Competition Join Us Events Membership / Donate Contact www.Conservatives.com;http://www.Conservatives.com For clarity, this only includes a few (harmless) links. As I hope it obvious, you simply indent child items under their parents, and you make links by adding a semi-colon ('';'') and link at the end of a line. That's it. You update the ''menu.txt'' file and the menu changes when it is next loaded (assuming you're browser didn't cache this file). Grab the original Flash MX document (''.fla''), Shockwave flash movie (''.swf'') and sample menu (''menu.txt'') file in this handy ''.rar'' file, made using my, now legitamate, copy of WinRAR! {{coding:flashmenu.rar|Download my lovely home-made Flash menu system}} ==== phpBB Rank Genres ==== While I was webführer of [[http://www.animesoc.co.uk|www.animesoc.co.uk]] I created a modification for phpBB which extended the rank system which comes as standard to allow progression along multiple path: genres. For instance you might have the following rank system: | ^ Genre ^^^ ^ Posts ^ 1984 ^ Corporate ^ Academia ^ ^ 0 - | Proletariat | Temp | Fresher | ^ 100 - | Outer Party | Contractor | Second Year | ^ ... | ... | ... | ... | ^ 4000+ | Big Brother | Chief Executive Officer | Chancellor | Each of these genres has a different name for what is effectively the same social standing in the community, and each instance can have a different picture. Check it out: [[coding:phpbb_rank_genre]] ===== Snippets ===== ==== List -> SQL lookup table ==== Here's a handy replacement expression (i.e. substituting regular expression) you can use to convert a list into a lookup table. In this particular instance, I wanted to convert the text-field "properties.area" into a lookup table "property_areas", so this was the code to make the insert / update SQL. From: ^(.*)$ to: INSERT INTO property_areas SET id=\i, area='\0';\nUPDATE properties SET area=\i WHERE area='\0'; This was used in [[http://www.textpad.com|Textpad]] (in POSIX mode), so I am not sure if the ''"\i"'' is available in other flavours. It means "incremented sequential", specifically it goes 1, 2, 3... in this case --- once per line, so even though the above refers to ''"\i"'' it is only incremented on each match, not each replacement. **Note:** This is obsolete to me now, as I've become a [[http://www.vim.org|VIM]] fiend! ==== Shake the current X window ==== Outputs some random escapes codes to move the terminal window, essentially causing it to "shake". #!/bin/bash for i in $(seq 90 100 | shuf); do for j in $(seq 90 100 | shuf); do echo -en "\e[3;$i;$j;t"; done done ===== Ideas ===== Stuff I'd like to try one day, or did want to try when I wrote. If you attempt any of these I'd be interested in hearing from you! Email [[robert.meerman@gmail.com]] ==== Per-window "default" windows colours ==== As I frequently switch between the black-on-white default colour scheme, and my night-time friendly white-on-black, many programs fall short of the accessibility requirements this places on them. For instance, Process Explorer uses some odd grey colour as it's foreground when the background of a line is coloured ("highlighted"), however it uses white-on-black perfectly for ordinary rows. If I could manipulate the default colour values it fetches from windows when it starts-up, I'd be able to over come this. Similarly I ought to be able to over come similar problems in other software. ==== Narrative Summary Engine for RPGs ==== I'm an avid gamer, and would love to work in the industry; to that end I enjoy tinking with ideas and concepts on things which I'd like to see in a game. Among other things I proposed a Narrative Summary Engine for RPGs as my final year project, before encoutering resource problems (i.e. a game to work with). The ultimate goal of which was to generate an informative and engaging summary of what you did last time (story-wise) in the game, akin to how television shows reel the audience back into the mood of the last cliffhanger with, say, "Previously, on 24". Many RPG games are fairly linear in what //must// be done (though often leaving the player free to go about it as indirectly as they like), so it ought to be possible to compute what must be done next and what the last major event was, and hence produce a summary which also hints at what must be done. ==== Complaints Centre in MMORPG ==== If I were a Games Master in an MMORPG, I'd definately errect a massive, overly luxurious and imposing temple to honour myself, and be sure to make an absolutely massive statue of myself/avatar the main attraction. The mere players wishing to complain would involuntarily humble themselves before it before their complaint is heard. The intended effect being humourous, not arrogant. Also, this incredible temple would lie on the otherside of a very unimpressive, rickety, ivy-covered wooden door with a very small sign which reads "Complaints Department", probably buried in an alley of a busy city-centre. :-) ==== Impact animations in Flash ==== Write some ActionScript to create impact animation, given the angle/direction of impact. * Copy the graphic/movie to another layer, and scale it by about 120% * Add a mask layer to this, with a slit-window which will be orientated perpendicularly to the direction of impact * Move this window from the point of impact, along the direction of impact until it leaves the movie bounding box. This ought to basically create the appearance of a ripple propagating through the graphic/movie. Use this effect multiple times on the same object, with different scaling to achieve (possibly) better results. ===== Notes ===== ==== Cscope and Paths with spaces in them ==== If you see errors like this: Error detected while processing /home/robmee01/.vim/plugin/cscope_maps.vim: line 42: cs_read_prompt EOF: No such file or directory E609: Cscope error: cscope: cannot read trailer offset from file cscope.out Press ENTER or type command to continue It's probably because the header in [[wp>cscope]] database files (''cscope.out'') is space-delimited, and if the directory the database was created in contained spaces it won't parse correctly. In [[wp>Cygwin]] what ''cscope'' and ''bash'' think the current directory is may be different. In my case I saw this: robmee01@e100325 ~/Projects/pixmap_test_win32 $ head -n1 cscope.out cscope 15 /cygdrive/c/Documents and Settings/robmee01/My Documents/Visual Studio 2005/Projects/pixmap_test_win32 -q 0000002403 0000137225 (Note that my home directory is __not__ in ''Documents and Settings'', but the default ''/home''.) I fixed this by replacing the path in ''cscope.out'' with an equivalent path that does not contain spaces (it doesn't seem possible to escape spaces...) and fixed-up the "trailer offset" at the end of the line. === Trailer Offset === See the [[http://www1.bell-labs.com/project/wwexptools/cscope/cscope.html|cscope toolman page]] and look at the section on "Symbol Database Format". The trailer offset is a byte-offset relative to the beginning of the file. Therefore, if you change the path in the header and make your file 20 bytes shorter, than your trailer offset should be reduced by 20 as well. == Eventually I'll update my ''~/cscope_gen.sh'' script, or recompile cscope to parse over backslash escapes in the header line... I came to this solution after reading [[http://www.cygwin.com/ml/cygwin-xfree/2007-01/msg00009.html|this post]]. ==== Win32 Console & ANSI ==== Win32 console's don't support ANSI properly, which is just plain annoying. In PERL you can overcome this with the package from [[http://www.bribes.org/perl/wANSIConsole.html|bribes.org]] and then adding the following line to the top of a script: use Win32::Console::ANSI; ====== VIM Snippets ====== [[/vim|Vim snippets have moved]]