Posts

Showing posts with the label programming

Review: Javascript, The Good Parts, by Douglas Crockford

I'm convinced  " JavaScript, The Good Parts " is one of the best JavaScript books for JavaScript doubters, especially those coming from a traditional object-oriented language like me. It really addresses whether JavaScript is just a mess (it definitely has messy parts) or whether there is something good in there. I'm convinced that by avoiding some problematic parts of the language, there is a very useful, functional language core that can express some interesting use-patterns. One of the cool concepts emphasized is that JavaScript has object-inheritance, not class-inheritance. There are no classes. Instead, you can inherit from an object. Something that looks like a class is actually just an object that you essentially make copies of and use in a consistent way. One of the implications is there are mixin/inheritance patterns that can't be expressed in Java/C++ that you can do in JavaScript. I haven't gotten my head around when they might be the best way t...

Review: Learning Javascript, by Shelley Powers

I read the 2nd edition , but it's been updated recently to the 3rd edition by a different author. This is a basic programming book, that tries to be fairly complete in covering all the features and pieces of Javascript. It includes an intro to the DOM and AJAX. It's not a reference like " The Definitive Guide ", but it's still quite easy to find specific information. It's a bit boring, and feels encyclopedic. I was wondering about some of Javascript's quirks and corners, but I didn't get much help or explanation in this book. I'd say "eh, it's ok" for a recommendation. Then I was pointed to  " Javascript, The Good Parts ." Now there's  the book I wanted to read. Review forthcoming...

Review: Build an HTML5 Game

Build and HTML5 Game , A Developer's Guild with CSS and Javascript, by Karl Bunyan. 2015. On Amazon This book walks through creating a 'bubble shooter' browser game, similar to Puzzle Bobble  or Snood . It uses jQuery and Modernizr script libraries to avoid browser-specific concerns, and Modernizr for loading scripts. The first version uses the DOM to position and animate game elements (bubble), and shows custom animation in jQuery. It discusses which animations are possible in pure CSS3, as well. I found it interesting that the book moves on to a second version, where the game board is completely contained in an HTML5 Canvas, and all animation is handled inside the canvas, using calls that are compatible with the DOM version - so the older version can run on old browsers that don't properly support Canvas. That structure seems useful to think about. I would have liked to see a more complex game, like a platformer or side-scroller, but that would have swelled the...

Angular 2.0 and Typescript meetup

Attended the  Getting started on Angular2 with TypeScript  meetup last night. Good attendance - the room at MetLife was full. It was a beginner tutorial, but since Angular2 is quite different from AngularJS and not that old, it's definitely what was needed. The presentation by  Kumanan Murugesan  was pretty smooth, and there were lots of useful questions.  I met someone (Jack?) on the way in lamenting that they couldn't convert an Angular 1 project to Angular 2 with just two months until release - but later Bryan Patrick Coleman, one of the organizers, told me that there are actually migration tools that will translate from Angular 1 to 2. Might be worth a try! 

Large files in C++

More specifically, wxWidgets and MSVC++ 2010. I found an msdn query that says 2010 is the first version that supports >2Gb file sizes with std::iostream. So that's fine with me. We found a few necessary changes: stat() changes to _stat64() istream::tellg() returns an istream::streampos, not an int. But what on earth happened here? // save the beginning position of this line for when we have to back up istream::streampos begin_line_pos = infile_stream.tellg(); string std_keyword; infile_stream >> std_keyword; // bunch of other keyword handling..... if (keyword == "shape") {    infile_stream.seekg(begin_line_pos);    // Danger! over 2Gb, this turns into negative seek, fails:    //infile_stream.seekg(begin_line_pos, ios::beg);    return true; } How does the commented line with the seekg() fail? It should treat begin_line_pos as an offset, which should be 64 bit. It's REALLY LAME if it sees the unsigned streampos and convert...

wxWidgets wxMemoryFS bug with filenames

This one drove me crazy this afternoon, using wxWidgets 2.8.8. Not the most recent, but I haven't found any notes that says it's been fixed. I added a file to a MemoryFS wxString name = "C:\data\my_file.txt"; wxMemoryFSHandler::AddFile(name, out_s.GetString()); //(where second arg is the file contents as a string) but then I couldn't retrieve it: wxFileSystem fs; wxFSFile *fs_file = fs.OpenFile("memory:"+name); if (!fs_file) return; // fs_file always NULL, so I'd get an early return Turns out, when trying to look up the file, filesys.cpp:: MakeCorrectPath is called on the string that's passed in, so it converted back-slashes to forward-slashes, and the names weren't equivalent. I did this: wxString name = "C:\data\my_file.txt"; name.Replace("\\", "/"); wxMemoryFSHandler::AddFile(name, out_s.GetString()); and now I'm able to retrieve it. 8Oct 10 Update: I submitted a defect .

CVS, cvsnt, and Norton Antivirus

Here's a friendly way to start your day: $ cvs update .... cvs [update aborted]: cannot rename file CVS/Entries.Backup to CVS/Entries: Permission denied This error occurs at random part way through the update, on a different directory each time. There are no files named Entries.Backup in the directory I'm trying to update. Or how about this one? cvs update: cannot remove xml directory: Directory not empty Guess what fixed the problem? Disabling Norton AntiVirus 2009 on my CVS server . No, not the client (my development PC), where I'm running the 'cvs update' command and don't even have anti-virus installed. The Windows XP box that's running CVS NT server. I was clued in when I was able to replicate the problem using cygwin cvs or cvsnt cvs, and inside WinCVS too. So it's not the fact that I just re-installed Windows on the client. It seems that this clean, speedy box is now too fast for the server to keep up with, but only if Norton is doing SOMETHING ST...

Launch external editor for file:// urls in Firefox

We maintain many docs in html format on a local shared drive. I wanted to launch my html editor of choice from within Firefox. I found the extension Launchy that does what I want. Unfortunately, it didn't find Komposer, the bug-fix release of Nvu, automatically. I had to generate a launchy.xml file as explained on the main page. I also learned that the 'command' entry should not contain double quotes! Otherwise Launchy ignores the entry.

Our App on Vista

What's different about Vista, for an application written for Windows XP? We write a config file in our application directory. When the user changes preferences, they are written to the config file. On XP, this file is located at C:/Program Files/DeltaSphere/bin/SceneVision-3D.cfg. Vista pretends that the file is still located there, but silently redirects it to C:/Users/username/AppData/Local/VirtualStore/Program Files/DeltaSphere/bin/SceneVision-3D.cfg. Got it? We need to update some drivers to Vista specific ones. We use the installer from VS2005 standard, and that seems to work fine We even use visual-basic scripts in the installer, and those still work. I bet Norton will still complain, though, just like on XP. We have a splash-screen app that auto-runs from our install CD, and Vista complains that it is unsigned. That's about it. Not too bad. I was prepared for much worse. Of course, we aren't really following the standards for where to locate our data and such, but we...

Perl regexp, one liners

The command perl -pe lets you do a line-by-line perl command on piped input and output. I discovered today that that means you can't use it on regexp that are supposed to match multiple lines.

Keyboard Macros in Emacs

A very useful tool in Emacs is the keyboard macro. Every so often I need to perform a repetitive task that is slightly different each time. This time, I was changing casts again, in C++. I had a series of casts, that looked like this: (MeasureLine *)(annot->newCopy()); and I needed to replace them with this: dynamic_cast<MeasureLine *>(annot->newCopy()); So I defined a keyboard macro, where I first selected 'MeasureLine *', and the macro would cut that text, type in 'dynamic_cast<', paste, then type '>' The keyboard macro is started by the keystroke 'Ctrl-x (', and ended with 'Ctrl-x )'. It is run by 'Ctrl-x e' When I found another spot in my code that looked like this: (ConstraintPlane*)(annot->newCopy()); I could drag over 'ConstraintPlane*' with my mouse, and hit 'Ctrl-x e', and it turned into: dynamic_cast<'ConstraintPlane*>(annot->newCopy()); Done. Another trick is that 'Ctrl-u...

Useful Regexp in Emacs for C++

First press Ctrl-Alt-Shift-5 to get Query-Regexp-Replace Then I want to find C-style casts in my .cpp file, and replace them with C++ style casts. For example: GeoData *gd = (GeoData *)mThreeDData; becomes GeoData *gd = dynamic_cast<GeoData *>(mThreeDData); First I figure out that this: (\w+ ?\*)[A-Za-z_]+ will find the expression I want. It's finding the parens, then \w is a 'word-constituent' which fits our type names nicely, followed by an optional space and the * for pointer. But in variable names, we often use underscores, so I search for those explicitly. Now I need to save parts of the search expression and use them in the replace expression. So I enclose in \( \), and reference with \N The search becomes: (\(\w+ ?\*\))\([A-Za-z_]+\) and the replace becomes: dynamic_cast<\1>(\2) A case this doesn't handle is if the C-style cast was on a method or function call, or array reference. so (Outline *)annot_to_save[i] became dynamic_cast...