Light Chaser

May 12th, 2012 by Silabsoft

If you havn’t visted http://gamedev.moparscape.org then you probably don’t know that lately I have been working on an html5 javascript clone of a game I used to have as a child called lights out. The game was rather simple all you had to do was turn off all the lights to progress to the next level. Currently the game is a work in progress and has a few minor bugs (don’t try to turn on all the lights) but it is playable. Please let me know if you find any bugs or just want to make some comments on improvements. Also you can view the source on my github account.

WordPress Runescape Highscore Widget Initial Release

April 24th, 2012 by Silabsoft

After working on the better-github-widget plugin I was inspired to write my own simple widget for WordPress. I choose to make one that would allow me to grab and display My characters Runescape highscore details using JSON.  Everything seems to be working at the moment it has the ability to either show or hide the activity data (mini games) If you have any suggestions to make it better please feel free to leave my a comment.

 

wpp1 Wordpress Runescape Highscore Widget Initial Releasewpp2 Wordpress Runescape Highscore Widget Initial Release

 

The Github: https://github.com/silabsoft/rs-highscore-widget

The WordPress plugin repository: http://wordpress.org/extend/plugins/runescape-highscores-widget/

Simple Runescape highscores json callback output

April 24th, 2012 by Silabsoft

I wrote this for a Runescape highscore plugin I had been working on. It allows me to grab the Runescape lite highscores and output it in a JSON callback format. Special thanks for http://recursive-design.com/blog/2008/03/11/format-json-with-php/ for writing a pretty JSON indent method as the current version of PHP on this web server does not support JSON_PRETTY_PRINT.

<?php
header('Content-type: application/javascript');
$player = isset($_GET['player']) ? $_GET['player'] :"zezima";
$callback = isset($_GET['callback']) ? $_GET['callback'] :"runescape.parseHighscores";
const TOTAL_ACTIVITIES = 38;
const TOTAL_SKILLS = 25;
 
    $name = array("Overall","Attack","Defence","Strength","Constitution","Ranged","Prayer","Magic","Cooking","Woodcutting","Fletching","Fishing","Firemaking","Crafting","Smithing","Mining","Herblore","Agility","Thieving","Slayer","Farming","Runecrafting","Hunter","Construction","Summoning","Dungeoneering","Duel Tournament","Bounty Hunters","Bounty Hunter Rogues","Fist of Guthix","Mobilising Armies","B.A Attackers","B.A Defenders","B.A Collectors","B.A Healers","Castle Wars Games","Conquest","Dominion Tower");
    $url ='http://hiscore.runescape.com/index_lite.ws?player='.$_GET['player'];
    $process = curl_init($url);
    curl_setopt($process, CURLOPT_HEADER, 0);
    curl_setopt($process, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($process,CURLOPT_CONNECTTIMEOUT,1);
    $resp = curl_exec($process);
    $resp = explode("\n", $resp);
    curl_close($process);
    for($i = 0; $i < 38; $i++){
    $s = explode( "," , $resp[$i]);
        $skillData[$i] = $i < TOTAL_SKILLS ? array("id" =>(int)$i,"isSkill" => (boolean)true,"name" => $name[$i],"rank" => (int)$s[0],"level" => (int)$s[1],"experience" => (int)$s[2]) : array("id" =>(int)$i,"isSkill" => (boolean)false,"name" => $name[$i],"rank" => (int)$s[0],"score" => (int)$s[1]);
    }
 
   $data = json_encode($skillData);// because my host sucks and does not use PHP 5.4 so I can't use the FANCY JSON OUTPUT so I have to use the indent method for debugging.
   echo $callback .'({'."\n  ".'"data":'. indent($data).'})';
 
 
 
 
 //Method from: http://recursive-design.com/blog/2008/03/11/format-json-with-php/
 function indent($json) {
 
    $result      = '';
    $pos         = 0;
    $strLen      = strlen($json);
    $indentStr   = '  ';
    $newLine     = "\n";
    $prevChar    = '';
    $outOfQuotes = true;
 
    for ($i=0; $i<=$strLen; $i++) {
 
        // Grab the next character in the string.
        $char = substr($json, $i, 1);
 
        // Are we inside a quoted string?
        if ($char == '"' && $prevChar != '\\') {
            $outOfQuotes = !$outOfQuotes;
 
        // If this character is the end of an element,
        // output a new line and indent the next line.
        } else if(($char == '}' || $char == ']') && $outOfQuotes) {
            $result .= $newLine;
            $pos --;
            for ($j=0; $j<$pos; $j++) {
                $result .= $indentStr;
            }
        }
 
        // Add the character to the result string.
        $result .= $char;
 
        // If the last character was the beginning of an element,
        // output a new line and indent the next line.
        if (($char == ',' || $char == '{' || $char == '[') && $outOfQuotes) {
            $result .= $newLine;
            if ($char == '{' || $char == '[') {
                $pos ++;
            }
 
            for ($j = 0; $j < $pos; $j++) {
                $result .= $indentStr;
            }
        }
 
        $prevChar = $char;
    }
 
    return $result;
}
 
?>

Example output: http://silabsoft.org/rs-web/highscore.php?player=zezima

GitHub:https://github.com/silabsoft/rs-web

A small fix for the better-github-widget plugin

April 18th, 2012 by Silabsoft

This WordPress plugin is an awesome little widget that displays your github projects. It does have two small markup errors that I had to fix to make it pass W3C validation.

 

The two very small problems include:

  1. required attribute “alt” not specified – This is found on the octocat image it has no ALT value which is required to be valid. It’s also good to have in case the image really can’t be found! a simple fix was to just add alt=”github Octocat”
  2. end tag for element “a” which is not open – This one seems to be more like a typo than a bug but its still present in the current release of the plugin.  What I found was that  link was accidentally closed prior to displaying the username text

 

I have reported these two small problems to the authors github and hope he will push a fixed version. However I have also included source with fixes already implemented right here for anyone that needs.

 

<?php
/*
Plugin Name: Better GitHub Widget
Plugin URI: http://github.com/fracek/better-github-widget
Description: Display your GitHub projects
Author: Francesco Ceccon
Version: 0.5
Author URI: http://francesco-cek.com
*/
 
/**
* Adds Foo_Widget widget.
*/
class Better_GitHub_Widget extends WP_Widget {
 
    /**
* PHP 4 constructor
*/
    function Better_GitHub_Widget() {
        Better_GitHub_Widget::__construct();
    }
 
    /**
* PHP 5 constructor
*/
    function __construct() {
        $widget_ops = array('classname' => 'better-gh-widget', 'description' => __('Display your GitHub projects'));
        parent::__construct(
'better-gh-widget', // Base ID
'Better GitHub Widget', // Name
            $widget_ops
);
    }
 
    /**
* Front-end display of widget.
*
* @see WP_Widget::widget()
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
    public function widget( $args, $instance ) {
        extract($args);
        $username = $instance['username'];
        $count = $instance['count'];
        $title = 'GitHub';
 
        echo $before_widget;
        echo $before_title . $title . $after_title;
 
        // Octocat image
        echo '<img width="128px" src="' . plugins_url('octocat.png', __FILE__) . '"';
       echo ' style="display: block; margin: 0px auto;" alt="github Octocat"/>';
 
        // username @ GitHub
        echo '<p style="text-align: center; ">';
        echo '';
        echo $username . ' @ GitHub</p>';
 
        // the list of repos
        echo '<ul id="gh-repos">';
        echo '<li id="gh-loading">Status updating...</li>';
        echo '</ul>';
        echo '<script src="' . plugins_url('github.js', __FILE__) . '" type="text/javascript"> </script>';
?>
<script type="text/javascript">
github.showRepos({
user: '<?php echo $username; ?>',
count: <?php echo $count; ?>,
skip_forks: true,
});
</script>
<?php
        echo $after_widget;
    }
 
    /**
* Sanitize widget form values as they are saved.
*
* @see WP_Widget::update()
*
* @param array $new_instance Values just sent to be saved.
* @param array $old_instance Previously saved values from database.
*
* @return array Updated safe values to be saved.
*/
    public function update( $new_instance, $old_instance ) {
        $instance = array();
        $instance['username'] = strip_tags($new_instance['username']);
        $instance['count'] = strip_tags($new_instance['count']);
 
        return $instance;
    }
 
    /**
* Back-end widget form.
*
* @see WP_Widget::form()
*
* @param array $instance Previously saved values from database.
*/
    public function form( $instance ) {
        // Assigns values
        $instance = wp_parse_args( (array) $instance, array( 'username' => '', 'count' => ''));
        $username = strip_tags($instance['username']);
        $count = strip_tags($instance['count']);
 
        echo '<p><label for="'. $this->get_field_id('username') . '">' . __('Username') . ':';
        echo '<input class="widefat" id="' . $this->get_field_id('username') . '" ';
        echo 'name="' . $this->get_field_name('username') . '" type="text" ';
        echo 'value="' . attribute_escape($username) . '" />';
        echo '</label></p>';
 
        echo '<p><label for="' . $this->get_field_id('count') . '">' . __('Number of projects to show') . ':';
        echo '<input class="widefat" id="' . $this->get_field_id('count') . '" ';
        echo 'name="' . $this->get_field_name('count') . '" type="number" ';
        echo 'value="' . attribute_escape($count) . '" />';
        echo '<br><small>' . __('Set to 0 to display all your projects</small>');
        echo '</label></p>';
    }
 
} // class Foo_Widget
add_action( 'widgets_init', create_function( '', 'register_widget( "better_github_widget" );' ) );
?>

WordPress and XHTML 1.0 Transitional

April 18th, 2012 by Silabsoft

Many people ignore W3C markup validation. I am not one of them, so when I checked if my site was valid only to find that WordPress on a fresh install had an error I was rather annoyed.

The error found: there is no attribute “role”:

You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is often caused by incorrect use of the “Strict” document type with a document that uses frames (e.g. you must use the “Transitional” document type to get the “target” attribute), or by using vendor proprietary extensions such as “marginheight” (this is usually fixed by using CSS to achieve the desired effect instead).

This error may also result if the element itself is not supported in the document type you are using, as an undefined element will have no supported attributes; in this case, see the element-undefined error message for further information.

 

After doing some searching on Google it seems that this problem has been around in WordPress for awhile now. It also seems they are not interested in fixing it. However some people have stated that the easiest way to fix it is to implement your own searchform.php without the role attribute. This is easier said then done as most themes do not modify this file and have no reason to include it in a distribution.  So after doing a little poking around I was able to find what was included in the template file and change it to suite my sites needs

 

<form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
	<div>
		<label class="screen-reader-text" for="s">Search For:</label>
		<input type="text" name="s" id="s" value="Search..." />
		<input type="submit" class="submit" name="submit" id="searchsubmit" value="Search" />
	</div>
</form>

As a result I am now able to proudly display the W3C Valid Icon!

Webfish Angler

April 17th, 2012 by Silabsoft

Some of you may have noticed I changed my wordpress theme to Webfish Angler.  This particular theme sparked my interest as its simple and clean yet stylish enough for my taste.  Installing any theme with wordpress is rather painless. This particular theme had a header and footer image with easy options to turn them off!  If I had to gripe about anything with this theme it would be the lack of a description tag. Normally I wouldn’t notice things like this but recently I have been playing with an addon for firefox called SEO Doctor which displays a green yellow or red flag based on your sites SEO score.  SEO Doctor gave my site a yellow flag as the theme did not include a meta description tag.  To be completely fair this seems to be more of an issue with the standard wordpress rather than the theme developers  as wordpress by default does not give a section for descriptions.  Regardless adding a quick line to the header of the template fixed all the problems and gave the site a green flag.

 

 

<meta name='description' content='Simply put this site is just a pile of Silab'/>

Scala MP3 Sorter

April 15th, 2012 by Silabsoft

So over at MITB all of us cool kids rehashed the same shitty mp3 sorting program in multiple languages. here is mine in SCALA

 

package mp3sorter
import java.io.File;
import java.io.FileInputStream;
object MP3Sort {
 
  /**
   *Simple MP3 sorting application translated from C to C# to Java to Jython to Scala
   *By Silabsoft and all those prior.
   * @param args the command line arguments
   */
  def main(args: Array[String]): Unit = {
    if(args.length &lt; 2){
      println("USAGE: MP3Sort [source] [destination]");
      return;
    }
    val source : File = new File(args(0));
    val destination : File = new File(args(1));
    var mp3List : List[MP3File] = Nil;
    if(!source.isDirectory || !source.canRead){
      println("Please check the source path");
      return;
    }
    for (file  "INVALID"
      }
    };
    def getYearTitle = {
      try{
        year.toInt+" - ";
      }catch{
        case e: Exception =&gt; ""
      }
    }
    def getAlbum = album;
    def getTitle = title;
    def getFileName = title+".mp3";
    def getFile : File = file;
    def isValid = valid;
 
    override def toString = artist + " - " + title + " (" + getYear + ", " + album + ")";   
 
    // could use some more valudation checking but I'm lazy and noone else bothered.'
    def parseTags = {
      try{
        val buffer :Array[Byte] = new Array(128);
        val fis : FileInputStream = new FileInputStream(file);
        fis.skip(this.file.length() - buffer.length);
        fis.read(buffer, 0, buffer.length);
 
        for(i  valid = false;
      }
    };
  }
 
}

MTK6516 tetherxp.inf

March 29th, 2012 by Silabsoft

This is a tetherxp.inf file I modified to make it work with my star-A8000 phone. Basically the tetherxp.inf that google provides does not account for all the android phones available.

The Line I added to the file has the specific VID and PID for my phone. To do this I went to the missing device in my device manager, clicked on its properties and went to details. under details it shows me the information I needed

android MTK6516 tetherxp.inf

; MTK6516 Specifically from my Star-A8000
%AndroidDevice%    = RNDIS, USB\VID_0BB4&amp;PID_0003

The complete INF file:

; MS-Windows driver config matching some basic modes of the
; Linux-USB Ethernet/RNDIS gadget firmware:
;
;  - RNDIS plus CDC Ethernet ... this may be familiar as a DOCSIS
;    cable modem profile, and supports most non-Microsoft USB hosts
;
;  - RNDIS plus CDC Subset ... used by hardware that incapable of
;    full CDC Ethernet support.
;
; Microsoft only directly supports RNDIS drivers, and bundled them into XP.
; The Microsoft "Remote NDIS USB Driver Kit" is currently found at:
;   http://www.microsoft.com/whdc/hwdev/resources/HWservices/rndis.mspx
 
[Version]
Signature           = "$CHICAGO$"
Class               = Net
ClassGUID           = {4d36e972-e325-11ce-bfc1-08002be10318}
Provider            = %Android%
Compatible          = 1
MillenniumPreferred = .ME
DriverVer           = 03/30/2004,0.0.0.0
; catalog file would be used by WHQL
;CatalogFile         = Android.cat
 
[Manufacturer]
%Android%          = AndroidDevices,NT.5.1
 
[AndroidDevices]
; Google Nexus One without adb
%AndroidDevice%    = RNDIS, USB\VID_18D1&amp;PID_4E13
; Google Nexus One with adb
%AndroidDevice%    = RNDIS, USB\VID_18D1&amp;PID_4E14
; Google Nexus S without adb
%AndroidDevice%    = RNDIS, USB\VID_18D1&amp;PID_4E23
; Google Nexus S with adb
%AndroidDevice%    = RNDIS, USB\VID_18D1&amp;PID_4E24
; HTC Sapphire without adb
%AndroidDevice%    = RNDIS, USB\VID_0BB4&amp;PID_0FFE
; HTC Sapphire with adb
%AndroidDevice%    = RNDIS, USB\VID_0BB4&amp;PID_0FFC
; Motorola Sholes without adb
%AndroidDevice%    = RNDIS, USB\VID_22B8&amp;PID_41E4
; Motorola Sholes with adb
%AndroidDevice%    = RNDIS, USB\VID_22B8&amp;PID_41E5
; MTK6516 Specifically from my Star-A8000
%AndroidDevice%    = RNDIS, USB\VID_0BB4&amp;PID_0003
 
[AndroidDevices.NT.5.1]
; Google Nexus One without adb
%AndroidDevice%    = RNDIS.NT.5.1, USB\VID_18D1&amp;PID_4E13
; Google Nexus One with adb
%AndroidDevice%    = RNDIS.NT.5.1, USB\VID_18D1&amp;PID_4E14
; Google Nexus S without adb
%AndroidDevice%    = RNDIS.NT.5.1, USB\VID_18D1&amp;PID_4E23
; Google Nexus S with adb
%AndroidDevice%    = RNDIS.NT.5.1, USB\VID_18D1&amp;PID_4E24
; HTC Sapphire without adb
%AndroidDevice%    = RNDIS.NT.5.1, USB\VID_0BB4&amp;PID_0FFE
; HTC Sapphire with adb
%AndroidDevice%    = RNDIS.NT.5.1, USB\VID_0BB4&amp;PID_0FFC
; Motorola Sholes without adb
%AndroidDevice%    = RNDIS.NT.5.1, USB\VID_22B8&amp;PID_41E4
; Motorola Sholes with adb
%AndroidDevice%    = RNDIS.NT.5.1, USB\VID_22B8&amp;PID_41E5
; MTK6516 Specifically from my Star-A8000
%AndroidDevice%    = RNDIS.NT.5.1, USB\VID_0BB4&amp;PID_0003
[ControlFlags]
ExcludeFromSelect=*
 
; Windows XP specific sections -----------------------------------
 
[RNDIS.NT.5.1]
Characteristics = 0x84   ; NCF_PHYSICAL + NCF_HAS_UI
BusType         = 15
DriverVer           = 03/30/2004,0.0.0.0
AddReg          = RNDIS_AddReg_NT, RNDIS_AddReg_Common
; no copyfiles - the files are already in place
 
[RNDIS.NT.5.1.Services]
AddService      = USB_RNDIS, 2, RNDIS_ServiceInst_51, RNDIS_EventLog
 
[RNDIS_ServiceInst_51]
DisplayName     = %ServiceDisplayName%
ServiceType     = 1
StartType       = 3
ErrorControl    = 1
ServiceBinary   = %12%\usb8023.sys
LoadOrderGroup  = NDIS
AddReg          = RNDIS_WMI_AddReg_51
 
[RNDIS_WMI_AddReg_51]
HKR, , MofImagePath, 0x00020000, "System32\drivers\rndismp.sys"
 
; Windows 2000 and Windows XP common sections --------------------
 
[RNDIS_AddReg_NT]
HKR, Ndi,               Service,        0, "USB_RNDIS"
HKR, Ndi\Interfaces,    UpperRange,     0, "ndis5"
HKR, Ndi\Interfaces,    LowerRange,     0, "ethernet"
 
[RNDIS_EventLog]
AddReg = RNDIS_EventLog_AddReg
 
[RNDIS_EventLog_AddReg]
HKR, , EventMessageFile, 0x00020000, "%%SystemRoot%%\System32\netevent.dll"
HKR, , TypesSupported,   0x00010001, 7
 
; Common Sections -------------------------------------------------
 
[RNDIS_AddReg_Common]
HKR, NDI\params\NetworkAddress, ParamDesc,  0, %NetworkAddress%
HKR, NDI\params\NetworkAddress, type,       0, "edit"
HKR, NDI\params\NetworkAddress, LimitText,  0, "12"
HKR, NDI\params\NetworkAddress, UpperCase,  0, "1"
HKR, NDI\params\NetworkAddress, default,    0, " "
HKR, NDI\params\NetworkAddress, optional,   0, "1"
 
[SourceDisksNames]
1=%SourceDisk%,,1
 
[SourceDisksFiles]
usb8023m.sys=1
rndismpm.sys=1
usb8023w.sys=1
rndismpw.sys=1
usb8023k.sys=1
rndismpk.sys=1
 
[DestinationDirs]
RNDIS_CopyFiles_98    = 10, system32/drivers
RNDIS_CopyFiles_ME    = 10, system32/drivers
RNDIS_CopyFiles_NT    = 12
 
[Strings]
ServiceDisplayName    = "USB Remote NDIS Network Device Driver"
NetworkAddress        = "Network Address"
Android               = "Android"
AndroidDevice         = "Android USB Ethernet/RNDIS"
SourceDisk            = "Ethernet/RNDIS Driver Install Disk"

Welcome back to Silabsoft.org

March 26th, 2012 by Silabsoft

So I decided it was time to bring the site back up, For now its just going to be a simple WordPress blog. I don’t have any major plans for the site at this time other than to post things I find of interest.  If you are looking for Runescape private server related discussions I must suggest you try another website Moparscape Forums as its simply something that does not interest me anymore and I will not be using the domain silabsoft.org for anything Runescape private server related.