<span id="postmessage" style="display:none">Success Message</span>
<form action="http://www.remoteserver.com/upload_test.php" method="post" target="post_to_iframe">
<input type="hidden" value="the text to send to remote server" />
<input type="submit" value="Submit" />
</form>
<!-- When you submit the form it will submit to this iFrame without refreshing the page and it will make the popup and display the message. -->
<iframe name="post_to_iframe" style="width: 600px; height: 500px;"></iframe>
Technology Bits
I am always exploring interesting tidbit in technology. I will keep a blog of my path to discovering new technology.
Friday, March 16, 2012
Send text to remote server using an Iframe
Here is an example to post text to a remote server.
And you can print javascript in the remote server if you want to change the page you have the Iframe on to say something like success. Or a popup saying it finished. On the remote server you can print this to make a popup: <script> parent.document.getElementById('postmessage').style.display='block'; parent.alert('Successfully posted');</script>
On the webpage you want to send information from make a form and Iframe like this.
Sunday, January 22, 2012
Password strength
Recently I joined Lastpass.com for free password management. It is great to have this secure website help keep my passwords safe while using a different password for every site I have registered at. I the past I had used the same password but now they are all 30 characters using letters, numbers and special characters. Here is a sample password that lastpass will generate for you:
z$7cAP%#Ak%r39x!PU5e2Nq1As*2Np
I have changed 35 or so different sites passwords to different passwords and it was simple. Now if one site stores the passwords in plain text and a hacker gets it then I will just change that one password to a different one using lastpass in a minute. And the hacker won't be able to get into any of my other sites.
One thing I liked was how secure you can make lastpass forum for instance. They allow your password to be upto 255 characters. But while I was changing passwords I found something surprising. The only 2 sites that I wasn't able to use my 30 character password on was financial sites. Wellsfargo forces it to be 14 or less and paypal.com forces the password to be 20 or less. How come all the biggest sites on the internet let you use a 30 character password and then where you want a stronger password it has to be half the size? I think they should allow 255 character passwords. It isn't something that should use more computer power to store a longer password. It's just one line of code usually to change the length allowed in login systems.
Saturday, December 10, 2011
Saving includes to a variable
I was reading a forum post and they wanted to save an include to a variable when making new forums on their website. I thought about it and here is what I came up with:
<?php function get_include($path, $cat_id = null){ ob_start(); // start buffer include $path; $content = ob_get_contents(); // assign buffer contents to variable ob_end_clean(); // end buffer and remove buffer contents return $content; } $render = array(); $render[] = "testing1"; $render[] = "testing2"; $category['fid'] = '134'; echo "<pre>"; $render[] = get_include('add_forum.php', $category['fid']); $render[] = get_include('add_forum.php', $category['fid']); print_r($render); ?>and the forum_add.php looks like this:<?php echo "here is your id: $cat_id"; ?>The result looks like:Array ( [0] => testing1 [1] => testing2 [2] => here is your id: 134 [3] => here is your id: 134 )Isn't this a nice way of both saving an include to a file and passing a variable to the include in a function.
Friday, November 25, 2011
Quick install LAMP server on Ubuntu
Here is the site I am going to summarize here: https://help.ubuntu.com/community/ApacheMySQLPHP
I am using Ubuntu 10.10 for this install. It should take 10 minutes or so to follow these steps.
The fastest way to install Appache2, PHP5.3, and MySQL is to use this command:
If you are using 11.04 then tasksel might not be installed. Then use this to install it:
Tasksel will install the Lamp server but won't remove it, but we won't need to remove it.
At this point go to http://localhost and it should say "It works!"
Next use this command to make a new site:
Make a folder in your home folder called webhome or anything you want to put your website in instead of the default var/www because I like to be able to edit the website files from my home so I own them and don't have to use sudo to edit them as root. Edit the DocumentRoot line to point to your new web root: /home/user/webhome/
Change the Directory directive by fixing the path to point to your webhome folder. Instead of <Directory /var/www/> use <Directory /home/user/public_html/>
After saving the file in gedit use these commands to disable the default website and enable the new website.
Next make a index.php file in the webhome folder that says:
You should see the php configuration showing all the php settings.
This was pretty easy. They have streamlined alot of these steps.
I am using Ubuntu 10.10 for this install. It should take 10 minutes or so to follow these steps.
The fastest way to install Appache2, PHP5.3, and MySQL is to use this command:
sudo tasksel install lamp-serverIf you are using 11.04 then tasksel might not be installed. Then use this to install it:
sudo apt-get install taskselTasksel will install the Lamp server but won't remove it, but we won't need to remove it.
At this point go to http://localhost and it should say "It works!"
Next use this command to make a new site:
sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/mysite
gksudo gedit /etc/apache2/sites-available/mysiteMake a folder in your home folder called webhome or anything you want to put your website in instead of the default var/www because I like to be able to edit the website files from my home so I own them and don't have to use sudo to edit them as root. Edit the DocumentRoot line to point to your new web root: /home/user/webhome/
Change the Directory directive by fixing the path to point to your webhome folder. Instead of <Directory /var/www/> use <Directory /home/user/public_html/>
After saving the file in gedit use these commands to disable the default website and enable the new website.
sudo a2dissite default && sudo a2ensite mysite
sudo /etc/init.d/apache2 restartNext make a index.php file in the webhome folder that says:
<?php phpinfo(); ?>
Now go to: http://localhostYou should see the php configuration showing all the php settings.
This was pretty easy. They have streamlined alot of these steps.
Tuesday, November 22, 2011
Idea for making midi or tracker sequencer in html
I would like to make a sequencer in html5. I think its possible and I have been researching how it can be done. The main problem will be making it work in the main browsers and not just 1 or 2. You could make tracker mod music play from firefox by installing vlc and check vlc firefox plug-in when you install it. That works and allows you to add files to the playlist using simple javascript. I made a demo which plays, stops, goes to next track and pauses the music. It works but then the next problem would be how to make the .it or .xm or .mid or .mod file on the fly using the server. Would that be done using a batch command run from php or could it be made using pure php. This would be faster than creating wave or mp3s on the fly and uploading them.
Here is a link to VLC's wiki talking about how to make the embeded object work in firefox and controlling it using js.
http://wiki.videolan.org/Documentation:WebPlugin#Playlist_object
Then I thought this was not really good either since its using old technology and when I refreshed the page it would crash the plugin too. I found a new way to run midi type files in firefox at least and maybe Chrome, Safari or Opera which use webkit.
I found this site:
http://weare.buildingsky.net/processing/audionode.js/examples/index.html
The top example works sort of:
http://weare.buildingsky.net/processing/audionode.js/examples/drum-machine.html
It uses javascript and html5's audio object to create audio from scratch like wave files.
https://wiki.mozilla.org/Audio_Data_API
You tell it what the sample rate is and then feed it all the data in an array. 44100 samples per second is the normal rate. Its the quality of CD's and it seems to work. There is a website I found which converts .midi files to wave channels on the fly in javascript on the client and plays them using firefox.
http://jsspeccy.zxdemo.org
It will take time to learn how to use this to make a cool sequencer program all on the web but it looks like it would be possible. I just need to know how to make sounds either wave files or how to make track files and then convert them to wave files to play in the browser. Its easy to make a simple sine wave but how do you introduce other sounds into the mix?
Here is a link to VLC's wiki talking about how to make the embeded object work in firefox and controlling it using js.
http://wiki.videolan.org/Documentation:WebPlugin#Playlist_object
Then I thought this was not really good either since its using old technology and when I refreshed the page it would crash the plugin too. I found a new way to run midi type files in firefox at least and maybe Chrome, Safari or Opera which use webkit.
I found this site:
http://weare.buildingsky.net/processing/audionode.js/examples/index.html
The top example works sort of:
http://weare.buildingsky.net/processing/audionode.js/examples/drum-machine.html
It uses javascript and html5's audio object to create audio from scratch like wave files.
https://wiki.mozilla.org/Audio_Data_API
You tell it what the sample rate is and then feed it all the data in an array. 44100 samples per second is the normal rate. Its the quality of CD's and it seems to work. There is a website I found which converts .midi files to wave channels on the fly in javascript on the client and plays them using firefox.
http://jsspeccy.zxdemo.org
It will take time to learn how to use this to make a cool sequencer program all on the web but it looks like it would be possible. I just need to know how to make sounds either wave files or how to make track files and then convert them to wave files to play in the browser. Its easy to make a simple sine wave but how do you introduce other sounds into the mix?
Sunday, November 6, 2011
Get amazon ASIN using javascript
I was wondering how this can be done and found a couple answers on:
http://stackoverflow.com/questions/1764605/scrape-asin-from-amazon-url-using-javascript
url = window.location.href;
url.match("/([a-zA-Z0-9]{10})(?:[/?]|$)");
url = window.location.href;
url.match("/([a-zA-Z0-9]{10})(?:[/?]|$)");
Monday, October 31, 2011
Hierarchy in databases for folders
I have been building a folder system that stores files and revisions to these files in the folders. I have now added deleting the folders or files by turning a column isDeleted = 1 or 0 when it is deleted so I can keep them in side until a certain time has gone by before moving them to an old table or delete them.
I am using a PHP class: http://www.php4every1.com/scripts/walker-class/
It was made for a comment system but I converted it to show the folder structure by building an unordered list for each root node and using lots of DIVs and spans with CSS to show the mini folders with plus and minus signs that will hide or unhide the inside list to show or hide a list of folders. This works for many levels. Then I made 2 columns on the right of the tree structure that shows 2 levels of the folders at any point. Then by clicking on any folder in the 2nd column it moves to the first column and shows the files and folders that are in it, in the second column or just a blank folder and file icon to allow you to add new folders and files. I also implemented a right click menu to add or remove files and folders. Then I made the folders and files draggable so we can move them to other folders either in the tree on the left or another folder in one of the 2 columns we navigate in.
Now the problem I have to solve is how to keep them in order when I move a folder to another place. My folder tree walker fails to build the tree when it reads the table from top to bottom because I moved the folder above the point where the parent is so when it tries to find the parent for the child folder I moved it can't find it because the child it mentioned before the parent is listed in the database. I need to make a column that lists the tree in order from the root nodes out to the children. I have to do this because I don't want every person that views the page to have recursively find all the nodes since this won't scale well. I have to redo the order of the folders each time a new folder is added or a folder is moved.
I read an article online: http://www.ferdychristant.com/blog/archive/DOMM-7QJPM7
about a way to make adding a folder easy. It uses a lineage column that lists all the ids from the root to the present like 1-4-8 and when you add a child to 8 you will just add "-9" to the 9th folder in the system that's being placed inside the 8th folder. If I use this method then when I move a folder with many folders inside then I need to rewrite the lineage for each folder recursively using the parent of the folder it is being placed in as the base for the new location the folders are being moved to.
Then I read this article: http://evolt.org/node/4047/
It mentions another way of fixing this by running a stored procedure when you insert a new folder where all folders after it it incremented by 1 id.
This article: http://www.alandelevie.com/2008/07/12/recursion-less-storage-of-hierarchical-data-in-a-relational-database/
talks about other methods of working with this data. I am going to try pulling all the data out of the database using a single select and then build the tree in php and then update the sequence in the database afterward. I can do this each time a folder is moved.
Subscribe to:
Posts (Atom)