Tuesday, November 23, 2010

Facebook BigPipe is great!

BigPipe has been around for a while in Facebook. I love how the pagelets load all at once so that the first one to get loaded comes first. Also the idea of prolonging the javascript until all page content is loaded it a great idea.
Here is the page about BigPipe:
http://www.facebook.com/notes/facebook-engineering/bigpipe-pipelining-web-pages-for-high-performance/389414033919
I love this idea and may implement it on a site next time I am building a multimedia site. The nice thing is the main parts of the site are loaded very fast and then the rest are loaded with AJAX.

Saturday, October 2, 2010

Javascript is Crazy

I have found out that javascript has some things that you have to be aware of or errors can creep into your code and you wouldn't know why.

I found this page that shows some weirdness of Javascript.
http://www.ozzu.com/programming-forum/javascript-get-array-key-name-t43467.html

There is no real associative array in Javascript. In most languages such as PHP you can do this.
$person = array();
$person['eyes'] = 'blue';
$person['hair'] = 'brown';
$person[1] = 'a number';
echo count($person); //returns 2

$person['length'] = '1 foot';
echo count($person); //returns 3

In Javascript here is what I found out.
You can try the same thing but it won't work right.
One reason is you have to get to Javascript associative arrays by its properties. Normally if you use numbers instead of words in the array keys you can go through the array with a for loop using:
for(x=0;x < person.length;x++){alert(x);}
When you use that with associative arrays it will show a length of 0 in the array. But you can loop through the array using for(x in person){alert(x);}

Here is the example for Javascript:
person = new Array();
person[0] = 'a number';
person['eyes'] = 'blue';
person['hair'] = 'brown';

alert(person.length); //returns 1 It only sees the associative array
alert(person.toString());

person['length'] = 99;
alert(person.length); //returns 99 this is the weird part
alert(person.hair); // returns brown

And if you use a string like 'one foot' for the length is will create an error since it is only expecting a number here. The length property is set by using x = new Array(99); and this is for making the array resized so if you made 3 items in the array then set the array to a size of 2 with:
x['length'] = 2;
You will notice that you won't be able to get at the 3rd array since the length has been truncated.

To go through the array above in Javascript you need to use the
for(x in person){
alert(x);
}

This is the way to get at the associative properties of the array.

Friday, July 9, 2010

Getting MySQL data into XML easily

I have been experimenting with XML lately and have found a great article for using XSLT to make an html table using an sql query from a database.
http://blog.mclaughlinsoftware.com/2008/08/29/querying-oracle-directly-from-xml/
It will use some of the instructions from this blog post:
download Xalan and unzip it to C:/xalan-j_2_7_1
http://xml.apache.org/xalan-j/downloads.html
Then download the mysql J connector:
Go into the zip and take it out and put it in the xalan folder
Mine was put here:
C:/xalan-j_2_7_1/mysql-connector-java-5.1.13-bin.jar
Next make an xsl file and name it mysql.xsl and put this in it:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sql="org.apache.xalan.lib.sql.XConnection"
extension-element-prefixes="sql">
<xsl:output method="html" />
<xsl:template match="/">
<xsl:variable
name="movies"
select="sql:new('com.mysql.jdbc.Driver','jdbc:mysql:///storedb','student','student')" />
<xsl:variable name="streaming" select="sql:disableStreamingMode($movies)" />
<xsl:variable
name="queryResults"
select="sql:query($movies,'SELECT i.item_title, i.item_asin, i.item_release_date FROM storedb.item i')" />
<html>
<head><title>MySQL Result Set</title></head>
<body style="font-family: sans-serif;">
<table border="1" cellpadding="5">
<tr>
<xsl:for-each select="$queryResults/sql/metadata/column-header">
<th><xsl:value-of select="@column-label" /></th>
</xsl:for-each>
</tr>
<xsl:apply-templates select="$queryResults/sql/row-set/row" />
</table>
</body>
</html>
<xsl:value-of select="sql:close($movies)" />
</xsl:template>
<xsl:template match="row">
<tr><xsl:apply-templates select="col" /></tr>
</xsl:template>
<xsl:template match="col">
<td><xsl:value-of select="text()" /></td>
</xsl:template>
</xsl:stylesheet>

Next run these commands from command prompt:
set CLASSPATH=%CLASSPATH%;C:\xalan-j_2_7_1\xalan.jar;.
set CLASSPATH=%CLASSPATH%;C:\xalan-j_2_7_1\serializer.jar
set CLASSPATH=%CLASSPATH%;C:\xalan-j_2_7_1\xercesImpl.jar
set CLASSPATH=%CLASSPATH%;C:\xalan-j_2_7_1\xml-apis.jar
set CLASSPATH=%CLASSPATH%;C:\xalan-j_2_7_1\xsltc.jar
set CLASSPATH=%CLASSPATH%;C:\xalan-j_2_7_1\mysql-connector-java-5.1.13-bin.jar
java org.apache.xalan.xslt.Process -XSL mysql.xsl > mysql.html
Now you should have an html document called mysql.html all ready to look at in a browser with the database tables showing in html format.
I will show an example:

item_titleitem_asinitem_release_date
"Good Eats with Alton Brown, Vol. 6 (3 - Pack): Tossed Around, Veggie Eats, Breakfast Eats 2"143499
"Good Eats with Alton Brown Vol. 8, Delicious Dishes (3 - Pack): Condiment Nation, Ocean Edibles 2, Veggie Eats 2"143510
Sports Medicine Imaging DVD: Single User477044
Musculoskeletal MRI DVD: Single User477087

Wednesday, July 7, 2010

Converting html codes to html entities

I found this helpful site to convert the html entities like < into &lt;
http://centricle.com/tools/html-entities/

And then url encode / decoding is good too:
http://meyerweb.com/eric/tools/dencoder/

XSLT and iTunes parsing into HTML table

I will now show some code that I have been tweaking from a site:

It wasn't working so I had to play with it some until I understood how it works. XSLT is powerful when it comes to converting xml to any format you want.
I will show the example xslt style document I changed from the site above to make really cool looking iTunes tables showing all your music sorted by genre and the times and sizes of each.

First download the Xalan

Find your itunes xml document in My Music folder in My Documents for your current user then open the iTunes folder and copy the iTunes Music Library.xml to your xalan folder and rename it to itunes.xml

Here is where mines was found:
C:\Documents and Settings\mike\My Documents\My Music\iTunes

Now make an itunes.xsl file and put this in it:


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:key name="songsByAlbum" match="dict"
use="string[preceding-sibling::key[1]='Album']"/>

<xsl:key name="songsByGenre" match="dict"
use="string[preceding-sibling::key[1]='Genre']"/>


<xsl:template match="/plist/dict/dict">
<html>
<style>
table,th,td{border:1px solid black;padding:3px;}
th{text-align:left;background-color:#3333CC;}
.indent{border:0px;width:10px;}
.genre{background-color:#7094FF;}
.album{background-color:#3366FF;color: #222}
</style>
<body>
<table>
<tr><th colspan="2">Genre / Album</th><th>Artist</th><th>Time</th><th>Size</th></tr>
<xsl:for-each select="dict[generate-id(.)=
generate-id(key('songsByGenre',string)[1])]">
<xsl:sort select="string[preceding-sibling::key[1]='Genre']"/>
<xsl:for-each select="key('songsByGenre',string)[1]">

<xsl:call-template name="albumsInGenre">
<xsl:with-param name="genre"
select="string[preceding-sibling::key[1]='Genre']"/>
</xsl:call-template>



</xsl:for-each>
</xsl:for-each>

</table>
</body>
</html>
</xsl:template>


<xsl:template name="albumsInGenre">
<xsl:param name="genre"/>

<tr><td class="genre" colspan='5'><b><xsl:value-of select="$genre"/></b></td></tr>

<xsl:variable name="song" select="/plist/dict/dict/dict"/>
<xsl:for-each select="$song[generate-id(.)=
generate-id(key('songsByAlbum',string[preceding-sibling::key[1]='Album'])[1])]">
<xsl:sort select="string[preceding-sibling::key[1]='Album']"/>
<xsl:for-each select="key('songsByAlbum',string[preceding-sibling::key[1]='Album'])
[string[preceding-sibling::key[1]='Genre']=$genre][1]">
<tr>
<td class="indent"> </td>
<td class="album" align='left'><xsl:call-template name="albumName"/></td>
<td class="album" align='left'><xsl:call-template name="artistName"/></td>
<td class="album" align='right'><xsl:call-template name="iTunesTimeAlbum"/></td>
<td class="album" align='right'><xsl:call-template name="iTunesSizeTotal"/></td>
</tr>
</xsl:for-each>
</xsl:for-each>
</xsl:template>

<xsl:template name="albumName">
<xsl:value-of select="string[preceding-sibling::key[1]='Album']"/>
</xsl:template>

<xsl:template name="artistName">
<xsl:choose>
<xsl:when test="true[preceding-sibling::key[1]='Compilation']">
<i>Compilation</i>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="string[preceding-sibling::key[1]='Artist']"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="iTunesTimeAlbum">
<xsl:variable name="tracksInAlbum"
select="key('songsByAlbum',string[preceding-sibling::key[1]='Album'])"/>
<xsl:variable name="t"
select="sum($tracksInAlbum/integer[preceding-sibling::key[1]='Total Time'])"/>
<xsl:call-template name="formatTime">
<xsl:with-param name="t" select="$t"/>
</xsl:call-template>
</xsl:template>

<xsl:template name="formatTime">
<xsl:param name="t"/>
<xsl:if test="$t != 0">
<xsl:variable name="h" select="floor(($t div (1000*60*60)))"/>
<xsl:variable name="m" select="floor(($t div (1000*60)) mod 60)"/>
<xsl:variable name="s" select="floor(($t div 1000) mod 60)"/>
<xsl:if test="$h != 0"><xsl:value-of select="$h"/>:</xsl:if>
<xsl:value-of select="format-number($m,'00')"/>:<xsl:value-of select="format-number($s,'00')"/>
</xsl:if>
</xsl:template>

<xsl:template name="iTunesSizeTotal">
<xsl:variable name="tracksInAlbum"
select="key('songsByAlbum',string[preceding-sibling::key[1]='Album'])"/>
<xsl:variable name="s"
select="sum($tracksInAlbum/integer[preceding-sibling::key[1]='Size'])"/>
<xsl:value-of select="format-number($s div (1000*1000),'00.00')"/>MB
</xsl:template>

<xsl:template name="formatSize">
<xsl:param name="s"/>
<xsl:if test="$s != 0">
<xsl:value-of select="floor($s)"/>GB
</xsl:if>
</xsl:template>

<xsl:template name="iTunesSizeTotalorig">
<xsl:variable name="s" select="sum(dict/integer[preceding-sibling::key[1]='Size'])"/>
<xsl:value-of select="floor($s div (1000*1000))"/>MB
</xsl:template>

</xsl:stylesheet>



Now you just open command prompt and paste this into it:
set CLASSPATH=C:\JavaDev\Java5\ojdbc5.jar;.
set CLASSPATH=%CLASSPATH%;C:\xalan-j_2_7_1\xalan.jar;.
set CLASSPATH=%CLASSPATH%;C:\xalan-j_2_7_1\serializer.jar
set CLASSPATH=%CLASSPATH%;C:\xalan-j_2_7_1\xercesImpl.jar
set CLASSPATH=%CLASSPATH%;C:\xalan-j_2_7_1\xml-apis.jar
set CLASSPATH=%CLASSPATH%;C:\xalan-j_2_7_1\xsltc.jar

Next paste this line:
java org.apache.xalan.xslt.Process -IN itunes.xml -XSL itunes.xsl -HTML > itunes.html

Now after pressing enter you should have an html file in the xalan folder and it will be formated like this:

Genre / AlbumArtistTimeSize
General Classical
Bibbidi Bobbidi BachScott Tennant07:3107.22MB
Soundtrack
Les Miserables 10th Anniversary Concert Disc 11995 Royal Albert Hall Concert Cast03:1503.12MB
Les Miserables 10th Anniversary Concert Disc 21995 Royal Albert Hall Concert Cast03:0903.02MB

Isn't that cool? You could also use the path to the itunes xml file in the xalan if you like what you see and then it will just convert to html what ever you have now.
This works for me too if you are in the xalan folder or where ever you have your itunes.xsl file and where you want your itenues.html to be written or you may change those as well:
java org.apache.xalan.xslt.Process -IN "C:\Documents and Settings\mike\My Documents\My Music\iTunes\iTunes Music Library.xml" -XSL itunes.xsl -HTML > itunes.html

learning XSLT and xml to csv to Oracle or MySQL

I have been learning some XSLT
Here is a good place to start learning how to use it to convert xml to html.
This is the page on W3 schools teaching about the for-each loop that lets you loop through the xml code then you can select the xml elements you want to grab.

You can also convert xml to csv and then to a database if you want. Here is a good tutorial on how to do this:

Also if you want to take a csv file and put it into a MySQL database this is what you do:
DROP TABLE IF EXISTS movie;
CREATE TABLE movie ( role VARCHAR(30) , actor VARCHAR(30) , movie VARCHAR(60)) engine=memory;

TRUNCATE movie;
LOAD DATA LOCAL INFILE 'path_to_csv/movie.csv'
INTO TABLE movie
FIELDS TERMINATED BY '\t'
ESCAPED BY '\\'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES;

The csv is taken into the table with the load data local infile command.
Drop table will drop the table so you can create it again next time you use this command so it is a re-runnable script.
Truncate just removes all data in the table. The Oracle script on blog.mclaughlinsoftware.com uses an external table which makes it so when you read from the table movie you are really reading from the csv file so when ever you change the csv the data in the database is automatically changed when you read from it next. Like:
SELECT * FROM movie;





Monday, June 28, 2010

Making sounds or notes with internal speakers

If you have qbasic you can try this:
http://www.youtube.com/watch?v=hITypVqHWjk
here is the code that will play a song.

PLAY "T120 << e8e8f8g8g8f8e8d8c8c8d8e8e8d12d4"
PLAY "e8e8f8g8g8fe8d8c8c8d8e8d8c12c4"
PLAY "d8d8e8c8d8e12f12e8c8d8e12f12e8d8c8d8P8"
PLAY "e8e8f8g8g8fe8d8c8c8d8e8d8c12c4"

The T120 is the tempo and the << means go down 2 octaves

Then I also got my internal pc speakers to play different tones with this python code:
import winsound
winsound.Beep(337, 200);
winsound.Beep(437, 200);
winsound.Beep(537, 200);
winsound.Beep(637, 200);
winsound.Beep(737, 200);
winsound.Beep(937, 200);
winsound.Beep(637, 200);
winsound.Beep(337, 200);

although it is not as music sounding. But I may try making it sound better later.
The first parameter of the winsound.Beep is the frequency and the second is the length of the note.

Saturday, June 26, 2010

mod re-write is awsome

I think I found how to make multiple mod re-write rules in one htaccess file
you just write the regular expression line
then do another afterward
and if it doesn't match the first it tries the second line.
then I was wondering if you could use this to make it so that no one can visit a certain page such as your js or css folder without being redirected to somewhere else.

Monday, June 21, 2010

foo

command line posting

Sunday, June 20, 2010

blog

I just posted this from GoogleCL!
I hope they keep improving this service

WOW GoogleCL

I can now edit my google docs from the commandline in Windows!
This is great. I got a list of my contacts to the screen easily. Now I am going to try editing a google docs document.
to install google CL go here
then download gdata-2.0.10.tar.gz
Now uncommpress these files to 2 different folders then to install you have to install python.
I already had it installed.

Now go to:
C:\googlecl\gdata-2.0.10
run this command from that folder
python setup.py install

Now go to C:\googlecl\googlecl-0.9.5
and do this command as well
python setup.py install

Now go to C:\googlecl\googlecl-0.9.5\src
and run this:
python google

Now you should get a
>
now type

contacts list name,email

Now it will ask you for your email for google.
It should open your browser for you now you type in your password.
Next press enter and that is it. Soon it will print all the contact info for you.

All the info you need is here for more commands

type help and you get:
Welcome to the Google CL tool!
Commands are broken into several parts: service, task, options, and arguments.
The available services are 'picasa', 'blogger', 'youtube', 'docs', 'contacts', 'calendar'

docs command options are
Did not recognize task, please use one of ['edit', 'delete', 'list', 'upload', 'get']

test post from BloggerClientTest

Hey look, another test!

test from python BloggerTest

This is only a test.

Friday, May 28, 2010

I have found a great way to use excel for user defined functions

I have found a great site that tells how to make a grade lookup in excel without using arrays.
It uses virtual lookups:
'Define a single dimension array of a UDT (record)  
Dim VirtualLookup(1 To 15) As VirtualLookup    
' Record initialization  
VirtualLookup(1).lowerLimit = 0.93  
VirtualLookup(1).upperLimit = 1#  
VirtualLookup(1).letterGrade = "A"

Then you can get and use the values in the lookups like you would with a vlookup in excel.
In a for loop you do this to make the grade = to the vlookup
grade = VirtualLookup(i).letterGrade
I have also been learning how to make arrays in vba in excel

Tuesday, May 18, 2010

Online Radio for free

I created my own online streaming radio station that allows people to listen to your music as you stream it. So everyone that listens will hear the same thing at the same time. I did this with Windows XP but linux would be even better to use.
I installed Icecast2 which is the program that shows you the radio stations that you are streaming. Make sure to look at the settings first by clicking edit configuration in the configuration menu. Next click the start server button. You can see your music streams by going to for example http://localhost:8000
But once you set up your own VPN or website you can use that ip address to allow anyone to listen. But if you are listening to copyrighted music make sure it requires a password so only you can listen to it. I will add a post sometime about how I got my own website built using dyndns.org for free and can host the website from my own laptop or any other computer using a dynamic ip address.

After I installed Icecast2 I looked on their website and found 3rd party client that will read a playlist of mp3's or ogg file and send them to the Icecast2 service which sends them on to the listeners. I picked Ezstream for the client. All you have to do is make a m3u playlist with a program like VLC. I added as many songs as I wanted to the VLC player then clicked playlist menu and then save playlist to file. I put this file in the Ezstream folder. I also edited the ezstream_mp3.xml file in the example folder and moved it into the root of Ezstream folder instead of the example folder. Next add Ezstream to environment path so you don't have to travel to that folder while in CMD. Then type the command:
ezstream -c ezstream_mp3.xml
This will start the streaming if you did everything right. Then just go to the localhost:8000 address to see all your streams. Click the m3u link to the right to download the m3u playlist that you can open with VLC or any other music player. It will start playing the stream. It took me about 3-4 hours to get everything to work. It would have taken less time if I knew what I was doing.
After getting it to work on localhost I made it work onn my VPN and it works. I also added another xml file for Ezstream that pointed to a different m3u playlist so when someone goes to your port 8000 address page they will see both streams. But you have to have 2 command prompt windows open and do the ezstream -c command using both of your xml files one in each of the cmd windows.

What will I try in the future? I want to use mysql and php with this type of streaming to allow uses to login to a website and they can look through the music that is available and pick music to be qued up next on the radio station. When there is no music qued it will pick a random genre and play the music in that genre for 1 hour and then pick another genre. Too many music stations I know of play a small amount of songs and repeat songs all day. I would want songs to repeat once a week so it doesn't get boring to listen to all day.

MySQL table is full error for InnoDB

I was playing with importing data from csv into a table that is only in memory with InnoDB and it came up with an error:
"table is full"
There was 107,000 records added and it stopped before finishing the import.

-- here is the sql code that I used to make the table
SELECT 'ITEM_IMPORT' AS "Drop Table";
DROP TABLE IF EXISTS item_import;
-- ------------------------------------------------------------------
-- Create ITEM_IMPORT table.
-- ------------------------------------------------------------------
SELECT 'ITEM_IMPORT' AS "Create Table";
CREATE TABLE item_import
( item_barcode CHAR(14) NOT NULL
, item_type INT UNSIGNED NOT NULL
, item_title CHAR(60) NOT NULL
, item_subtitle CHAR(60)
, item_rating CHAR(8) NOT NULL
, item_release_date DATE NOT NULL
, screen_type INT UNSIGNED DEFAULT NULL
) ENGINE=memory;

-- loads the csv into the temporary table
LOAD DATA LOCAL INFILE 'C:/Documents and settings/mike/Desktop/datawarehousing/import.csv'
INTO TABLE item_import
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\r\n';

to fix the limit on the amount of rows in the InnoDB table change or add the following line to the my.ini if you are using windows:
max_heap_table_size = 600M
I tested this and it enabled me to add 4 million rows in the table. Since it is a table in memory it removed the tables data as soon as you exit mysql.

Friday, May 14, 2010

Cool new trick to use to stop system beep

My computer is a Dell inspiron 1521 and the system beep it makes when ever I make an error while typing commands in MySQL are so loud it startles me. I wanted to stop the beeps so I googled it and found this page or here. Hope it helps. All you need to do is use a -b in the mysql sartup command like this:
C:\Documents and Settings\mike>mysql -uuser -ppassword -b
now you can type a bad command and it won't beep at all. Another method to use to stop it until you restart the computer is:
net stop beep
the beeps will now be off.
then use:
net start beep
and the beep starts up again.
If you want it to stop for good then use this line:
sc config beep start= disabled
then use
sc config beep start= auto
to turn it back on

Tuesday, May 11, 2010

Some cool things I may write more about

on newegg 1TB drive is $70 free shipping now

7Gbps wireless coming in ayear or so using the 60Ghz band instead of 5


2TB sd cards coming

connectify allows you to make your computer into a wifi access point but it requires Windows 7
the address to download: http://www.connectify.me/

inSSIDer
is a tool that scans your area and shows all the radios in your area and the channel they use
here is an image of it
great tool for seeing every ones mac address and the security of all the access points











Sunday, February 21, 2010

More Secure Passwords

One thing I have seen alot of among other computer savy friends and most of the people I know is they all use the same user name and password when they sign up for new website accounts. No one wants to have to remember more than one account password. And if we did use more than one password we would just add a number or increment the number by one. This is because humans have a hard time remembering more than one thing at a time when it is something they do all the time. I have found a website I am going to try that will let you type one password and it will make new random passwords for sites without making you remember them. Once you log in to the site that remembers your passwords it will let you log into many of your favorite sites quickly and no one will be able to unlock all your passwords from these sites. It is nice because the more sites you log into the more likely you are to run into one that is storing you password in plain text and someone might figure it out and unlock your other sites.
Here it is:
http://www.passpack.com