Jul 18 2010

HOWTO: Setup MediaWiki as a Single-user CMS

Published by Chris Rebert at 9:31 AM

If, like me, you’re abusing MediaWiki as a content management system for your personal website, here are some suggested options to set in your LocalSettings.php:

#Stricter than normal settings:

#prevent anonymous users from registering
$wgGroupPermissions['*']['createaccount'] = false;

#prevent anonymous users from editing
$wgGroupPermissions['*']['edit'] = false;
$wgGroupPermissions['*']['createpage'] = false;

#disable section edit links for anonymous viewers
$wgDefaultUserOptions['editsection'] = false;

#remove userpage & usertalk links for anonymous
$wgShowIPinHeader = false;

#disable bot API
$wgEnableAPI = false;
$wgEnableWriteAPI = false;

#disable RSS/atom change feeds
$wgFeed = false;

#Looser than normal settings:

#disable 'nofollow' on external links
$wgNoFollowLinks = false;

#allow uploading of non-images
$wgStrictFileExtensions = false;
$wgCheckFileExtensions = false;
$wgVerifyMimeType = false;

#disable copyright checks on upload
$wgCheckCopyrightUpload = false;

#disable anti-vandalism patrols
$wgUseNPPatrol = false;
$wgUseRCPatrol = false;

#allow raw HTML in <html>...</html> blocks
$wgRawHtml = true;

#allow more liberal redirecting
$wgMaxRedirects = 42;
$wgFixDoubleRedirects = true;

#Other:

#unless your site is multilingual..
$wgHideInterlanguageLinks = true;

#unless you use the Universal Edit Button..
$wgUniversalEditButton = false;

And if you’re using the Monobook skin, add the following to /skins/monobook/main.css to hide the “talk” and “view source” tabs:

li#ca-talk {
display: none;
}
li#ca-viewsource {
display: none;
}

Note that this merely hides the links from view; they’re still in the HTML and are still accessible by anyone who knows how override your CSS or construct the URLs manually (i.e. mere security thru obscurity; I mainly do it to improve the wiki’s aesthetics).

Also, I’ve now finished switching hosting providers! (You may have noticed the site being flaky for a bit.) Rebertia is now proud to be hosted by prgmr.com. Their pricing for VPSes is quite good; I’m now paying less than I was for shared hosting at my previous provider. (Protip: Install Fail2ban and setup its SSH rule to avoid being 0wn3d; I’ve safely observed a surprising number of random SSH login attack attempts on my VPS)

Popularity: 27% [?]

No responses yet

Jan 24 2010

Of Braces and Semicolons

Published by Chris Rebert at 8:52 AM

Finally, a post that lives up to the second part of this blog’s tagline by being about programming! (Well, there was C in a (Nutshell)2, but my point is it’s been a while.)

Now, I’m a would-be language designer. Programming language theory fascinates me, and to that end I’ve read a number of books on different languages to try and get a feeling for all the various approaches and paradigms. I’ve also read many interesting blog posts found via proggit (and some via Lambda the Ultimate) which argue about language issues.

From all this, I’ve reached some conclusions which I’m going to try and lay out in a series of blog posts.

In this first post, I’ll cover:

The Problem of Delimiting Blocks

All modern languages are block-structured. (Thank you Dijkstra!) That is, code segments are semantically and syntactically organized into a tree. Let’s start with an example of some code in a Blub-average of today’s most popular languages:

class Foo(Object)
{
    void bar()
    {
        if (baz)
            quxx();
    }
}

The first problem we have is which brace style is the “Right One”. This is a perennial holy war. The style in this example wastes lines just for parentheses. On the other hand, it makes it very easy to perceive the block structure of the code. On the gripping hand, in practice, programmers don’t really care about the braces (except when the compiler gives a syntax error about them being wrong), and instead pay attention to the indentation. Secondly, we have the sub-problem of whether one-statement blocks should have braces around them; we have clarity and maintainability (what if the block expands beyond the one statement and someone forgets to add the braces? In many cases, this leads to subtle bugs the compiler does not warn you about.) versus wasting space and causing unnecessary scrolling. At any rate, we are led to the obvious question of: Why not use the indentation programmers insert anyway to delimit blocks and do away with the braces altogether? And indeed, some languages have tried this. The posterboy is Python (my current favorite existing language).

However, this solution has problems of its own:

  1. Copy-pasting code into environments where indentation is not preserved (e.g. some online forums) causes it to become unintelligible (well, in practice, one can apply some heuristics and try and re-indent it manually, but there’s no way to ensure you got it exactly right, and if the code is long enough, it’s a real PITA; whereas code using braces can be automatically re-indented by several tools)
  2. As one sees every so often in the Python community, there are people who harbor unreasonable hate towards syntax-significant indentation. From what I understand, most of these people have bad memories from some early version of FORTRAN and their fear is completely irrational. But if you want your language to be a very popular one, you’re probably going to have to accommodate these people.
  3. We’re still left with the second code formatting holy-war of spaces vs. tabs as the indentation character. (BTW, have you seen *NIX‘s default tabstop of 8? Personally, it makes my eyes bleed.)

Of course, along with braces are their friends the semicolons, and they annoy the heck out of me; they’re just plain unnatural. I should not have to always remember to end a line with anything other than a linebreak, because 90% of the time, statements are only one line long; the other 10% are the ones I should have to type extra characters for, and only then after considering refactoring the line so it’s more readable anyway. This is basic Huffman coding people! Optimize for the overwhelmingly common case, not the exceptional one. (If this was a research paper, I would back up this 90-10 distribution with some empirical statistics, but since this is just a blog post, I’m not gonna bother.)

So, in summation, semicolons and braces are bad design choices. Eliminating the semicolons is relatively simple. As for the braces, our choices for what to replace them with are the off-side rule (i.e. syntactically-significant indentation) or begin-end keywords ala ALGOL or Pascal. Though I personally prefer the former, I opt for the latter due to the aforementioned issues with the former. Now, does this actually solve our problems, or is this a meaningless textual substitution? We’ll get to that in just a sec. There is a downside to vanilla begin-end though, and that is that it looks retro/outdated (i.e. like Pascal) or like a scripting language (using the pejorative connotation; i.e. like sh or BASIC). However, if we do it intelligently, like Ruby does, we can reduce the resemblance and make the substitution meaningful. All we need to do is realize that the begin keyword is technically superfluous and that we can force end to always go on a line of its own. Here’s an example of code in this style:

class Foo(Object)
    void bar()
        if baz
            quxx()
        end
    end
end

Advantages:

  • No dangling else problem as long as you have a elif construct.
  • Only one indentation style (Well, you could not indent the ends, but since they require their own line, there’s no particular reason not to.)
  • No space is wasted compared to the more compact of the 2 main brace styles.
  • The required ends solve the “what if this one-line code block grows to multiple lines?” problem

Now, in Iguana, I plan to alter this just slightly by allowing 1-line blocks to use colons and skip the end keyword; this let’s us re-special-case one-line bodies without any ambiguity or strain on the parser while continuing to avoid the multiline growth problem. Here’s what this looks like:

class Foo(Object)
    void bar()
        if baz: quxx()
    end
end

Of course, in this particularly simple example, you could also write it like this:

class Foo(Object): void bar(): if baz: quxx()

But I would hope your code reviewers would thoroughly chastise you if you did, so please don’t.

I agree it is not the cleanest or most obvious approach, but it’s a compromise between theoretically-best and familiar-enough-to-be-popular.

Popularity: 41% [?]

No responses yet

Dec 07 2009

The Weather, Man

Published by Chris Rebert at 10:59 PM

There was pretty bad rain today, very unusual for San Diego in my experience (hence this post; you know it must be quite bad if I wrote one of my few, infrequent blog entries about it). However, I can probably count on one hand the number of rainy days I’ve experienced at UCSD, and what with the drought, I suppose it’s rather needed…

The wind was the worst part; to quote Dr. Evil, it was re-god-damn-diculous. It’s like the weather knew it was final week and decided to materialize the collective bad feeling in aqueous form, thus further increasing the stressful atmosphere. It particularly pissed me off because my umbrella (thanks for having the commendable foresight to give me one Mom and Dad) suffered catastrophic failure due to the intense wind; some of the metal wire bent and it will no longer close or open all the way (I’m gonna try and get a raincoat tomorrow). I got rather wet walking back from meeting with a TA and needless to say, it’s a tad awkward to be using a busted umbrella.

I’m definitely glad I don’t happen to have a final tomorrow. (And I’m also glad for the dorm heaters for once; 90% of the time, air conditioning would be more useful, but they’re super-nice this other 10% of the time [and no, those statistics were not derived using the sound techniques from the final I took today])

Further but related aside: Prof. Politis is excellent and I wholeheartedly recommend him.

Popularity: 24% [?]

No responses yet

Oct 19 2009

Things that will ruin your life:

Published by Chris Rebert at 11:11 PM

  • Wikipedia editing (oh, the inane and petty arguments no one outside of the ‘pedia will ever care about…and this too)
  • TV Tropes (it will explode your tabs. Seriously.)
  • Reading manga online (the wasted night (and day? (days(s)?)) of archive binging)
  • Watching Bittorrent‘d anime series (at least this one has the natural limiting factor of your connection speed)
  • Working in student any sort of government (No, really, it’s not quite that bad)

All these are complete time sinks. Trust me, I know. Through personal experience. The hard way.

Avoid them scrupulously. Do not click those links. Really, I’m serious, don’t click them. You’ll be sorry. All right, but don’t say I didn’t warn you…

Popularity: 24% [?]

One response so far

Jul 12 2009

xkcd & tvtropes

Published by Chris Rebert at 10:11 PM

Just saw the below xkcd and had to comment on it. It’s oh so true. One time, I got close to exhausting the memory of my 4GB MacBook Pro I had so many tvtropes pages open in tabs. It took a good three minutes to close them all…

xkcd shows the evils of tvtropes

xkcd shows the evils of tvtropes

Popularity: 24% [?]

One response so far

Jun 01 2009

CodeRally

Published by Chris Rebert at 11:51 PM

[Meta-note: Yes, I realize this is a bit dated and definitely out of chronological order; So sue me.]

Earlier this quarter, I, in partnership with Nick, participated in a programming contest put on by the CSE Department. It used a Java framework called “CodeRally” and involved programming an AI for a car on a virtual track. The cars start out at random locations and score points by doing various things, such as going through the track flags in order, throwing and hitting other cars with spare tires, etc. until time runs out. We named our AI “King Regicide” (all credit to my Desmondian counterpart for the name).

Our initial strategy we dubbed “tirespamming”; that is, just try and hit people with tires constantly and ignore trying to go around the track circuit. We got it partially working, but then decided that due to the point spread we should focus on writing logic to go around the track circuit. After fixing a particularly nasty bug that sometimes surfaced when turning from say 5° to 355°, we tuned the tire-firing logic and did decently in simulated contests. We also wrote some smart logic for when to activate our emergency shields. We had dreams of writing some code to evade tires, but we never got around to it.

We ended up finishing 19th in the second qualifying round, one short of the top 18 who got to advance to the final round. However, a couple instructors and TAs, who were ineligible to win any titles/prizes, finished ahead of us, and due to the aforementioned random starting locations there was a large random factor involved and not enough rounds were done, in my opinion, to mitigate this, so we got slightly screwed over. Oh well. Se la vie.

This was almost made up for by the hilarity of “Disappointer”, Prof. Dana Dahlstrom’s entry in the contest. I forget the exact details, but I believe that after a set amount of time stuck in a pileup (see next paragraph), it would extricate itself, tirespam the car who caused the pile-up and throw all available tires at it, and then go back to being stuck. All assembled got a grand laugh out of it.

On an interesting note, the biggest problem in the contests ended up being “pileups”. These are when one car runs out of fuel while going around the circuit, and another car hits it and is too stupid to go around it. Yet more cars would then also pile-up behind these cars, blocking the inner cars from moving at all. This would usually cascade until all the cars were motionless and part of the pile-up. Only one or two cars had AIs which were smart enough to deal with this situation, and interestingly they weren’t even the top finishers. We tried to add such a feature near the end of the contest, but completely ran out of time.

In the end, those who actually won the contest admitted that their AIs didn’t do anything particularly fancy compared to the average entrant: just go around the circuit, throw tires occasionally, and activate shields when necessary; I believe this further supports my assertion about the large, unaddressed random factors involved.

All in all, it was grand fun even though we were robbed of our chance to advance to the finals, and I look forward to next year’s contests. Props to the Dini Group for sponsoring the contest and providing caffeine and food!

Popularity: 24% [?]

No responses yet

May 23 2009

Obligatory Post-SunGod Post

Published by Chris Rebert at 9:16 PM

You knew it was coming. I couldn’t let the biggest on-campus event of the entire year slip by without mention.

So, yes, I attended Sun God Festival 2009, despite my usual aversion towards parties (who am I kidding, social events generally; but I have made progress). Unfortunately, my MMW 3 paper was also due that day in section and I also had an Algorithm Analysis quiz that morning, so it was not ideal. I had almost no sleep the night before, save a brief ~3 hour respite, as I worked on completing my paper, which probably impacted my quiz performance. In a twist of fate, however, my schedule inadvertently let me dodge a serious bullet.

You see, since everyone was anxious about getting into the festival, they started lining up in front of the box office early in the morning; by around 11 or so, this line stretched down from Ridge Walk down to Peterson Hall, turned the corner, went down past Geisel and the Price Center, and, for at least a time, continued into Warren Mall. To paraphrase Garrett Berg, it was as if everyone in school had gotten in line. At once. Needless to say, there was some criticism of the wristbanding system afterwards. The sheer mass of people (in contrast to the usual relative dearth of students) led me to momentarily ponder whether some people enroll just to go to Sun God. Needless to say, the line complicated my movements to-and-from Geisel to research and print. Now finally to the “fortunate” part: due to my classes, I didn’t go to get my wristband until around 1PM, by which time the line had disippated entirely and getting into the festival was a breeze (rumors of insufficient wristbands being available were greatly exaggerated).

So, on to the festival proper: Ironically, I liked the Midway tent and its performances rather than the headliners, which makes sense considering I’d only heard of 2 of the headliners and I’m not a fan of hip-hop. Highlights from the tent include:

  • Cirque Berzerk: sort of like Cirque de Solei on Goth crack, it featured some amazing fire acts
  • Kaba Modern: an astounding Asian dance group whose impressive performance just kept on going (every time I thought they had come to a reasonable stop, there was a brief pause and the music changed)
  • A performance by UCSD’s Cheer squad (IIRC), which featured an (appropriate for UCSD) lab coat-themed suggestive dance
  • A great comedy routine featuring Horatio Sanz, a guy who was literally butt-naked save for a fannypack, and a good bashing of Communications and Poli Sci majors (hehehe ;-)

The main stage  was not completely ignored by me, however. In between a ~3 hour nap to make up for the insomnia, I saw:

  • Augustana, whose vibe was entirely enjoyable as I laid on the grass listening, although the lead singer’s fangirls were a slight annoyance
  • Sara Bareilles (I have no idea how you pronounce her last name), who agonizingly delayed her ultimately poppin’ performance of her Love Song…song with less famous filler and finished with an unexpected but certainly unique rendition of Rihanna‘s Umbrella (of all things)

I managed to avoid alcohol and drugs myself (unlike many apparently; suffice it to say I saw a few “men down” in apparent need of aid while walking around), instead opting for a fresh but entirely too large funnel cake. I also been there, done that, got the T-shirt and got dinged for an excessive surcharge at the on-festival ATM.

All in all, it was quite a fun day, sleep deprivation aside, and I look forward to next year. Now I just need to actually visit the beach one of these days…

Popularity: 24% [?]

One response so far

May 01 2009

Broomball – The Official Sport of Fun and Bruises

Published by Chris Rebert at 4:52 AM

Tonight, some of us Roosevelt First Years played Broomball; and as a first-time player, I have to say it was a large barrel of fun, even though my side lost (but considering that no one ever declared which color brooms were supposed to go which direction and thus the teams were arbitrary and uneven, it’s nothing to be shamed about).

The only disappointing thing was that the sport didn’t turn out to actually involve brooms (in the normal sense); instead the “sticks” were more like polo sticks with flat, triangular plastic heads; but this minor disappointment quickly pales in comparison to the joy of playing this game as part of a mob

For those who are unfamiliar, broomball is basically like ice hockey, except it uses the “brooms” instead of hockey sticks and a ball instead of a puck, and, most importantly, ice skates are not worn. The lack of proper skates is largely what makes the game so fun — trying to rapidly change direction proves to be impossible and attempting it results in you losing your balance and either falling on your ass or awkwardly breaking your fall with one or more hands, but of course the fast-paced nature of the game demands that you move rapidly to respond to the movement of the ball. Needless to say, Hilarity Ensues (oh wait, I’m not writing a comedy series pitch… hmm. <scribbles frantically>). The sheer number of people involved, along with the fact that we used 2 balls concurrently meant there was never a lull in action, thus intensifying the effect.

So, I might have a decent bruise on my butt from falling down hard on it once, but it was well worth it. Now if only there was an intramural version of Broomball, I would join in a second and it would be awesome. All in all, the game was quite satisfying and made me harken back to my old glory days as a Fullback in AYSO soccer.

Popularity: 24% [?]

No responses yet

Apr 06 2009

Human Sorting Algorithms Video

Published by Chris Rebert at 9:24 PM

A while back in high school (Menlo School to be precise), myself and some other members of The Neighborhood (the math & comp sci club), suggested we try acting out the various sorting algorithms with humans and videotaping it. Unfortunately, we never were able to make the necessary arrangements to actually carry out the project, though I did write choreographic drafts for a couple of the sorts at one point.

However, this year during Knight School, some other Neighborhood members held a course on algorithms and managed to make the dream a reality. Here’s the terrific video on YouTube.

For what I can only assume were time constraints, Quicksort sadly is not shown(!). Neither is Heapsort, but that would be particularly hard to videotape given the necessary viewing angle to show the structure of the heap being made.

Anyway, congratulations to everyone in the “Algorithmic Thinking” Knight School class of 2009! Great job!

[EDIT: Also, I don't remember seeing that Obama clip before. That's pretty funny. I wonder who clued the Commander-in-Chief in...]

Popularity: 24% [?]

2 responses so far

Apr 04 2009

C in a Nutshell in a Nutshell

Published by Chris Rebert at 2:12 PM

I recently finished reading C in a Nutshell, which I highly recommend as an excellent C reference and tutorial to anyone with programming experience. I previously learned some MS Visual C++ at CyberCamps some years ago, but finding the language a bit clunky, I searched around the web, found Python and have been in love with it ever since. But since every programmer should know (at least most of) C, and I had a C/Assembly course coming up, I resolved to learn C properly; hence the book. Anyway, here are my notes from it, both as a memo to myself and in the hope that others might find it mildly useful:

Interesting trivia

  • index[array] ≡ array[index] ≡  *(array + index)
  • arguments to a function may be evaluated in any order by the compiler
  • The signed-ness of plain char is compiler-dependent

C99 Hotness

  • Boolean type introduced:
#include <stdbool.h>
bool a = true, b = false;
  • //-comments formally allowed
  • declarations can go anywhere within a function; C89 forces you to declare everything at the start of the function

Syntax

#include <something_in_std_lib.h>
#include "your_own_lib.h"
enum SomeEnum {A, B, C};
typedef someDeclaration newTypeAlias;
  • const keyword, like Java’s final
  • static keyword means private to this source file, like C#’s internal

Basics

int main(int argc, char * argv[])
char aStringVariable[length];
  • EXIT_SUCCESS, EXIT_FAILURE defined in stdlib.h

Function pointers

int foo(char);//declare function
int (*funcPtr)(char) = foo;
int result = funcPtr('a');//use func pointer

Objects

Defining

struct Foo
//unions use same syntax, just w/ different keyword
{
    int a;
    char b;
}

Using

/* C99: */ struct Foo bar = {.b = 'Q', .a = 42};
/* C89: */ struct Foo baz = {42, 'Q'};

Defining macros

  • Function-like macros: #define foo(a,b) ((a)-(b))
  • The ## operator within macros:
    • Given: #define foo(x) MSG_##x
    • Then: foo(A)MSG_A
  • The # operator within macros – converts operand to string

Useful macros

Assertions:

#include <assert.h>
assert(booleanExpression);
  • #define NDEBUG – disables asserts
  • #error "Message" – causes compile error with given message
  • Conditional compilation: #if#elif#else#endif

Metadata macros

  • __func__ – name of current function
  • __LINE__ – current line number
  • __FILE__ – name of current file
  • __TIME__ – time of compilation
  • __DATE__ – date of compilation

Standards macros

  • __STDC__ – bool for whether compiler is C89-compliant
  • __STDC_VERSION__199901L >= if C99-compliant
  • __STDC_IEC_559__ – bool for IEEE-754 compliance

Stdlib survey

  • stdlib.hmalloc()free(), array sorting, binary search, str->num conversion, random numbers
  • stddef.h: defines NULL, size_t
  • string.h: also includes general array/memory stuff
  • math.h, time.h: speak for themselves
  • errno.h: defines errno global var
  • ctype.h: ASCII character classification
  • fenv.h: controls floating point rounding mode, etc [C99 only]
  • limits.h: limits of integer types
  • float.h: describes properties of float representation
  • See also my summary of the essential parts of the stdlib

GCC options

  • -o exec_name (instead of a.out)
  • -Idir_name:other_dir_name (places to also look for headers)
  • -fsyntax-only (just check syntax)
  • -ansi (use C89)
  • -std=c99 (use C99)
  • -Wall (warn about a bunch of stuff)
  • -pedantic (adhere pedantically to standard)
  • -Wextra (warn about strange/pointless code)
  • -g (add debug info)
  • -pg (add profiling hooks)

Popularity: 26% [?]

5 responses so far

Older Entries »