codeneko
read my profile
sign my guestbook

Visit codeneko's Xanga Site!

Name: codeneko
Country: United States
State: Idaho
Metro: Boise
Gender: Male


Message: message me


Member Since: 5/8/2005
Premium

SubscriptionsSites I Read

Blogrings
Vendor Trash
previous - random - next


Posting Calendar

|<< oldest | newest >>|
view all weblog archives

Get Involved!

Suggest a link

Recommend to friend

Create a site


Thursday, September 06, 2007

"They most likely failed to clamp donw on features and design and got bit in the ass by feature creep and the fuck up fairy - she loves to poke her head in when you change things."

A reply from a /. article that I found humorous.


Thursday, May 10, 2007

Here is the same script with additional functionality and more configuration options...


#include <asuka.hpp>
#include <iostream>
#include <fstream>

AT::Configuration config;


//
// Loads a lua datafile...
//
AT::Field load(AT::Field file, AT::Field root) {
  lua_State* state = luaL_newstate();

  luaL_openlibs(state);

  AT::Field contents = AT::Path::open(file);
  contents.push("return ");
  contents.push(root);

  if(luaL_loadstring(state, contents)) {
    throw("failed to load example.lua");
  }
  if(lua_pcall(state, 0, LUA_MULTRET, 0)) {
    throw("script failure");
  }
 
  return(state);
}

//
// Updates the member database
//
AT::Field members(AT::DB::Interface &connection, bool init=false) {
  AT::Field resultset;
 
  AT::DB::Query db(&connection);
 
  try {
    if(init) {
      std::cout<<"*** attempting to initialize the database"<<std::endl;
     
      AT::Field query;
      query << "CREATE TABLE IF NOT EXISTS vt_guild_members ("
            << "userid int(11) NOT NULL default '0',"
            << "username varchar(25),"
            << "rank varchar(25),"
            << "note varchar(256),"
            << "class varchar(25),"
            << "officernote varchar(256),"
            << "level int(11),"
            << "status varchar(25),"
            << "PRIMARY KEY  (userid));";
     
      db.exec(query).status();
    }
   
    AT::Field timestamp_stats = AT::stat(config["MEMBERS_TIMESTAMP"]);
    if(timestamp_stats.defined()) {
      AT::Field members_stats = AT::stat(config["MEMBERS_SOURCE"]);
      if(members_stats[9] < timestamp_stats[9]) {
        std::cout<<"*** no updates necessary"<<std::endl;
        return(undef);
      }
    }
   
    //
    // Load the current dataset off disk
    //
    AT::Field state = load(config["MEMBERS_SOURCE"], "ES_GuildCheck_Data");
    AT::Field updates = state.shift();
   
    AT::Field guild;
    foreach(guild, updates.keys()) {
      std::cout<<"entry '"<<guild<<"'";
      if(guild == config["GUILD"]) {
        std::cout<<" <- updating";
      }
      std::cout<<std::endl;
    }
   
    //
    // Load any pre-existing members from the database
    //
    resultset = db.exec("SELECT * FROM vt_guild_members;");
   
    //
    // Brute-force check for new/old members...
    //
    std::cout<<"checking for deletes"<<std::endl;
    AT::Field row;
    foreach(row, resultset) {
      if(!updates[config["GUILD"]]["members"][row["username"]].defined()) {
        std::cout<<row["username"]<<" ... removing"<<std::endl;
        AT::Field query;
       
        query = "UPDATE vt_users SET block=1 WHERE username='%0';";
        db.exec(query, row["username"]).status(true);
       
        query = "UPDATE vt_guild_members SET status='na' WHERE username='%0';";
        db.exec(query, row["username"]).status(true);
      }
    }
   
    //
    // Set the userid incrementer to highest userid currently in-use
    //
    AT::Field userid = 10000;
    AT::Field rs = db.exec("SELECT MAX(userid) as max FROM vt_guild_members;");
    if(rs[0]["max"] > userid) {
      userid = rs[0]["max"];
    }
   
    std::cout<<"checking for inserts/updates ("<< userid <<")"<<std::endl;
    AT::Field username;
    foreach(username, updates[config["GUILD"]]["members"].keys()) {
      std::cout<<username;
      AT::Field user = updates[config["GUILD"]]["members"][username];
     
      AT::Field found;
      foreach(row, resultset) {
        if(row["username"] == username) {
          found = row;
          break;
        }
      }
      if(found.defined()) {
        std::cout<<" ... updating"<<std::endl;
        AT::Field values;
        values[0] = found["userid"];
        values[1] = db.escape(username);
        values[2] = db.escape(user["Rang"]);
        values[3] = db.escape(user["Notiz"]);
        values[4] = db.escape(user["Klasse"]);
        values[5] = db.escape(user["Offiziersnotiz"]);
        values[6] = db.escape(user["Level"]);
       
        std::cout<<"("<<found["userid"]<<")";
       
        AT::Field query;
        query << "UPDATE vt_guild_members SET "
              << "username='%1',"
              << "rank='%2',"
              << "note='%3',"
              << "class='%4',"
              << "officernote='%5',"
              << "level=%6 "
              << "WHERE userid=%0;";
       
        db.exec(query, values).status(true);
       
        std::cout<<" ... updated"<<std::endl;
      }
      else {
        AT::Field values;
        values[0] = ++userid;
        values[1] = db.escape(username);
        values[2] = db.escape(user["Rang"]);
        values[3] = db.escape(user["Notiz"]);
        values[4] = db.escape(user["Klasse"]);
        values[5] = db.escape(user["Offiziersnotiz"]);
        values[6] = db.escape(user["Level"]);
        values[7] = "new";
       
        AT::Field query;
        query << "INSERT INTO vt_guild_members ("
              << "userid,"
              << "username,"
              << "rank,"
              << "note,"
              << "class,"
              << "officernote,"
              << "level,"
              << "status"
              << ") VALUES (%0, '%1', '%2', '%3', '%4', '%5', %6, '%7');";
       
        std::cout<<"("<<userid<<") ";
       
        db.exec(query, values).status(true);
       
        std::cout<<" ... added"<<std::endl;
      }
    }
   
    std::ofstream file;
    file.open(config["MEMBERS_TIMESTAMP"], std::ios::out | std::ios::app);
    if(file.is_open()) {
      file<<time(NULL)<<"\n";
    }
    file.close();
  }
  catch(AT::Field e) {
    return(e);
  }
  catch(...) {
    return("Unknown exception occurred");
  };
 
  return(undef);
}

//
// Updates the bank page
//
AT::Field bank(AT::DB::Interface &connection, bool init=false) {
  AT::Field resultset;
 
  try {
    AT::Field timestamp_stats = AT::stat(config["BANK_TIMESTAMP"]);
    if(timestamp_stats.defined()) {
      AT::Field bank_stats = AT::stat(config["BANK_SOURCE"]);
      if(bank_stats[9] < timestamp_stats[9]) {
        std::cout<<"*** no updates necessary"<<std::endl;
        return(undef);
      }
    }
   
    //
    // Load the current dataset off disk
    //
    AT::Field state = load(config["BANK_SOURCE"], "ACUI_MyBankProfile");
    AT::Field updates = state.shift();
   
    AT::Field toon;
    foreach(toon, updates.keys()) {
      std::cout<<"entry '"<<toon<<"'";
      if(toon == config["BANKTOON"]) {
        std::cout<<" <- updating";
      }
      std::cout<<std::endl;
    }
   
    AT::Field output;
    bool include = true;
   
    AT::Field line;
    foreach(line, AT::File(config["BANK_OUTPUT"])) {
      if(AT::rx("</script", line)) {
        include = true;
      }
      if(include) {
        output.push(line);
      }
     
      AT::Field key;
      AT::Field user;
      AT::Field server;
     
      (key, user, server) = AT::rx("<script.+data=\"((.+)\\|([^\"]+))\"", line);
      if(key) {
        std::cout<<"found user data section: "<<key<<std::endl;
        AT::Field data;
        data[user] = updates[key]["Bank"];
        output.push(AT::JSON::encode(data));
        include = false;
      }
    }
   
    std::cout<<output<<std::endl;
   
    std::ofstream file;
    file.open(config["MEMBERS_TIMESTAMP"], std::ios::out | std::ios::app);
    if(file.is_open()) {
      file<<time(NULL)<<"\n";
    }
    file.close();
  }
  catch(AT::Field e) {
    return(e);
  }
  catch(...) {
    return("Unknown exception occurred");
  };
 
  return(undef);
}

int main(int argc, char *argv[]) {
  config.expect("INIT", 0);
 
  config.expect("HOSTNAME=s", "127.0.0.1");
  config.expect("USERNAME=s");
  config.expect("PASSWORD=s");
  config.expect("DATABASE=s");
 
  config.expect("GUILD=s");
 
  config.expect("MEMBERS_TIMESTAMP=s", "/tmp/vendortrash.members.timestamp");
  config.expect("MEMBERS_SOURCE=s");
 
  config.expect("BANK_TIMESTAMP=s", "/tmp/vendortrash.bank.timestamp");
  config.expect("BANK_SOURCE=s");
  config.expect("BANK_OUTPUT=s");
 
  config.file("/var/www/vendortrash/sources/wtf.txt");
  AT::Field command, commands = config.cmdln(argc, argv);
 
  std::cout<<"*** "<<config["USERNAME"]<<"@"<<config["HOSTNAME"]<<std::endl;
 
  AT::DB::Interface db(config["HOSTNAME"],
                       config["USERNAME"],
                       config["PASSWORD"],
                       config["DATABASE"]);
 
  try {
    foreach(command, commands) {
      if(command == "members") {
        std::cout<<"*** updating the members listing"<<std::endl;
        AT::Field error = members(db, config["INIT"]);
        if(error.defined()) {
          throw(error);
        }
      }
      if(command == "bank") {
        std::cout<<"*** updating the bank listing"<<std::endl;
        AT::Field error = bank(db, config["INIT"]);
        if(error.defined()) {
          throw(error);
        }
      }
    }
  }
  catch(AT::Field e) {
    std::cout<<"-exception- "<<e<<std::endl;
  }
  catch(...) {
    std::cout<<"-exception-"<<std::endl;
  };

  std::cout<<"-finished-"<<std::endl;
  return 0;
}


Friday, May 04, 2007

This code is for a web site that I am working on that populates a guild member database from a lua source file.  Using asuka made it a trivial matter... oddly enough, it was harder to get this page to format the code below correctly.  Simulated a text box with a div and style tweaks.  I'll probably go back and update the prior code block to be consistent.

#include <asuka.hpp>
#include <iostream>

AT::Configuration config;


//
// Loads a lua datafile...
//
AT::Field load(AT::Field file, AT::Field root) {
  lua_State* state = luaL_newstate();

  luaL_openlibs(state);

  AT::Field contents = AT::Path::open(file);
  contents.push("return ");
  contents.push(root);

  if(luaL_loadstring(state, contents)) {
    throw("failed to load example.lua");
  }
  if(lua_pcall(state, 0, LUA_MULTRET, 0)) {
    throw("script failure");
  }
 
  return(state);
}

//
// Updates the member database
//
AT::Field members(AT::DB::Interface &connection, bool init=false) {
  AT::Field resultset;
 
  AT::DB::Query db(&connection);
 
  try {
    if(init) {
      std::cout<<"*** attempting to initialize the database"<<std::endl;
     
      AT::Field query;
      query.push("CREATE TABLE IF NOT EXISTS vt_guild_members (");
      query.push("userid int(11) NOT NULL default '0',");
      query.push("username varchar(25),");
      query.push("rank varchar(25),");
      query.push("note varchar(256),");
      query.push("class varchar(25),");
      query.push("officernote varchar(256),");
      query.push("level int(11),");
      query.push("status varchar(25),");
      query.push("PRIMARY KEY  (userid));");
     
      resultset = db.exec(query);
    }
   
    //
    // Load the current dataset off disk
    //
    AT::Field state = load("ES_GuildCheck.lua", "ES_GuildCheck_Data");
    AT::Field updates = state.shift();
   
    AT::Field guild;
    foreach(guild, updates.keys()) {
      std::cout<<"entry '"<<guild<<"'";
      if(guild == config["GUILD"]) {
        std::cout<<" <- updating";
      }
      std::cout<<std::endl;
    }
   
    //
    // Load any pre-existing members from the database
    //
    resultset = db.exec("SELECT * FROM vt_guild_members;");
   
    //
    // Brute-force check for new/old members...
    //
    std::cout<<"checking for deletes"<<std::endl;
    AT::Field row;
    foreach(row, resultset) {
      if(!updates[config["GUILD"]]["members"][row["username"]].defined()) {
        std::cout<<row["username"]<<" ... removing"<<std::endl;
      }
    }
   
    std::cout<<"checking for inserts/updates"<<std::endl;
    AT::Field username;
    AT::Field userid = 1000;
    foreach(username, updates[config["GUILD"]]["members"].keys()) {
      std::cout<<username;
      AT::Field user = updates[config["GUILD"]]["members"][username];
     
      AT::Field found;
      foreach(row, resultset) {
        if(row["username"] == username) {
          found = row;
          break;
        }
      }
      if(found.defined()) {
        AT::Field values;
        values[0] = found["userid"];
        values[1] = db.escape(username);
        values[2] = db.escape(user["Rang"]);
        values[3] = db.escape(user["Notiz"]);
        values[4] = db.escape(user["Klasse"]);
        values[5] = db.escape(user["Offiziersnotiz"]);
        values[6] = db.escape(user["Level"]);
       
        std::cout<<"("<<found["userid"]<<")";
       
        AT::Field query;
        query.push("UPDATE vt_guild_members SET ");
        query.push("username='%1',");
        query.push("rank='%2',");
        query.push("note='%3',");
        query.push("class='%4',");
        query.push("officernote='%5',");
        query.push("level=%6");
        query.push("WHERE userid=%0;");
       
        AT::Field temp = db.exec(query, values);
       
        std::cout<<" ... update"<<std::endl;
      }
      else {
        AT::Field values;
        values[0] = ++userid;
        values[1] = db.escape(username);
        values[2] = db.escape(user["Rang"]);
        values[3] = db.escape(user["Notiz"]);
        values[4] = db.escape(user["Klasse"]);
        values[5] = db.escape(user["Offiziersnotiz"]);
        values[6] = db.escape(user["Level"]);
        values[7] = "new";
       
        AT::Field query;
        query.push("INSERT INTO vt_guild_members (");
        query.push("userid,");
        query.push("username,");
        query.push("rank,");
        query.push("note,");
        query.push("class,");
        query.push("officernote,");
        query.push("level,");
        query.push(") VALUES (%0, '%1', '%2', '%3', '%4', '%5', %6, '%7')");
       
        std::cout<<"("<<userid<<")";
       
        AT::Field temp = db.exec(query, values);
       
        std::cout<<" ... added"<<std::endl;
      }
    }
   
  }
  catch(AT::Field e) {
    return(e);
  }
  catch(...) {
    return("Unknown exception occurred");
  };
 
  return(undef);
}

int main(int argc, char *argv[]) {
  config.expect("INIT", 0);
 
  config.expect("HOSTNAME=s", "127.0.0.1");
  config.expect("USERNAME=s");
  config.expect("PASSWORD=s");
  config.expect("DATABASE=s");
 
  config.expect("GUILD=s");
 
  config.file("wtf.txt");
  AT::Field command, commands = config.cmdln(argc, argv);
 
  std::cout<<"*** "<<config["USERNAME"]<<"@"<<config["HOSTNAME"]<<std::endl;
 
  AT::DB::Interface db(config["HOSTNAME"],
                       config["USERNAME"],
                       config["PASSWORD"],
                       config["DATABASE"]);
 
  try {
    foreach(command, commands) {
      if(command == "members") {
        std::cout<<"*** updating the members listing"<<std::endl;
        AT::Field error = members(db, config["INIT"]);
        if(error.defined()) {
          throw(error);
        }
      }
    }
  }
  catch(AT::Field e) {
    std::cout<<"-exception- "<<e<<std::endl;
  }
  catch(...) {
    std::cout<<"-exception-"<<std::endl;
  };

  std::cout<<"-finished-"<<std::endl;
  return 0;
}


Tuesday, May 01, 2007

Recently replaced my server with a virtual host running on vmplayer.  Went with debian etch/stable which is a little unusual for me.  For the last decade I've been using the unstable branch and for the second time during that period I had dependency issues that would require effort to resolve.  Not bad considering that I often do full updates every month or so.  Being able to do a complete system backup with just a simple copy will significantly improve my ability to recover in the case of catastrophy and these days I have little need to be on the bleeding edge.

Sadly even though it's a VM the performance has significantly improved because of the dated hardware I had available to run it on before.  Now it is running on a dual core 1.6ghz laptop that I am using as a media center.  Overall I am pretty pleased.

So with about 4 hours of work I installed and configured the following:
  • debian
  • exim4
  • apache2
  • mysql
  • svn
  • samba
  • ssh
  • gcc/g++
  • scons
  • drupal
  • joomla
  • asuka

Technically most of that time was porting asuka to gcc 4.1, which was a royal pain in the arse.  It wasn't quite as bad as the 2.95 to 3.3.1 port... but close.  Also, did the network setup a bit different this time.  Static IP specified by the host instead of by Mac/DHCP.  That only gave me an issue because I had no clue what DNS I should use and it took a while to find out.  Seems that Open DNS isn't all too popular and prone to attacks/spoofing.  Eventually I found my provider's DNS and it seems to be working like a charm...


Sunday, April 01, 2007

And here are some more sight seeing shots that I took today from another region.

WoWScrnShot_033007_164557
WoWScrnShot_033007_180926
WoWScrnShot_033007_180824



Next 5 >>