Planet Rosetta Code

September 13, 2011

Kevin Reid

New Project: Cubes

On September 6, I had an idea which I couldn't not work on. (Unfortunately, it wasn't an idea for either of my course projects this semester.)

As you may know, in Minecraft, the individual cubical blocks are textured with unsmoothed 16×16 pixel textures. All blocks’ shapes (that aren't just cubes) have lengths in multiples of 1⁄16 block (example, so that the objects have (to some degree) the appearance of being made out of voxels, or smaller cubes. And, people have built giant versions of specific blocks out of colored blocks.

So, what if building blocks out of blocks was actually how the block types were defined?

And that's what I've implemented, in JavaScript/WebGL. The working project name is “Cubes”, because I don't know where it's going enough to give it a better name right now.

The block types you see above were all procedurally generated as placeholders, since I don't have any save/load facility to save manually edited blocks (and I'm not sure about the color scheme of the current set of blocks-you-make-blocks-out-of).

Play (requires WebGL-capable browser; I recommend Chrome).

Source code.

Controls: Standard WASD keys, or arrow keys, and mouselook. The left button adds or removes blocks at the location of the white rectangle cursor; the right button brings up a menu for choosing blocks (the empty square at the top left is the removal tool). The R key enters the world of the selected block; the F key exits.

Update 2011-09-13: I've improved startup; it now tells you more explicitly what went wrong if it fails to load, rather than a blank white screen. I've also added an in-game Help button with controls and browser compatibility info.

September 13, 2011 06:57 PM

August 14, 2011

Kevin Reid

kpreid @ 2011-08-14T14:30:00

I just wrote up a couple tips for debugging simple physics simulations (of the sort you use in 2D games), in a bit more detail than the context required.

August 14, 2011 09:30 PM

August 01, 2011

Benny Baumann

FizzBuzz BrainFuck

Well yeah, after some nasty person dropped a link about why programmers are so bad at programming I somehow got to have a look at the Rosetta Code project’s site detailling this task and found (not to my surprise) that noone had solved that task — yet! So I sat down and implemented it. Usually this task should take you only about a few minutes but since I hardly ever programm anything in BrainFuck it took me roughly 45 minutes to complete. But well: Here’s the result (Beware: Ugly code)!

FizzBuzz
 
Memory:
  Zero
  Zero
  Counter 1
  Counter 2
 
  Zero
  ASCIIDigit 3
  ASCIIDigit 2
  ASCIIDigit 1
 
  Zero
  Digit 3
  Digit 2    
  Digit 1    
 
  CopyPlace
  Mod 3
  Mod 5
  PrintNumber
 
  TmpFlag
 
Counters for the loop
++++++++++[>++++++++++[>+>+<<-]<-]
 
Number representation in ASCII
>>>>
++++++++ ++++++++ ++++++++ ++++++++ ++++++++ ++++++++ [>+>+>+<<<-]
<<<<
 
>>
[
    Do hundret times:
 
    Decrement counter
    ->->
 
    Increment Number
    > >>+> 
        > >>+>
        <<<<
    <<<<
 
    Check for Overflow
    ++++++++++
    >>> >>>>
    >++++++++++<
    [-<<< <<<<->>>> >>> >-<]
    ++++++++++ 
    <<< <<<<
 
    Restore the digit
    [->>>> >>>-<<< <<<<]
    >>>> [-]+ >>>>[<<<< - >>>>[-]]<<<< <<<< 
 
    If there is an overflow
    >>>>[
        <<<<
 
        >>>----------> >>>----------<+<< <<+<<
 
        Check for Overflow
        ++++++++++
        >> >>>>
        >>++++++++++<<
        [-<< <<<<->>>> >> >>-<<]
        ++++++++++ 
        << <<<<
 
        Restore the digit
        [->>>> >>-<< <<<<]
        >>>> [-]+ >>>>[<<<< - >>>>[-]]<<<< <<<< 
 
        If there (again) is an overflow
        >>>>[
            <<<<
            >>---------->> >>----------<+< <<<+<
 
            >>>>
            [-]
        ]<<<<
 
        >>>>
        [-]
    ]<<<<
 
    >>>> >>>> 
 
    Set if to print the number
    >>>[-]+<<<
 
    Handle the Mod 3 counter
    [-]+++
 
    >>>>[-]+<<<<
    >+[-<->]+++<
    [->->>>[-]<<<<]
    >>>>[
        <[-]>
 
        [-]
        Print "Fizz"
        ++++++++ ++++++++ ++++++++ ++++++++
        ++++++++ ++++++++ ++++++++ ++++++++
        ++++++.
 
        ++++++++ ++++++++ ++++++++ ++++++++
        +++.
        
        ++++++++ ++++++++ +..
 
        [-]
        <<<--->>>
    ]<<<<
 
    Handle the Mod 5 counter
    [-]+++++
 
    >>>>[-]+<<<<
    >>+[-<<->>]+++++<<
    [->>->>[-]<<<<]
    >>>>[
        <[-]>
 
        [-]
        Print "Buzz"
        ++++++++ ++++++++ ++++++++ ++++++++
        ++++++++ ++++++++ ++++++++ ++++++++
        ++.
 
        ++++++++ ++++++++ ++++++++ ++++++++
        ++++++++ ++++++++ +++.
        
        +++++..
 
        [-]
        <<----->>
    ]<<<<
 
    Check if to print the number (Leading zeros)
    >>>[
        <<< <<<< <<<<
        >.>.>.<<<
        >>> >>>> >>>>
        [-]
    ]<<<
 
    <<<< <<<<
 
    Print New Line
    <<<<[-]++++ ++++ ++++ +.---.[-]>>
]
<<

I didn’t have a brainfuck interpreter at hand but I believe this should work. If it does not feel free to comment below pointing out the bugfixes. And I hope the documentation is appreciated; since that took extra time to write ;-)

Share and enjoy!

flattr this!

by BenBE at August 01, 2011 11:17 PM

July 20, 2011

Kevin Reid

Apple goes least authority in “Lion”

Whoa. They even called it a powerbox as we do.

Apple has chosen to solve this problem by providing heightened permissions to a particular class of actions: those explicitly initiated by the user. Lion includes a trusted daemon process called Powerbox (pboxd) whose job is to present and control open/save dialog boxes on behalf of sandboxed applications. After the user selects a file or directory into which a file should be saved, Powerbox pokes a hole in the application sandbox that allows it to perform the specific action.

Mac OS X 10.7 Lion: the Ars Technica review

It probably ain't capabilities (no bundling of designation of the resource with authority to access it, unless they've replaced file pathnames, which I doubt), but it's a big step in a good direction. UPDATE: Ivan Krstić says “The implementation uses actual capabilities under the hood.”

July 20, 2011 09:01 PM

June 17, 2011

Kevin Reid

kpreid @ 2011-06-17T09:42:00

Something I still miss from the ORCA development shell for the Apple IIgs (at least, I think that's where it was) is the option to interpret a command name which is directory as a command to change to that directory; essentially letting you omit “cd ”.

June 17, 2011 04:42 PM

May 25, 2011

Kevin Reid

On the use of finalizers for managing external resources

I have several times heard that one should not rely on finalizers (that is, code invoked after some object becomes garbage) to reclaim external resources (file descriptors, temporary files, etc.), on the grounds that there is no guarantee they will be promptly reclaimed and therefore one might run out.

Certainly for resources whose use has semantic significance to an outside system (e.g. a network connection or a locked file) or if there is a potential shortage of resources affecting other processes (e.g. free disk space), one should free them promptly whenever possible. (Finalizers are still important for error recovery unless you’re programming completely without nonlocal exits and extremely carefully, in which case you’re probably writing C and don’t have finalizers.)

But if the concern is for limited internal resources (most prominently, the limit on number of open file descriptors), and the process is entirely managed by the GC, would it not suffice to force a garbage collection and retry in the event that opening a file fails due to lack of file descriptors, just as if running out of memory while allocating memory?

May 25, 2011 04:05 AM

May 14, 2011

Rosetta Code Blog

Downtime this weekend

As I noted, there was an expectation of downtime as the VPS host Rosetta Code sits on moved from one data center to another. It looks like that downtime will be parts of today and/or tomorrow. Here is the email I just received a few minutes ago:
We're moving most of our servers from SVTIX[1] to Market Post Tower[2] this
weekend. we've got layer 2 between the two locations already, so we'll
be bringing down servers in batches of five and moving them five at a shot.
each user should experience something like two hours of downtime, if all
goes well.

This, along with the bandwidth outage earlier this month puts me way
over the SLA, so all users we move will be receiving 25% of a month off.

I am sorry for the short notice; I've made several bad decisions
that led to this short notice, but I think I am correcting some of those.
The deal wasn't even final until two days ago, but the solution to that
is more transparency, not less. Well, more transparency and longer
term agreements. I am sorry.

I'm now signing a long-term contract, and I'll put data as to when these
contracts expire in a publicly accessible place, so this sort of thing
will be more predictable in the future.

Now, market post tower is generally considered a better data center
than SVTIX. It's usually more expensive, It's much nicer looking and
has /much/ better and cheaper bandwidth available. I will immediately
double the bandwidth "don't worry about it" allowances for everyone.
Now, svtix has a better history for power, but CoreSite, I am assured,
has recently upgraded the power systems and the bad old days should be
behind us.

In any case, I am maintaining space at both MPT and SVTIX, though SVTIX
will be largely co-location; most of my Xen hosts will be moved to MPT.
For now, my bandwidth at svtix will be coming from MPT, which should
be an improvement for users still at svtix.

please see http://wiki.xen.prgmr.com/xenophilia/ for the blow-by-blow.
If your concerned about RC's server's state, latest information will be in #rosettacode and #prgmr on irc.freenode.net. Obviously, please don't harass the prgmr folks just lurk and listen if you're in #prgmr; they'll be working as quickly as they can, and the more time they need to spend responding to questions, the longer things will take.

If you normally use RC's web IRC client, I recommend you find an IRC client more suitable to your tastes.
  • On Linux GUI, X-Chat is very good.
  • On Linux CLI, I use irssi, though I've been investigating switching to WeeChat.
  • On Windows, there's the SilverX X-Chat build, though mIRC is widely used.
  • I can't make a recommendation on Macs, but IRC clients for them are certain to exist.
  • Pidgin supports IRC, and if you aren't in as many channels as I tend to be, it may work well as an IRC client for you.
  • If you still prefer an in-browser solution, try webchat.freenode.net.
Also, I've been recommending prgmr.com to many people, personally. We'll see whether that continues dependent on the stability at the new data center.

by Michael Mol ([email protected]) at May 14, 2011 05:38 AM

May 11, 2011

Kevin Reid

Not the Traveling Salesman Problem

The problem of arranging a set of unbreakable text blocks in columns in an arbitrary order such that the columns are of approximately equal height is equivalent to the NP-complete “multiprocessor scheduling” problem, and the “LPT algorithm” described in the linked article performed excellently for my instance of the problem (4 columns, 6 blocks), which is actually my packing list for traveling to California tomorrow.

(I have a program which generates my packing list for me, based on type, duration, season, and transportation. It encodes all the accumulated knowledge about what to pack and where to pack it; after a trip I review my changes written on the printed list and incorporate them into the program.)

May 11, 2011 10:58 PM

April 25, 2011

Kevin Reid

April 13, 2011

Rosetta Code Blog

March 30, 2011

Rosetta Code Subreddit Feed

Rosetta Code Blog

Trademarks, Scams and DNS

Part of this blog post should interest people who own domain names and run websites. Part of this blog post should interest anyone with an interest in Rosetta Code.

I received yet another scam email this morning warning me that someone was going to register a domain that might infringe on my "intellectual property."

(copied in all its HTML glory)

Dear Manager:

This email is from China domain name registration center, which mainly deal with the domain name registration and dispute internationally in China and Asia.
On March 28th 2011. We received HAITONG company's application, they want to register " rosettacode" as its Internet keyword and CN/Asia domain names. It is china and Asia domain names. But after checking we find this domain name conflict with your company, in order to deal with this matter better, so we send you email, and want to confirm whether this company is your distributor or business partner in China?

I'm looking forward to hearing from you!

Best Regards,

John
Oversea marketing manager
Office: +86(0)21 6191 8696
Mobile: +86 1366152 9704
Fax: +86(0)21 6191 8697
web: www.ygnetwork-ltd.com


One technical thing you should notice about emails such as this: there's a space prepending the 'rosettacode' string, so the actual identifier would be " rosettacode".

DNS does not allow spaces in domain names, so, right away, this prospective domain would be invalid. Even if I were to respond to this email and pay the guy to buy the domain from the erstwhile squatter, there's no way he could sell it to me and enter it into the system. (I also doubt I'd get a refund)

About my general position relating to 'rosettacode' as a trademark

First, I'm not the first guy to come up with the domain. As it happens, rosettacode.com was (and I believe still is) owned by someone else. He and I have communicated a number of times since I discovered the potential conflict. He and I are working on two very different projects, so there's no trademark dispute. However, because I wanted to absolutely avoid any matter of ambiguity, I've been hosting a small amount of static data he provided as a kind of disambiguation page. (If you point 'rosettacode.com' to RosettaCode.org's IP address, you should still be able to see it)

Second, I don't care if you want to use the name 'rosettacode' or 'rosetta code' in similar pursuits. I love that people have been calling task pages that have cropped up on various forums around the web as "rosetta code problems." That speaks well of (and popularizes) the nature of the solution, which I like and appreciate. Besides, I own the rosettacode.org DNS entry. If someone wants to find Rosetta Code, I've got the implicit domain for it. It's really no skin off my teeth of you want to popularize the term.

That's all. I'd write about the massive amount of interesting things I've been watching happen on the wiki (we've got a large number of new users and tasks), but I'm a bit low on time.

by Michael Mol ([email protected]) at March 30, 2011 05:51 AM