I can never quite keep all the options in my head. This MineCraft version comes closest to making it easy for me to remember:
Tag Archives: coding
grep
If you want to find all the HTML, or XML, tags in a document, `grep` the following:
?[^>]*>
In a GUI app you can choose find all or replace all (with whatever you like).
Codecademy’s “Something of Value”
Here’s the bit of code I wrote for this particular segment of the Python course. I’m rather happy with its simplicity:
# Two dictionaries given: {prices} and {stock}
total = 0
for item in prices:
worth = prices[item] * stock[item]
total += worth
print total
Time to Get Back to Learning to Code
There’s a lot of places to start. I’m starting with [Real Python][] this morning, as well as a bit of [Codecademy][]. I was a Kickstarter backer for _Real Python_, so this is my chance to see what kind of return I got on my investment.
[Real Python]: http://www.realpython.com
[Codecademy]: http://www.codecademy.com
If you need a reason for why you should start to learn to code: [Simon Peyton][] (link to Youtube video of TED talk) and [Yevgeniy Brikman][] tie it to learning to think.
There are plenty of places to start learning to code: [TED has a list][ted] and [Lifehacker has a tutorial for beginners][lh] — the tutorial addresses both abstract concepts as well as grounding you in actual coding. In this case, LH uses Javascript, which may or may not interest you.
Believe it or not, [Google has a nice curriculum](http://www.google.com/edu/tools-and-solutions/guide-for-technical-development/index.html).
[Simon Peyton]: https://www.youtube.com/watch?v=Ia55clAtdMs
[Yevgeniy Brikman]: http://brikis98.blogspot.com/2014/05/dont-learn-to-code-learn-to-think.html
[ted]: http://blog.ted.com/2013/01/29/10-places-where-anyone-can-learn-to-code/
[lh]: http://lifehacker.com/5744113/learn-to-code-the-full-beginners-guide
Review of “10 PRINT CHR$(205.5+RND(1)); : GOTO 10”
There’s an interesting [review of _10 PRINT CHR$(205.5+RND(1)); : GOTO 10_ at Slate][slate]. For those that don’t, like me, recognize that particular line of code, it’s from a Commodore 64 program that would create an ever-incrementing maze on the screen. The [book about the line of code][book] seems to be wide ranging and playful and thus, to my mind, worth a look. By the way, the book is available through a Creative Commons license and can be purchased in codex form in support of two nonprofits or downloaded for free as a PDF. My advice? Check out the PDF and if you like the book, buy the codex.
[slate]: http://www.slate.com/articles/technology/books/2012/11/computer_programming_10_print_chr_205_5_rnd_1_goto_10_from_mit_press_reviewed.single.html
[book]: http://10print.org
Python in XCode
If you want to use XCode for Python development, there’s a [way to do it][], but it’s not straightforward. Tyler Crompton’s instructions have 22 steps, but he insists that it’s easier than those steps make it look.
[way to do it]: http://stackoverflow.com/questions/5276967/python-in-xcode-4
Learn to Code
The resources available should you want to learn to code just keep getting better and better: now Khan Academy has an entire computer science curriculum. [Here’s the link](http://www.khanacademy.org/cs).
Tinker … Learn
This is really cool. Given that I have been thinking about developing an iOS app for field researchers, the timing on this could not have been better: [TinkerLearn](https://www.tinkerlearn.com/xray) aims to teach you iOS development by showing you a real app and walking you through its source code. What you get is an Xcode project with lots and lots of comments. You can run it yourself and then see what works and what doesn’t work.
If we taught writing the way programming is often taught, we would never have students read any kind of writing before asking them to write themselves, which is somewhat nonsensical. The way we learn so much of what we learn is through mimicry, mimicry leads competency, and, with desire and discipline, competency can lead to mastery.
And I love the logo:

Splitting a File
Make no mistake: my coding fu remains quite weak. Still, something as simple as splitting a text file into smaller files based on a small string that sits on a line by itself shouldn’t be too hard of a problem. Well, the splitting isn’t that hard when someone hands you a Perl script. What’s hard is finding a way to split the files for yourself and also to have the files named after the string by which they were split.
What do I mean by this? I have a large text file, two of them actually, which are made up of over one hundred texts each. Each text begins with `–###–` and proceeds for some number of lines before the next `–###–` occurs.
I would like to split these larger files into their constituent parts and have each of those parts be contained in a file named, `###`. This shouldn’t be as hard as it is. I have tried:
split -p ‘^–[0-9][0-9][0-9]–‘ mytext.txt
And:
csplit -k individuals.txt /–[0-9][0-9][0-9]–/
And that’s just to split the file. (Neither worked.) This Perl script did:
#!/usr/bin/perl
open(FI,”individuals_refs.txt”);
read(FI,$_,10000000);
close(FI);
@arr = split(‘–[0-9][0-9][0-9]–‘);
$cnt=0;
for $c (@arr)
{
open(FO,”>$cnt.txt”);
print FO $c;
close(FO);
$cnt++;
}
But it simply labels the files by number, which loses their original identifying number.
It turns out that [StackOverflow is not all that friendly](http://stackoverflow.com/questions/11090292/break-text-file-into-multiple-text-files), or at least the subset that decided to close the question I had asked. (You’d think you could only close a question if you had either opened it or tried to answer it. Ah, Internet moderation, you are a beast that feeds the self-righteous.)