Sunday, February 28. 2010Splitting arbitrary length stringsA friend of mine was apparently inspired by my solution to the problem of finding the first 10 digit prime number in e, and told me about a seemingly similar problem he faced while trying to manipulate a text file he had created in a custom format. While some solutions from the e problem may be applicable, his data format allowed for arbitrary length strings, rather than the 10 digit limitation, which made the problem suddenly much harder. I will detail the exact problem below, as well as listing some of the methods we used to tackle it. Thursday, December 17. 2009
A one-liner for finding spelling ... Posted by Hagfish
in Programming at
16:26
Comments (0) Trackbacks (0) A one-liner for finding spelling mistakes in codeI do a lot of programming, and I like writing one-liners to help me with things, so it’s perhaps not surprising that I’ve ended up writing a one-liner to help me with my programming. I should point out that the initial motivation to write this one-liner was not that I made any mistakes in the code I wrote, rather it was someone else’s code I was looking at which needed correction, but it would be hubris to assume I’m never going to make any mistakes myself, so I’m sure this script will be useful for my own code. Of course, nowadays editors will at least spell check the comments in your code for you, but it is also good to make sure your variable names don’t contain misspelled words, as that makes it harder for people (who know the correct spelling) to collaborate with you. This one-liner is rather crude and does produce a lot of noise in the output, but it is also interesting from a technical point of view, so I will discuss below how I came up with it and how it works. Continue reading "A one-liner for finding spelling mistakes in code"Monday, November 30. 2009
Which Linux applications are named ... Posted by Hagfish
in Programming at
22:26
Comments (0) Trackbacks (0) Which Linux applications are named after dictionary words?Every now and then I find my mind gets caught on some seemingly trivial observation, and I end up following a chain of thought tangential to the one I was originally on, until I arrive at somewhere quite unexpected. Whereas people in former times may have been unable to travel too far down these intellectual rabbit holes, we now live in a world where Google and Wikipedia have made us seemingly omniscient, and hypertext in particular allows us to jump from one idea to the next, wherever our curiosity takes us. The secondary limit, I suppose, would be the ability to process all of this information that we amass while browsing the Web. As a programmer, though, there are certain options for information processing which are open to me but would not be readily available to non-programmers, and even if what I do with the processed information isn’t particularly ground-breaking, it can at least be the subject of a new blog post. As the title of this post suggests, my most recent such endeavour involved looking at Linux application names, and dictionary words, and below I explain what I found and how I found it. Continue reading "Which Linux applications are named after dictionary words?"Wednesday, September 30. 2009
Uploading signatures from a ... Posted by Hagfish
in Programming at
21:52
Comments (0) Trackbacks (0) Uploading signatures from a keysigning partySigning people’s keys is one problem, but when people sign your key that requires its own procedure with its own set of potential issues. You will likely receive several emails, one from each person with whom you exchanged keyslips, and these emails will each include an attachment or message body that contains encrypted data for you to decrypt. The plaintext you get from decrypting should be a copy of your public key that has been signed by someone’s private key. It is this signature that you’re looking for, and GPG can extract it and add it to your key. Once you have collected the signatures, you can upload your key to a keyserver where the information about who has signed your key can be publicly stored. That’s the principle, but the steps to do all this can be quite cumbersome, so I used some console one-liners to speed some of the steps up, and I include them below with an explanation of what they do. Continue reading "Uploading signatures from a keysigning party"Monday, August 31. 2009Simply signing GPG keysCryptography is hard to do right, and even if it is implemented correctly, the user is often required to perform some complicated operations to make use of it. One area of cryptography which involves a great deal of activity from the user is the signing of public keys used in public key cryptography. Not only does it usually require users actually meet each other and do some sort of identity verification, it then requires quite an involved process at the computer involving retrieving keys, checking signatures, and sending emails. To automate this as much as possible, I have come up with a little script which helps me perform some GPG and email operations quickly and simply, without, I hope, reducing my security. Continue reading "Simply signing GPG keys"Friday, July 31. 2009
The right way to split strings Posted by Hagfish
in Programming at
20:35
Comments (0) Trackbacks (0) The right way to split stringsThis month I found myself considering the problem of how to split a string representing some English text into substrings that contain only whole words, but where the substrings are as near as possible to a certain number of characters in length. Formalising this a bit, I wanted an algorithm which would take a string s of characters (including spaces but not as consecutive characters) and a number n, and return a substring of s starting at the first character (using one-based numbering) and going up to the mth character, where m ≤ n, character m+1 is a space, and any characters in s which are after the m+1th (exclusive) and before the n+1th (inclusive) are not spaces. That has probably made things sound more confusing, so imagine that n was 7, and s was “1234 6789 ABCD”, then m would be 4, and m+1 would be 5, meaning there are no spaces that are strictly after m+1 but before or including n+1. The main focus of this post, though, is showing the different ways it can be done in Groovy, and how beautiful those ways are, especially if you make it a one-liner. Continue reading "The right way to split strings"Wednesday, April 29. 2009
A bit of help with closures in Groovy Posted by Hagfish
in Programming at
16:37
Comments (0) Trackbacks (0) A bit of help with closures in GroovyWhile looking through my ideas for potential future blog posts, I came across some notes I made while trying to consolidate my understanding of closures in Groovy. I also had a few points I wanted to make about other aspects of the language, including things I found while working on the game that I presented in my last blog post, so I thought that this would be a good time to write up these ideas. This post may end up sounding like a criticism of Groovy’s documentation and tool support, but it is a fairly new language and I think that should be taken into account. The small problems I have come across have certainly not put me off it, but have perhaps given me a greater appreciation of more mature languages like PHP. Continue reading "A bit of help with closures in Groovy"Tuesday, March 31. 2009Groovy Tic-Tac-ToeI have enjoyed using Groovy in the past, and even think it might be the nicest (programming) language in the world, so I thought I would try using it for a fun little project. Perhaps I should have remembered how difficult it was writing a graphical program in Java (on which Groovy is based), or perhaps I should have given up when I realised that Debian doesn’t have a nice Groovy 2D graphics library packaged yet, but my hubris got the better of me and I waded in, trying to create the game Tic-Tac-Toe. I would call it “Noughts and Crosses”, except the limitations of the graphical commands available meant I couldn’t do crosses. So, I will show you the source code needed to run this game, and warn you of the difficulties you will encounter if you try my bizarre way of doing graphics in Groovy. Continue reading "Groovy Tic-Tac-Toe"Tuesday, March 31. 2009
first 10 digit prime in consecutive ... Posted by Hagfish
in Programming at
16:41
Comments (0) Trackbacks (0) first 10 digit prime in consecutive digits of eThere was once a recruitment campaign by Google which involved putting this mysterious message on billboards: { first 10 digit prime in consecutive digits of e } . com which many people solved and it lead them to a website and down a rabbit hole further testing their abilities. I had a go at this question myself and did manage to find the answer, but I didn’t record the method I used. It definitely involved a long command I typed into a terminal window, but I have a feeling I “cheated” by using a semi-colon. What I mean is, my solution wasn’t technically a “one-liner”, and was therefore no more interesting than a solution written in any other language. While emailing a friend of mine recently, this puzzle came to mind, and I decided that I would see if I could write a one-line BASH script to generate the answer. I did manage to, but it’s a little bit scary, so I’ll share it with you and try to explain it in this blog post. Continue reading "first 10 digit prime in consecutive digits of e"Friday, December 5. 2008Learning Java with EclipseOr should that be, “Learning Eclipse with Java”, as I suppose there are people out there who know Java and want to know what using Eclipse is like. There may also be people who are interested in the particular issue of class inheritance and calling objects from one class defined in the superclass, so I don’t want to limit the audience of this post too much. My main motivation for this post, however, is a desire to see Java taught right, which is an ambitious goal, I know, especially as it implies that I and everyone I know was taught incorrectly. Perhaps I should settle for “Java taught differently”, and this can be an experiment to test my hypothesis that people shouldn’t have to scale the learning curve mountain before they can write a line of Java, they should use all the shortcuts at their disposal to get to the summit, and then enjoy the ride down the other side as soon as possible. The main shortcut I can see, apart from just ignoring the formal theory behind the language until you’ve actually seen it in action, is to get Eclipse to tell you what you can do, and settle for knowing which option is right. Continue reading "Learning Java with Eclipse"Thursday, December 4. 2008
(Un)packing and (un)zipping in PHP ... Posted by Hagfish
in Programming at
19:16
Comments (0) Trackbacks (0) (Un)packing and (un)zipping in PHP and RubyI like to think of myself as experienced in many computer languages, even if some of those experiences are unpleasant, and what better example of the variety of languages (and experiences) than PHP and Ruby. It seems that everyone skilled in one those languages has a strong preference for one or the other, so perhaps it would be helpful for me to contribute a comparison of how the two languages can be used to solve the same problem. My personal opinion is that while Ruby (and Rails sites) may fail spectacularly, PHP sites fail based on the quality of the programmer, and there are more PHP programmers out there (with a wider range of abilities) to pick bad examples of code from. Really, though, this blog post (and my whole blog) should not be about wading into the current argument of the day, and Ruby has its places and I’m happy to use it in those places, so I should make it clear that the comparison below is to aid interoperability. This was in fact what motivated me to write this code, actually, as there was a web service that needed implementing in both languages and the implementations were disagreeing on how the zipping stage should work. There are also a couple of gotchas just getting either language to zip or pack something, so hopefully the example code will be useful for someone trying to spot a bug in their own code. Continue reading "(Un)packing and (un)zipping in PHP and Ruby"Sunday, November 30. 2008JavaScript global variablesI admit, scope can be a tough concept to get your head around, especially when different programs do it differently, and JavaScript is no exception. In fact, JavaScript makes quite a few design decisions which, while logical, can go unnoticed even by programmers with a fair amount of experience in the language. This blog post is not the place to list and explain all of them, but I will try to give some insight into the global variable issue, and how persistence of variables works. Hopefully this knowledge can be useful to people making web pages which involve storing a lot of state, like JavaScript games require. Continue reading "JavaScript global variables"Sunday, November 30. 2008Hate PerlThat’s not a very helpful (or fair) title, but it’s what I’ve called a little file on my computer containing some helpful reminders about how unintuitive programming in Perl is. My incompatibility with Perl may well be to do with my personal preference, or inexperience with it, but compared to the half dozen programming languages I feel I know well, Perl seems to be deliberately difficult with no obvious benefit. Most of my observations below focus on Perl’s idea of scope, as the confusing rules it uses can, I’ve found, be grouped together to tell a story of misdirection and contradiction. If I was writing a post about all the things I dislike about the language, it would take me more than a month to complete, but just so you know, it would start with the fact that Perl doesn’t have Boolean data types or a Friday, October 31. 2008
Make your own censored webmail! Posted by Hagfish
in Programming at
22:50
Comments (0) Trackbacks (0) Make your own censored webmail!Censoring webmail is considered bad, especially when someone is censoring someone else’s email, and even more so when they are doing so without permission. I don’t know much about those sorts of situations, because I don’t rely on sites outside of my control to host my webmail (any more), but nor do I rely on myself to host my webmail, because the only software I’ve found is not designed for mobile phones or not in Debian yet. Failing to follow basic security practise, I exempt software which I have written myself from my stringent, Debian-based, quality control rules, and so, when I really needed a webmail service (or at least a subset of it), I was forced to write my own implementation. Fortunately the subset I required was very, very small, to such an extent that it is arguable whether what I’ve written is a webmail system at all. Basically it allows you to view on a webpage whether a person has sent you an email, and when they sent it, but no attacker could ever discover more information than this. By changing the source code you can restrict it to only consider emails based on certain criteria. In my particular case, this allows me to check if a certain special somehow has emailed me, which lets me look forward to the pleasure of reading their message when I get home. Continue reading "Make your own censored webmail!"Tuesday, September 30. 2008
VirtualHost problem plus Multiple ... Posted by Hagfish
in Programming at
01:09
Comments (0) Trackbacks (0) VirtualHost problem plus Multiple MySQL MAXesAs mentioned last time, my trouble with Apache didn’t end with mod_rewrite rules on my blog. I have Apache installed on my home PC (firewalled off) and have been receiving warning messages from it in emails caused by a logrotate cronjob which runs every week. The same warning appears when the server is restarted, and while it is not critical, it is something I wanted to understand and avoid. Also, in case this post is too short or not varied enough (and because I have an unhelpful backlog of little comments I’d like to blog), I will include below a little trick for getting MySQL to produce a set of results where each row contains the name of a table and MAX(foo) for some field foo in that table. (Unfortunately the MySQL trick doesn’t enumerate the tables for you and the length of the query’s SQL scales linearly with the number of rows, but it is slightly nicer than running several queries which each produce one row, then parsing and combining the results). Continue reading "VirtualHost problem plus Multiple MySQL MAXes" |
QuicksearchArchivesCategoriesSyndicate This BlogBlog Administration |