Random Panic Linux Kernel Module

Published
Last Updated
Author(s)
Enimihil
Tags
#code

This kernel module, entirely useless, and probably not even very funny, is meant to torment people you don't like. And who let you have root access anyway.

As the description states, when loaded it will set a timer for a random amount of time into the future, 0-65535 seconds, to call panic() with a randomly selected message (grep'ed from the kernel source tree, see panic_msgs.h)

This really should serve to frustrate and annoy anyone attempting to use the machine if the module were loaded automatically on boot. Don't do it without expecting a nosebleed when they find out it was you.

The source can be downloaded from the mercurial repository or you can download a tarball.

Not much to it, type make and it'll compile. insmod it and it'll do it's thing.

risk-calculator.py

Published
Last Updated
Author(s)
Enimihil
Tags
#code #game probabilities #python #risk

[Game of World Domination] battle probability calculator. A python script to calculate the success of conquering a territory.

Download

#!/usr/bin/env python

from __future__ import division
import sys

def cross(*args):
    if not args:
        yield []
        return
    for i in args[0]:
        for n in cross(*(args[1:])):
            yield tuple([i] + list(n))

# http://linux.derkeiler.com/Mailing-Lists/Fedora/2005-11/4432.html
def combinations_r( list_of_items, number_of_picks ):
    k = number_of_picks
    n = len(list_of_items)
    if k==0 or n==0:
        return
    b = [0]*k # make list [0,0,0,....,0] - of length k
    bdone = [0]*k
    while True:
        choice = [list_of_items[i] for i in b]
        yield tuple(choice)
        # Modify b in place (an addition operation in base-n)
        for i in range(k):
            b[i] += 1
            if b[i] < n:
                break # break our of for loop, no need to carry
            b[i] = 0 # carry
        if b == bdone:
            break # break out of while loop, no more choices left
    return

RANGE = range(1,7)

DIE_PROB = 1/max(RANGE)

SINGLE_DIE = list((x,) for x in RANGE)
TWO_DICE = list(combinations_r(RANGE, 2))
THREE_DICE = list(combinations_r(RANGE, 3))

dice_rolls = {
    1: SINGLE_DIE,
    2: TWO_DICE,
    3: THREE_DICE,
}

def risk_wins(attack, defense):
    at_victory = 0
    de_victory = 0
    for at,de in zip( sorted(attack, lambda x, y: y-x),
                      sorted(defense, lambda x, y: y-x) ):
        if at > de:
            at_victory += 1
        else:
            de_victory += 1
    return at_victory, de_victory


def make_probability(nattack, ndefense):
    attacker = dice_rolls[nattack]
    defender = dice_rolls[ndefense]

    probs = {
        (2, 0): 0,
        (1, 0): 0,
        (1, 1): 0,
        (0, 1): 0,
        (0, 2): 0,
    }
    values = list(cross(attacker, defender))
    for at_roll, de_roll in values:
        at, de = risk_wins(at_roll, de_roll)
        probs[(at,de)] += 1

    l = len(values)
    for k in probs:
        probs[k] /= l

    return probs

def calculate_round(nattack, ndefense):
    probs = make_probability(nattack, ndefense)
    diffs = {}
    for k, v in probs.items():
        at, de = k
        diffs[(-de, -at)] = v
    return diffs

def decision_sum(decision):
    ats, des = 0, 0
    cum_prob = 1.0
    for (at, de), prob in decision:
        ats += at
        des += de
        cum_prob *= prob
    return ats, des, cum_prob

def make_decisions(nattack, ndefense, iterations):
    decisions = []
    from pprint import pprint
    for i in range(iterations):
        if not decisions:
            decisions = [ [(o, p)] for o, p in calculate_round(min(nattack-1, 3), min(ndefense, 2)).items() if p != 0.0]
            continue
        for decision in decisions[:]:
            at, de, _ = decision_sum(decision)
            try:
                round = calculate_round(min(nattack+at-1, 3), min(ndefense+de, 2))
            except (KeyError, AssertionError):
                continue
            for outcome, prob in round.items():
                if prob == 0.0:
                    continue
                try:
                    decisions.remove(decision)
                except:
                    pass
                decisions.append(decision + [(outcome,prob)])
    return decisions

def calculate_outcomes(nattack, ndefense, iterations):
    decisions = make_decisions(nattack, ndefense, iterations)
    results = []
    for decision in decisions:
        ats, des, cum_prob = decision_sum(decision)
        if cum_prob == 0.0:
            continue
        results.append( (nattack+ats, ndefense+des, cum_prob) )
    assert str(sum(prob for na, nd, prob in results)) == "1.0"
    return results

def print_outcomes(results, n):
    winp = 0.0
    losep = 0.0
    draws = {}
    for nat, nde, prob in results:
        if nat == 1:
            losep += prob
        elif nde == 0:
            winp += prob
        else:
            if (nat, nde) not in draws:
                draws[(nat,nde)] = 0
            draws[(nat,nde)] += prob
    draws = [ (nat, nde, prob) for (nat, nde), prob in draws.items() ]

    print "Chance of victory in %d battles: %3.2f%%" % (n, winp*100)
    print "Chance of defeat (1 remaining) in %d battles: %3.2f%%" % (n, losep*100)
    for at, de, prob in draws:
        print "%3.2f%% chance of:" % (prob*100)
        print "\tAttacker remaining: %d" % at
        print "\tDefender remaining: %d" % de

def print_result(probs):
    for result, prob in probs.items():
        if prob == 0.0:
            continue
        at, de = result
        print "Attacker Loses: %d, Defender Loses: %d (probability %1.2f)" % (de, at, prob)

def testmain():
    for at, de in cross(range(1,4),range(1,3)):
        print "------------------------------------------------------------------------"
        print " Attacker: %d dice Defender: %d dice" % (at, de)
        print "------------------------------------------------------------------------"
        print_result(make_probability(at, de))

def main():
    at, de, n = int(sys.argv[1]), int(sys.argv[2]), int(sys.argv[3])
    print "Attacking Units: %d\t\tDefending Units: %d\t\t# of Battles: %d" % (at, de, n)
    print_outcomes(calculate_outcomes(at, de, n), n)

if __name__=='__main__':
    sys.exit(main())

On Open Minds and the Value of Information

Published
Last Updated
Author(s)
Enimihil
Tags
#essay #information #mind #open #philosophy #skeptics #values #writings

I came upon a thought recently, while wandering through my brain, and I feel like I should write it down to clarify and crystallize it. It's not fully formed, and is just a notion; I have no evidence to back it up.

Phrased as a question, it looks something like this:

Do skeptics value information less than the more open-minded?

To elaborate, I wonder if the nature of skepticism is to create a value judgment about information in general — that information is, by itself, worth very little, any one piece of information is only of trivial value. Then, I posit, it might be the case that the open-minded place a higher value on information; any piece of information is valuable and important in isolation. The open-minded put a value on knowing, regardless of what is known.

I ask these questions, and wonder about these things, primarily because it seems to me skeptics reject information too easily. I'm not saying that skeptics should reject information that is incorrect, or wrong, or <insert-reason-here>; It seems to me the default assumption of skeptics (that assertions are false) leads to the undesirable quality that skeptics say, "Prove it to me," rather than, "I must investigate."

Again, this is not a fully formed idea, but a sketch — a fragment. Do skeptics (especially hard-line skeptics) value information differently than more traditional viewpoints might suggest?

Possibly Asked Questions

Published
Last Updated
Author(s)
Enimihil
Tags
#about #faq #new-world-order #paq #purpose #questions #site-related

What "New World Order" is this? And why do I have to take notes?

It's a tongue-in-check name to give it a name. I don't plan to take over the world, establish some new world order, or make any particular impact on the world.

I do, however, have notes. So, as broadly and generally as that, these are my notes on things that possible relate to a better world.

Wait... what?

The name of the site notwithstanding, this is a place for me to put interesting things. The nominal plan was to have articles and essays, along with maybe a bit of fiction, and some technical stuff because I do write a bit of software.

My idea was that the site become a sort of idea repository, not necessarily a complete picture, just fragments in which you might glimpse the whole (like a hologram).

So you say you want a Revolution...

Published
Last Updated
Author(s)
Enimihil
Tags
#annoyance #essay #government #guidance #philosophy #politics #semiserious #writings

With all the fuss and politicking around the new (September 2008) rapidly approaching presidential election, many people are feeling like new leadership isn't going to fix anything. The problems we face seem endemic to the whole system of government we have.

(At least that's the explicit frustration I've heard from one person I know, and many other people I talk to seem to agree. But I don't really get out much so this opinion may be based on the intelligent-technical-college-student culture and not something more general. — he, at least my biases are fairly obvious.)

Anyway, it seems like the current governmental strucutre is brokne or at the very least malfunctioning. If, for a moment, we assume that is true, and some other system would be superior, then we have a few things we need to know:

  • What system is superior, and how?
  • In what manner can the new system be instituted, or what manner can it not be instituted?

To answer the first question requires answering a lot of other questions, at the very least, identifying the superior system.

The second question is somewhat easier to break apart because we only need to know about the current system; though, it is possible the superior system's specifics will inform the precise answer (or the optimal answer).

The tried and true, old school, tested and respected method of changing out governmental systems is, of course, revolution.

But revolution is the brute force approach, it's hard, messy, and inelegant — if romantic. It also doesn't work very well "at scale."

The United States military is one the most dominating forces in the world. When both sides of a revolution had muskets, it's one thing. When one side has hunting rifles and the other side has air support — The side the the air support wins.

So straight revolution is out, unless the military is leading the way, in which case, by historial example, things have probably Gone Horribly Wrong.

The next most obvious thing to do is to have the system change itself. Revolution from within, so to speak. This, of course, relies on the system being somewhat functional, and not broken in the very particular manner of trying to keep the power it has at all costs. That last bit, unfortunately, is usually a symptom of a system that needs changing.

If you go the route of infiltrating the system until you have enough control to enact the changes you want — you've just created a totalitarian state, just like the fascist leader of the nineteen thirties and forties. This may be acceptable if there is a single restructuring and the totalitarian control goes away; but again, history tells us that doesn't actually happen.

We (the proto-revolutionaries) could try to make the current system obsolete. We provide a compelling alternative to everything the system currently provides. Then the system gets replaced effectively, but not on paper. Eventually, when everyone realized the old system is not longer necessary the old system can be removed.

Again, there are a host of problems with this plan, the the least of which is the issue of providing services in competition with your government's while not being a recognized sovereign power.

The last option, the easiest of all, is to simply write about the change,s what you want, what needs to happen. Nothing will actually change, but you do get the melancholy satisfaction of saying "I told you so," when someone complains about the system.

I don't think there's an easy answer to find for changing the status quo. You need to look at your agenda, timetable, and resources to find the best option. If you've figured out the superior system — go to it, maybe we can avoid an ungraceful all from out decaying superpower status. Instead, what?

Go buck the system, start a revolution; but remember you New World Order is standing ont he shoulds of the giant before you.

And have a plan!

Google App Engine Pylons Authentication Decorator

Published
Last Updated
Author(s)
Enimihil
Tags
#code #decorator #googleappengine #pylons #python #technology #writings

I've recently been playing with Google's latest strange (ad)venture, Google App Engine. I've been addicted to python for a while, and have been playing with some of the web frameworks like TurboGears and pylons. So I jumped on the opportunity to write something I wouldn't have to worry about getting slashdotted for. That is, if I could get slashdotted (or dugg, or whatever).

In any case, it's a interesting framework, the datastore is different from anything you've probably worked with before, but is definitely worth a look, if only to expand your mind.

But, I just recently started writing an application with the App Engine SDK using pylons, and had a need to restrict access to certain pages of the application to logged in, or administrative users. Google's user API allows this fairly easily, but I wanted something nice and simple, so I wrote a decorator for the controller actions.


  1. from decorator import decorator
  2. import google.appengine.api.users as users
  3.  
  4. @decorator
  5. def reqire_user(f, *args, **kws):
  6. if users.get_current_user() is None:
  7. redirect_to(users.create_login_url(request.path_info))
  8. else:
  9. return f(*args, **kws)
  10.  
  11. @decorator
  12. def require_admin_user(f, *args, **kws):
  13. if users.get_current_user() is None:
  14. redirect_to(users.create_login_url(request.path_info))
  15. elif not users.is_current_user_admin():
  16. return render('/need_admin.mako')
  17. else:
  18. return f(*args, **kws)

Free to use, put it in the public domain, no need to credit or anything. Just thought I'd throw this out there for all those people who are new to python and might not think of this solution first.

We have collectively decided we don't want to decide…

Published
Last Updated
Author(s)
Enimihil
Tags
#essay

Just sharing a link:

Blogging, the nihilist impulse

A nice long essay on the philosophical interpretations of Blogging phenomena. This is pretty much the sort of thing (though I found this quite some time after) that I started this site to aggregate, and hopefully produce.

The essay is a bit negative, from my perspective, but any time philosopher's are faced with the idea that the only course of action left is to give in to unreason, or to live a vapid empty lie of a life...well, you can see where they get it. The point is, the Internet is a cynical, nihilistic place, and this essay may help you to understand that you'll never understand why. I certainly can't follow even most of the references, but I'd say I understand enough of it to know that we're either pretty screwed, or philosopher's are going to have a hell of a time figuring out what to do when things really get going.

Polycom 500 VoIP on the Cheap

Published
Last Updated
Author(s)
Enimihil
Tags
#cheap #ebay #electronics #hacking #phone #polycom #technology #voip #writings

Background

I'll start this story at the beginning, because there's no other place really to start a story, and get to the fun tech stuff later.

I worked over the summer and into the fall of this year (2007) at a small local company that provides call center, call recording, and CRM software solutions for a variety of businesses across the world. A big part of the business was VoIP solutions, both hosted and deployed at customer sites, and I spent some time working with Polycom 500/501 VoIP phone configuration files (dynamically generated over HTTP for the 501's).

At some point at work it was mentioned that the rather expensive Polycom phones could be had on eBay for a steal, and since I was curious I decided to take a look. One week later I ended up with a Polycom 500CS phone for a total of $17.50 including shipping.

More after the break...

The Problem

The reason I was able to get the quite nice phone so cheaply was that it came without a power adapter. Usually that's not too much of a problem, because you can just pick one up at the local $hack. Complication #1: Polycom IP phones don't use a separate power supply, they take power over the ethernet cable. Complication #2: The Polycom power over ethernet isn't documented anywhere I could find on the internet.

Now, I could just go and buy an adaptor/special cable for the phone, but that would probably cost me as much as I paid for the phone, which is no good. I'm a cheapass student, I'm not going to pay more than I paid for the device to turn it on...

The Solution

So, the obvious solution, I think, is to just make my own damn cable / power supply. Unfortunately, I'm not an electronics guy really, and while I'm not a complete neophyte when it comes to soldering and wires, I really haven't physically done very much of this sort of hacking.

The first challenge, figuring out what power (voltage, which wires) wan't too difficult, because I was still working at the time and had easy access to take a look at a real polycom power supply. 12V, and on some pins I couldn't figure out.

The unused pins for 100Base ethernet are 4,5,7, and 8, so I just took an ethernet cable I didn't mind accidentally ruining and stripped out those wires. I took a multimeter to them and found out that 4,5 and 7,8 were connected.

I've got an old computer power supply (who doesn't?) that I've used for random tinkering before, so I twisted 4,5 and 7,8 wires together and hooked up the 12V from the power supply with some alligator clips and bits of wire™, and the multimeter for good measure just to see what voltages were where. I turned on the power supply and...blinking red light and bootup!

(Alright, there were a few hiccoughs and trials along the way, but I've outlined how I would do it if I knew what I was doing from the begining.)

So now all I've got to do is get a less bulky power brick that'll power the phone, solder it all up and start setting up the phone and software to connect up with Gizmo and FWD and so on. That's slightly complicated by the fact that the phone is a CS phone, meaning it's a MGCP protocol phone, but I'm fairly certain I can just flash the SIP firmware onto it, as SIP is much more widely used and there's more open source / free software that uses it.

The attached bad cell phone camera photos are hopefully illustrative of the setup and what I did. If not, sorry.

UPDATE: Well, having done some work to get the phone powered, I've run across a new problem. The phone seems broken, i.e. it won't pull DHCP, or even light up the port on the switch. I hope it's not something I did to it, but I can't be too upset, the thing was practically free.

So for now, it goes in the bin with all my other semi-broken electronics, waiting for me to have the time and skill to fix or cannibalize for other projects.

More updates when I have them...

Attachment Size
1128072350a.jpg 119.5 KB
1128072350b.jpg 64.38 KB
1128072350c.jpg 164.97 KB
1128072350d.jpg 159.78 KB
1128072350.jpg 176.69 KB
1128072351.jpg 145.96 KB

Punctuality Problems

Published
Last Updated
Author(s)
Enimihil
Tags
#creative writing #fiction #science fiction #short story #writings

"The important thing is the educational experience itself — how to survive it." — Donald Barthelme

Cori woke up to a high and whiny sound filling her cluttered dormitory room. She rolled out of bed and grabbed her Student Information Device (SID). A sort of planner, organizer, and alarm clock economically packaged into a hand-held device the size of a small novel; University standard issue.

"Ugh," she said. Today is not a day I want to be woken up early by imminent annoyance, she thought, Starting the week exhausted is not the way to go.

Cori hit a button on the side of the device; the sound ceased. The SID display read, "WARNING: Temporal Disturbance. Local time altered. Low battery: change soon." She turned off the SID and quickly glanced at her clock: "1:20 PM." Her heart nearly skipped a beat. Her only Monday class, Genetic Engineering 253 Making Friends: Technique & Practice, started in ten minutes — on the other side of campus. Cori snatched up her things and started sprinting.

It's trouble if students are late for afternoon classes because morning didn't happen, thought Cori. One day isn't enough time to recover from Saturday's Fiasco Science Fair. I'm certainly not, and yesterday, people were still picking shrapnel out of their clothing.

Cori absently dodged through the normal campus hazards: High Energy & Entropy lab exhaust pipes, ambulatory vending machines, and the occasional crater. She vaguely remembered some of the new ones as she crossed the quad— it was all a bit foggy, she had awakened quite confused in the Student Health Center late Saturday afternoon.

What kind of sick person skips over Monday morning? she thought, There's nothing inherently bad about it. It's just unpopular because it comes after Sunday night.

Quickly glancing up at the University clock, Cori noticed the clock read Sunday, not Monday. Double-checking against her SID, she sighed. She was about twenty-four hours early.

"Not again," moaned Cori. Still, she couldn't remember what was the official policy for repeated days?

Movie Operating System

Published
Last Updated
Author(s)
Enimihil
Tags
#computers #fiction #movie #operating #satire #system #technology #writings

The Movie Operating System (MOS) is that operating system seen in the movies, the one with all the pretty graphics, weird displays, and magical powers. The one that doesn't have users, only passwords, and only one password. The one that can't be hacked from the outside, and runs on a mainframe in a vault underneath the volcano.

Yeah, right.

This document aims to outline how, in our very non-cinematic universe we could emulate the movie operating system, or at least fake it well enough that one could then film it as if it were real™.

First of all, I'd like to say this was my idea, but it's not. (See HollywoodOS for example.) I was introduced to it by a friend. I'm just writing this down here because I think it'd be a fun project, and, while I do work far too much right now, I do have the capability to do it. More or less.

My plan is to make a 'Linux flavor' that has basic functionality for the MOS, and work towards something usable as a 'software prop,' and eventually, perhaps as an actual computer (like, web browsing and email). Unfortunately, this plan will most likely require graphic design skills beyond my own, and creativity greater than what I can currently muster. Plus, I'm not much of a movie-goer, so I probably require inspiration from those who are to really do this idea any justice.

Planned features:

Boot modes like:

...more to come when I have time.