Web Programming

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

Web Programming

#1 Post by technosaurus »

I intentionally did not specify html programming in the topic, since web programming can take several forms.

Please post your web programming tip, tricks or questions here.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#2 Post by technosaurus »

Here is a script that will generate an html index of directories and files.

Code: Select all

#!/bin/sh
# $1 is a directory to index as html
cd $1;
for x in *; do [ -d "$x" ] && D=$D"<li><a href=\"$x/\">$x/</a></li>" || F=$F"<li><a href=\"$x\">$x</a></li>"; done
echo "<html><head><title>index of $1</title></head><body><p><b>index of $1</b></p><p>directories:</p><ul><li><a href=\"../\">[parent directory]</a></li>$D</ul><p>files:</p><ul>$F</ul></body></html>" >$1/index.html
there is a C version of this script here:
http://www.mathopd.org/dist/dir_cgi.c.txt
Last edited by technosaurus on Mon 20 Dec 2010, 01:50, edited 1 time in total.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
trapster
Posts: 2117
Joined: Mon 28 Nov 2005, 23:14
Location: Maine, USA
Contact:

#3 Post by trapster »

Not working well with spaces in file names.
trapster
Maine, USA

Asus eeepc 1005HA PU1X-BK
Frugal install: Slacko
Currently using full install: DebianDog

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#4 Post by big_bass »

Hey trapster
Not working well with spaces in file names.


this will auto fix /heal all folders and files with spaces or symbols and convert them to underscore "_"

just place it in the folder with the bad names and run it


all is automatic

Joe

Code: Select all

#!/bin/bash

# Joe Arose version 1.05  
# sana_auto  =  auto find and repair 
# sana =  sanitize  these =;:"`<>,!@#$?%^*&(){}[]
# sana =  sana sana colita de rana   "for the spanish translation" 
# drag N drop rename files that have been badly named 
# to a corrected format with underscores 
# many bad characters get deleted  
# programs will not function correctly with spaces placed in the name 
# note that permissions are preseved !


rm -f /tmp/sanitized
rm -f /tmp/borked_name
rm -f /tmp/fix_borked_names.txt


#this is faster fix directories first later it will fix the files 


find $pwd -type d | tr " " "?" | tr  '=;"`<>,!@#$?%^*&(){}[]' '?'| grep '?' >>/tmp/fix_borked_names.txt

#so you have a list of changed files that have ???
cp /tmp/fix_borked_names.txt /tmp/fix_borked_names_dir$$


##special function to clean everything 

for pkg in `cat /tmp/fix_borked_names.txt` ;do
echo "$pkg" | tr -d '=;`"<>,?!@#$%^*&(){}[]' |tr -s ' ' '_*' >/tmp/sanitized
echo "$pkg" | tr " " "?" | tr  '=;"`<>,!@#$?%^*&(){}[]' '?' >/tmp/borked_name


rename_bork=`cat /tmp/borked_name`
echo  "$rename_bork"


for_cleaned=`cat /tmp/sanitized`
echo "$for_cleaned"

mv $rename_bork $for_cleaned 



 Xdialog --title "working on directories" \
        	--infobox "\nConversion to $for_cleaned has finished.\n" 0 0 1000

done 


 Xdialog --title "Complete" \
        	--infobox "\n Auto conversion folders  finished.\n" 0 0 3000

#-----------------------------
#  fix all the files now
#----------------------------

rm -f /tmp/sanitized
rm -f /tmp/borked_name
rm -f /tmp/fix_borked_names.txt


find $pwd -type f | tr " " "?" | tr  '=;"`<>,!@#$?%^*&(){}[]' '?'| grep '?' >>/tmp/fix_borked_names.txt


#so you have a list of changed files that have ???
cp /tmp/fix_borked_names.txt /tmp/fix_borked_names_files$$


##special function to clean everything 


for pkg in `cat /tmp/fix_borked_names.txt` ;do
echo "$pkg" | tr -d '=;`"<>,?!@#$%^*&(){}[]' |tr -s ' ' '_*' >/tmp/sanitized
echo "$pkg" | tr " " "?" | tr  '=;"`<>,!@#$?%^*&(){}[]' '?' >/tmp/borked_name





rename_bork=`cat /tmp/borked_name`
echo  "$rename_bork"


for_cleaned=`cat /tmp/sanitized`
echo "$for_cleaned"

mv $rename_bork $for_cleaned 



 Xdialog --title "working on files" \
        	--infobox "\nConversion to $for_cleaned has finished.\n" 0 0 1000

done 


 Xdialog --title "Complete" \
        	--infobox "\n Auto conversion files  finished.\n" 0 0 3000
Last edited by big_bass on Tue 21 Dec 2010, 04:33, edited 2 times in total.

User avatar
trapster
Posts: 2117
Joined: Mon 28 Nov 2005, 23:14
Location: Maine, USA
Contact:

#5 Post by trapster »

big_bass -
Thanks for the offer and I will save this for future use but I have 6,000 songs + movies already running on my server and I don't want to mess with the filenames.

I do use "tree" to create an html file index.
ie:

Code: Select all

tree -a -H /mnt/home/music > /mnt/home/music/index.html
Works a treat.
trapster
Maine, USA

Asus eeepc 1005HA PU1X-BK
Frugal install: Slacko
Currently using full install: DebianDog

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#6 Post by big_bass »

Hey technosaurus ,trapster

well here is a real simple basic index maker and easy to edit
for anyone to hack at


Code: Select all

#!/bin/sh

#code from Joe Arose big_bass built for special use
# generate a custom index
# drag N drop a folder on the script

#with the end goal of easily making the correct formatting
#simple and clean
#as just the URL's then generate a new index

#/root/new_index_list  #this is the index generated




#---------------index maker--------------------------------
echo '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
 <head>
  <title>Index of </title>
 </head>
 <body>
<h1>Index of  new_index_list</h1>
<pre><img src="/usr/local/lib/X11/pixmaps/archive48.png" alt="Icon "> <a href="?C=N;O=D">Name</a>' >/root/new_index_list



for i in `find "$@"/*`
do echo "<"a href="$i"">"$i"<"/a">" >>/root/new_index_list
done

echo '<hr></pre>
<address>Apache Server at distro.ibiblio.org Port 80</address>
</body></html>' >>/root/new_index_list

#you can edit this if you have seamonkey 
#gtkmoz /root/new_index_list 
/usr/lib/firefox/firefox /root/new_index_list 


User avatar
abushcrafter
Posts: 1418
Joined: Fri 30 Oct 2009, 16:57
Location: England
Contact:

#7 Post by abushcrafter »

http://www.catb.org/~esr/imgsizer/
This tool auto-generates or corrects WIDTH and HEIGHT parameters into HTML IMG tags, making page loading faster.
[url=http://www.adobe.com/flashplatform/]adobe flash is rubbish![/url]
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#8 Post by technosaurus »

Use this to remove spaces:

Code: Select all

for x in *; do X="`echo $x|tr ' ' '_'`";[ "$x" != "$X" ] && mv "$x" "$X"; done
I used * to fix the initial version too - so it should allow spaces when I repost it
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#9 Post by big_bass »

Hey technosaurus


I liked the visual output of the generated code you did nice job 8)
It however was difficult to read the source code
I combined my code with yours to have both
the source and the output pretty :D

thanks for starting this thread
and posting your code

Joe

*this takes more lines of course but the byte count is still very low
EDIT filter for files so folder isnt made for directories also

Code: Select all




#!/bin/sh

# drag N drop html index maker
# "$@" is a directory to index as html
# technosaurus author
# big_bass improved generated source code readability
 
cd "$@"

#---------------------
# clean up old debugging files
#---------------------
rm -f "@"/index.html
rm -f /tmp/flist2
rm -f /tmp/dlist2

#---------------------
# generate the directory and file index
#---------------------
for x in *
 do [ -d "$x" ] &&  echo "<li><a href=\"$x/\">$x/</a></li>" >> /tmp/dlist2
  ! [ -d "$x" ] && echo "<li><a href=\"$x\">$x</a></li>"  >>/tmp/flist2
 done
 
#---------------------
# Head  make the html head 
#---------------------
echo "<html><head><title>index of "$@"
</title></head><body><p><b>index of "$@"</b>
</p><p>directories:</p>
<ul><li><a href=\"../\">[parent directory]</a>">"$@"/index.html

#---------------------
# Body append the dynamic info  for the index here the (directories )
#---------------------
echo "</li>" >>"$@"/index.html
cat /tmp/dlist2>>"$@"/index.html
echo "</ul>">>"$@"/index.html

#---------------------
# Body  append the dynamic info  for the index here the (files )
#---------------------
echo "<p>files:</p><ul>" >>"$@"/index.html
cat /tmp/flist2 >>"$@"/index.html
echo "</ul>" >>"$@"/index.html



#---------------------
#Close the html header
#---------------------
echo "</body></html>" >>"$@"/index.html


# remove new debugging files
#rm -f /tmp/flist2
#rm -f /tmp/dlist2


Last edited by big_bass on Mon 20 Dec 2010, 19:33, edited 4 times in total.

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#10 Post by technosaurus »

Normally I would do the same, but wanted the code to be as fast as possible in case it's used as a cgi script - thus only one loop, one check and one echo... but I could probably add some return characters and/or backslashes for readability without affecting the speed.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
sc0ttman
Posts: 2812
Joined: Wed 16 Sep 2009, 05:44
Location: UK

#11 Post by sc0ttman »

[quote="TechGuruLive.com"]Besides from using perl scripts, phpmyadmin and customized php pages, here is a quick way to fetch data from mysql database using shell script.

Just make sure you are currently running mysql from your box with existing database and table inside.

First, launch your favorite linux editor and create a bash script and paste the following bash codes inside and save.

Code: Select all

#!/bin/bash
# july 03 2007 – vertito
# this script retrieves data from mysql using bash

dbase=`mysql -uMYSQLUSENAME -pMYSQLPASSWORD -e
[b][url=https://bit.ly/2KjtxoD]Pkg[/url], [url=https://bit.ly/2U6dzxV]mdsh[/url], [url=https://bit.ly/2G49OE8]Woofy[/url], [url=http://goo.gl/bzBU1]Akita[/url], [url=http://goo.gl/SO5ug]VLC-GTK[/url], [url=https://tiny.cc/c2hnfz]Search[/url][/b]

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#12 Post by big_bass »

having code examples are great when they can be recycled

what is worth more than any code snippet in itself
is the educational value it has

if you can learn something from the code it is useful


In my opinion
good documentation is worth more than the original work itself
because it invites creativity and growth

Joe

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#13 Post by big_bass »

Hey technosaurus


I recycled the code some more to take a plain text file as input
I dont have direct access to the folder /files on the server to dragndrop the file to build the index


I had earlier written my own indexing for my packages
I was happy with it but the rendering of the page was slow
due to the images and so I decided to go simple and clean
and re do it

*I had written a way to auto generate package sizes and the dates
but that only works when you have all the files on your box :?


if you (or any one else )see(s) something you would change / improve let me know




if you take a look at the link http://www.puppy2.org/slaxer/
here is a simple new index waiting on improvements

thanks
Joe

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#14 Post by technosaurus »

... good idea for adding file size

need to change this:
F=$F"<li><a href=\"$x\">$x</a></li>"; done

to something like this:
F=$F"<li><a href=\"$x\">$x</a> `du $x` kb</li>"; done
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#15 Post by big_bass »

I just made two strings
$datemodified
$size

here is only an example I dont use the echoes
and the package is "x"
just wanted to post a stand alone snippet

awk is nice to get exactly what you want from the output
and this also displays in MB or KB automatically

Code: Select all

# use any package for a test 
package="/root/qemu-0.91-launchscript-SDL-1.29-i486-3_SLXR.txz"


datemodified=`ls -lh "$package" | awk '{ print $6 }'`
size=`ls -lh "$package" | awk '{ print $5 }'` 

echo $datemodified
echo $size
Joe

User avatar
abushcrafter
Posts: 1418
Joined: Fri 30 Oct 2009, 16:57
Location: England
Contact:

#16 Post by abushcrafter »

Code: Select all

#!/bin/sh

# Version=0.0.4

# drag N drop html index maker
# "$@" is a directory to index as html
# technosaurus author
# big_bass improved generated source code readability
# abushcrafter: Improved output HTML.
# abushcrafter: Fixed delete existing "index.html".
# abushcrafter: Added size and modified date code by big_bass.
 
cd "$@"

#---------------------
# clean up old debugging files
#---------------------
rm -f "$@"/index.html
rm -f /tmp/flist2
rm -f /tmp/dlist2

#---------------------
# generate the directory and file index
#---------------------
for x in *
 do [ -d "$x" ] &&  echo "            <li><a href=\"$x/\">$x/</a></li>" >> /tmp/dlist2
  ! [ -d "$x" ] && echo "            <li><a href=\"$x\">$x</a> ,`ls -lh \"$x\" | awk '{ print $5 }'`KB, Date Modified=`ls -lh \"$x\" | awk '{ print $6 }'`</li>"  >>/tmp/flist2
 done
 
#---------------------
# Head  make the html head
#---------------------
echo "<html>
    <head>
        <title>Index Of: "$@"</title>
    </head>
    <body>
        <h1>Index Of "$@"</h1>
        <h2>Directories:</h2>
        <ul>
            <li><strong><a href=\"../\">[Parent Directory]</a></strong></li>">"$@"/index.html

#---------------------
# Body append the dynamic info  for the index here the (directories )
#---------------------
cat /tmp/dlist2>>"$@"/index.html
echo "        </ul>">>"$@"/index.html

#---------------------
# Body  append the dynamic info  for the index here the (files )
#---------------------
echo "        <h2>Files:</h2>
        <ul>" >>"$@"/index.html
cat /tmp/flist2 >>"$@"/index.html
echo "        </ul>" >>"$@"/index.html



#---------------------
#Close the html header
#---------------------
echo "    </body>
</html>" >>"$@"/index.html


# remove new debugging files
#rm -f /tmp/flist2
#rm -f /tmp/dlist2 
[url=http://www.adobe.com/flashplatform/]adobe flash is rubbish![/url]
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#17 Post by technosaurus »

My sprite generator is here:
http://murga-linux.com/puppy/viewtopic.php?t=82009

here is an example that slices the output into 24x24 icons

Code: Select all

<style>
.img{height:24;width:24;float:left;padding:0 0 0 0;display:block;background:url(sprite.png)}
.a{background-position:0-24}
.b{background-position:0-48}
.c{background-position:0-72}
</style>

<div class="img"></div>
<div class="img a"></div>
<div class="img b"></div>
<div class="img c"></div>
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#18 Post by technosaurus »

How to localize web pages.

include this in you're page

Code: Select all

<html><head><title>Localized page</title>
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body>
<div id="string1">  This is the default text of string 1.  </div>
<div id="string2">  This is the default text of string 2.  </div>
</body></html>
<script>
function UrlExists(url){	var http=new XMLHttpRequest()
	try{http.open('HEAD', url, false);http.send()return http.status!=404
	}catch(e){return false}
}

function setLang(data){		var term
	for (var i=0;i<data.items.length;i++){
		term=document.getElementById(data.items[i].id)
		if (term) term.innerHTML=data.items[i].value
	}
}

var lang=navigator.userLanguage || navigator.language.toLowerCase()
if(UrlExists(lang+".js")){	var script=document.createElement("script")
	script.src=lang+".js?callback=setLang";
	document.body.appendChild(script)
}

</script>
then for each supported language, set up a file such as en-us.js

Code: Select all

setLang({"items":[
{"id" : "string1","value" : " Localized text of string1. "},
 {"id" : "string2", "value" : " Localized text of string2. "}
]});
This file goes in the same directory as your page and can be shared by all pages in that directory (with modifications it could do multiple directories or sites or only one file, but I didn't want to complicate it)
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#19 Post by technosaurus »

here is the start of puppy's /usr/share/doc/index.html:

I made 2 sections so far: the intro and legal, to do the translation for es-es, just copy en-us.js to es-es.js and modify each of the "value" values ("id" and its value is not translated)

if you have set your language and it still isn't working, find this line:
var lang=navigator.userLanguage || navigator.language.toLowerCase();
and after it add
alert(lang);
you will get a message telling you what your language is, the language file should be the contents of that message (should be lower case) with a .js extension
Attachments
doc.zip
(5.27 KiB) Downloaded 909 times
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Web Programming

#20 Post by L18L »

technosaurus wrote:...
if you have set your language and it still isn't working, find this line:
var lang=navigator.userLanguage || navigator.language.toLowerCase();
and after it add
alert(lang);
you will get a message telling you what your language is, the language file should be the contents of that message (should be lower case) with a .js extension
In seamonkey it is the language of the languagepack.
If not installed it is en-us of course, no dependency of locale setting.
de-de.js wrote:setLang(
{"id":"intro","value":"<br>Hi, ich bin Barry Kauler, der original developer of the Puppy Operating System,................
function UrlExists(url){ var http=new XMLHttpRequest()
needs a web server, ?
Attachments
tweb.png
start of puppy's /usr/share/doc/index.html
no translation (yet)
(18.05 KiB) Downloaded 1363 times

Post Reply