Archive for the ‘ Computers ’ Category

Java Word Wrap Algorithm

On a recent coding project I’ve been working on, I had need for a simple line-wrapping method.  I googled around, but couldn’t find anything useful — so, like any coder, I made my own.  I think it’s pretty nice, if I do say so myself:

public static String wrap(String in,int len) {
in=in.trim();
if(in.length()<len) return in;
if(in.substring(0, len).contains("\n"))
return in.substring(0, in.indexOf("\n")).trim() + "\n\n" + wrap(in.substring(in.indexOf("\n") + 1), len);
int place=Math.max(Math.max(in.lastIndexOf(" ",len),in.lastIndexOf("\t",len)),in.lastIndexOf("-",len));
return in.substring(0,place).trim()+"\n"+wrap(in.substring(place),len);
}

That first “in.indexOf()” has the space string (” “) as an argument, not an empty string.

I apologize for the difficult-to-read-ness of this code; I had it nicely spaced and indented but WordPress ate my formatting.
If you want to be really fancy, switch out the “\n” with a System.getProperties(line.separator).

Advertisements

Gedit Themes

Okay, first of all, I realize I have posted anything in nearly three months.  This has no excuse; I am shamed.  SHAMED.

Anyways.

So, I was thinking, I want to do another computer-y post. But then I thought about how so far I’ve really just done software reviews and stuff — and it’s not like that doesn’t already exist elsewhere.  I don’t need to reinvent the wheel.  So I decided to post something more original — two gedit themes I created.

gedit (all lowercase, always) is the default GNOME text editor.  It handles syntax highlighting, line numbers, margins, adjustable tab width… it’s pretty full-featured.  Visually, it starts out pretty basic but it’s got great plugin support and some pretty good built-in color themes.  However, all of them had something that bugged me; I decided to fix it.

Screenshot of my Oblivion++ theme

Click through for large size!

My first theme, Oblivion++, is based off the ships-with-gedit theme Oblivion.  It’s much bluer.

You can download the .xml file here or view it here; scroll  to the bottom of the post for installation instructions.

Screenshot of my gedit theme Vim Stylin'

This one has a large size too -- click it!

My other theme is Vim Stylin’, based off Vim color interpretations.  You can download the .xml here or view it here, just like the other.  Also just like the other, scroll to the bottom of the post for installation instructions.

If you do want one of these (if I do say so myself) pretty cool themes, download them to ~/.gnome2/gedit/styles, which may need to be created first.

gedit, as far as I know, works on Linux, Mac OS, and Windows, but comes with and works best on Linux.  If you have gedit on a non-linux OS, the file location will be different; it /should/ work okay from somewhere else but I haven’t tested it.

Once it’s downloaded and saved, open gedit.  In the menu bar choose Edit and navigate to Preferences.  Once there, click Fonts & Colors and click the Add button.  Navigate to and choose the downloaded theme; it should change immediately.

Enjoy!

Edit:  The text in the images is a bit of the code of Keylime Py, a fail-pun-named text-based adventure game I’m writing in python.  I’ll be blogging about it once it’s ready to be let out to teh interwebs.

This Link Kills Spam

Email harvesting bots — also known as data miners — trawl the internet for anything that looks like an email address.  When they find one, they send spam to said address.  They then search the site on which the email was found and search everything linked to there.  The good people at the Office of Strategic Influence have created a site with a script that generates gigabytes of fail email messages (like “qzloxqsiy@rluzuhv.net”) and have handily provided links to it.  Whenever this site, or any other site that links to the script, is found by an email harvester, the harvester also checks the script-hosting site.  And dies.  They can’t handle the millions of fake emails.  Death to spam!

If you want a text-only link on your site, paste

<a href=”http://officeofstrategicinfluence.com/spam/”&gt;
This link kills spam</a><br />

into your posts.  If you want an image link (like the one below; both kinds work equally well) paste

<a href=”http://officeofstrategicinfluence.com/spam/”&gt;
<img alt=”This link kills spam” src=”http://officeofstrategicinfluence.com/spam/icon.png&#8221; border=0></a><br />

in.


This link kills spam

Why DRM is Bad: The Law of Unintended Consequences

DRM is software used to restrict your access to your files.  And it is one of the worst ideas of the modern world. To quote Cory Doctorow in his book Someone Comes To Town, Someone Leaves Town,

No one woke up this morning and said, “Damn, I wish there was a way to do less with my books, movies and music.”

It was intended, originally, to keep copyright laws working.  Before about the 20th century, copying another work was an arduous process (no computers, no recording mechanisms, etc), so restricting the copying of an item (like a song, or a picture) was most easily done at the stage of copying.

All that has changed.  Now we have computers, cheap cameras, video recorders, scanners, recorders, and so on.  It’s suddenly very hard to keep people from copying.

The Law of Unintended Consequenses states:

Any intervention in a complex system may or may not have the intended result, but will inevitably create unanticipated and often undesirable outcomes.

Basically, that means “Anything you do might work, but it will always do something you didn’t expect or want.”

The attempt to keep copyright working in today’s day and age is DRM, which keeps you from copying and using files how you want.  And it’s not just constricted to copying, either:

  • In July of 2009 Amazon deleted copies of two books from Kindles, as the books were illegally placed in the Amazon ebook store.  Ironically, they were Nineteen Eighty-Four and Animal Farm, both by George Orwell.Now, assume a leaked copy of a secret eight Harry Potter book (of which there are in fact rumors) is bound by an individual and placed in Borders.  You walk in and want to buy it — you don’t know that it shouldn’t be there.  The teller, who doesn’t really like fantasy, doesn’t know that they shouldn’t be selling that book.  Later that night, it is revealed to the manager that this book was sold.  Some of his workers break into your house, take the book (you had already been reading it; you were about halfway through) and leave.  I believe you would be sufficiently enraged.  What’s to stop Amazon from deleting or editing any book you have on a Kindle?
  • DRM is on many DVDs in order to keep the market from getting too segmented — spread out over too many demographics, which is a huge hassle (if I read correctly) for marketing and the company in general.  Now, assume you just bought a new DVD.  You’re going on vacation to Japan soon, and haven’t yet had a chance to watch it.  You bring with you, to watch in the hotel one night.  Woops, too bad!  Many DVDs only work in players manufactured for the same country the DVD was manufactured in, and possibly a few others.
  • Or maybe, while in Japan, you buy some anime DVD to watch at home. Too bad, so sad.
  • Don’t like Safari on the iPhone?  Want, perhaps, Opera Mini?  Oh wait — everything on the iPhone is slathered in DRM.  You can’t use third-party software not from the App Store, and Opera Mini hasn’t been accepted yet.  So, it does get accepted, then an update changes its code some.  Apple doesn’t like the new version.  Oh, sorry, it appears Opera Mini isn’t on your iPhone anymore.  Download a vehemently anti-Apple article on your iPad?  Nope.  It’s deleted.  They can do that, if they want.  At any time.  To any one.  On any thing.
  • So, you just downloaded this ebook and man, is it great.  You want your friend to read it, but he doesn’t want to buy it.  “Okay,” you think, “I’ll just send it to him.”  Woops, sorry!  You can’t share your files if their DRM says so.
  • Any song you download from iTunes has DRM on it. You can only have iTunes accounts on three computers, and those songs are very restricted. This is doubly stupid. Not only is DRM a bad idea, but each of those songs is available on CD without DRM. iTunes DRM’s its songs because the big music companies say so, but then they release unlocked CDs (which is a great thing) that you can rip.

And get this — DRM doesn’t, for the most part, do a thing except annoy people.  Pirates have cracked every DRM scheme out there.  Any file with DRM is available on BitTorrent without it.

Help spread awareness:  DRM is bad.

Facebook Chat Emoticons

You probably know most of these, but there’s probably also a couple you don’t know.  Try ’em out!

Standard Smileys
Happy :)
Really happy
:D
Sad :(
Crying :'(
Wink ;)
Anime face ^_^
Laughing eyes >:o
Cat smile :3
Mad >:(
Surprised :o
Tongue out :p
Glasses 8)
Shades 8|
Skeptical o.O
Dopey smile -_-
Bored :/ or :\
Devil 3:)
Angel O:)
Kiss :*

Not smiley faces
Robot
:|]
Penguin <(")
Putnam :putnam:
Shark (^^^)
Heart <3
Pacman :v
42 in a box :42:

Some Great Webcomics

I read a whole bunch of webcomics, all of which are great or at least worth a look. Without further ado, here’s the list:

  • Ctrl+Alt+Del is along the lines of Penny Arcade, but deals more with the characters than with games. In my opinion, it’s better.
  • Irregular Webcomic, also written about here, is made entirely out of legos.  And is loads of fun.
  • The Adventures of Dr. McNinja is about a ninja who is also a doctor. He descends from a long line of ninjas who, of course, have a long-standing rivalry with pirates.  His vehicle of choice is a velociraptor.
  • XKCD is the well-known techie stickfigure webcomic. I like it.
  • Questionable Content is definitely worth going through the entire archive. I got very little done this weekend because of it. Among other things, it’s really interesting to watch the progression of the author’s art style. If you have not read it yet, you should. Now. Click that link!
  • Order of the Stick, a D&D webcomic, is set out to use every trope (clicking on that link may cause you to click on other links uncontrollably. You are warned.) and is full of excellent humor.
  • Goblins – Life Through Their Eyes is another D&D comic, from the point of view of a party of goblins who become adventurers. It’s got some heavy stuff in it, but is definitely worth checking out.

Ta-da!  If you haven’t read any of ’em, at least check out the first couple.

Linkdump

So, here’s a whole bunch of cool links for your enjoyment.  Check ’em out!

By the way, middle-clicking (or, often, Ctrl+clicking) opens the link in a new background tab, so you can keep reading the post until  you’re done, at which point you can just close this tab and move on.

  • Star Wars Weather Forecast
    Compares the weather of a user-defined location to various Star Wars planets.  Right now the description for mine is “Wow.  18 C, Light Rain?  It’s like Kamino out there.  Wet.  There’s also a significant chance of unconvincing CGI aliens.”
  • Earthship Homes
    Earthship homes are houses built entirely eco-friendly:  insulation from old tires, glass from recycled bottles, and so on.  It’s pretty sweet.  Check out the link for the full post.
  • Space
    Simply an amazing picture of a section of space.  Once there, click it to zoom in.
  • The Star Wars Opening Crawl Finally Reaches Earth
    Some genius decided to show what would happen if the text from the opening of Star Wars made its way to Earth.  Definately worth checking out.  Very funny.
  • Pokescience
    Proof that Pokemon are “freaking hax,” taking into account things like the fact that Blaziken can apparently jump 60 times its own height, and that Magcargo’s body is somewhere around 1.8 times as hot as the surface of the sun.
  • Electric Umbrella
    An instructable detailing how to build an umbrella with embedded LED lights for maximum awesomeness.
  • The Something Store
    Buy a $10… something.  It’s a mystery.  You can get anything with a value of or greater than $10.  Just go for it!  If you don’t like it, well, it was only $10 and there’s a good chance it’d be something cool.
  • Where To Start With Young Adult Science Fiction
    A list by io9 of young adult Science Fiction books, most of which I think are great to read if you haven’t yet.  At least give it a look.
  • Gizmodo Reading Room:  Fiction
    Another list of great fiction books, but this one isn’t limited to Sci-Fi.
  • Orisinal Winterbells
    A fun little game in which you are a rabbit, jumping as high as you can off of floating bells.  Control with your mouse.  Not much of a point, but fun and (perhaps?) calming nonetheless.
  • Return My Pants!!
    A site to keep track of who’s borrowing stuff from you, and whose stuff you’re borrowing.  
  • ColorJack
    A color picker, with a nice look/feel and great for grabbing the hex or RGB value of a given color.  Worth a look for any web designer or dabbler in HTML.
  • Facepalm
    A great facepalm image.  Insert it into threads where a facepalm is required.
  • Pirate vs. Pay
    Describes why people pirate, through a few images and some arrows.  Humorous, but very very true.
  • Math Heart
    An equation that, when graphed, makes a very nice heart.  You may have to scroll down a bit to see the graph
  • Math Leaf
    Along the line of the above, this equation makes a leaf.  Maple, I think.
  • Binary — It’s Digitalicious!
    A great non-laggy Binary/Hex/Octal/English translator.

Et voila!