Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 26 Nov 2014, 10:06
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Web Programming
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 5 Posts_count   Goto page: 1, 2, 3, 4, 5 Next
Author Message
technosaurus


Joined: 18 May 2008
Posts: 4379

PostPosted: Sun 19 Dec 2010, 17:44    Post_subject:  Web Programming  

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.

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send_private_message 
technosaurus


Joined: 18 May 2008
Posts: 4379

PostPosted: Sun 19 Dec 2010, 17:45    Post_subject:  

Here is a script that will generate an html index of directories and files.
Code:
#!/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

_________________
Web Programming - Pet Packaging 100 & 101

Edited_time_total
Back to top
View user's profile Send_private_message 
trapster


Joined: 28 Nov 2005
Posts: 2027
Location: Maine, USA

PostPosted: Sun 19 Dec 2010, 18:09    Post_subject:  

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

Asus eeepc 1005HA PU1X-BK
Frugal install: Puppeee4.31 + 1.0, Puppy4.10 + Lupu52
Currently using Slacko AND lupu52 w/ fluxbox
Back to top
View user's profile Send_private_message Visit_website 
big_bass

Joined: 13 Aug 2007
Posts: 1747

PostPosted: Sun 19 Dec 2010, 19:46    Post_subject:  

Hey trapster
Quote:
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:

#!/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

_________________
debian wheezy ,linux mint, slackware I use them all and they all have good points
Mint would be best for general users though

Edited_times_total
Back to top
View user's profile Send_private_message 
trapster


Joined: 28 Nov 2005
Posts: 2027
Location: Maine, USA

PostPosted: Sun 19 Dec 2010, 20:04    Post_subject:  

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:
tree -a -H /mnt/home/music > /mnt/home/music/index.html


Works a treat.

_________________
trapster
Maine, USA

Asus eeepc 1005HA PU1X-BK
Frugal install: Puppeee4.31 + 1.0, Puppy4.10 + Lupu52
Currently using Slacko AND lupu52 w/ fluxbox
Back to top
View user's profile Send_private_message Visit_website 
big_bass

Joined: 13 Aug 2007
Posts: 1747

PostPosted: Sun 19 Dec 2010, 20:56    Post_subject:  

Hey technosaurus ,trapster

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



Code:

#!/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


_________________
debian wheezy ,linux mint, slackware I use them all and they all have good points
Mint would be best for general users though
Back to top
View user's profile Send_private_message 
abushcrafter


Joined: 30 Oct 2009
Posts: 1447
Location: England

PostPosted: Sun 19 Dec 2010, 21:05    Post_subject:  

http://www.catb.org/~esr/imgsizer/
Quote:
This tool auto-generates or corrects WIDTH and HEIGHT parameters into HTML IMG tags, making page loading faster.

_________________
adobe flash is rubbish!
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/
Back to top
View user's profile Send_private_message Visit_website 
technosaurus


Joined: 18 May 2008
Posts: 4379

PostPosted: Sun 19 Dec 2010, 21:37    Post_subject:  

Use this to remove spaces:
Code:
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

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send_private_message 
big_bass

Joined: 13 Aug 2007
Posts: 1747

PostPosted: Mon 20 Dec 2010, 12:21    Post_subject:  

Hey technosaurus


I liked the visual output of the generated code you did nice job Cool
It however was difficult to read the source code
I combined my code with yours to have both
the source and the output pretty Very Happy

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:




#!/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



_________________
debian wheezy ,linux mint, slackware I use them all and they all have good points
Mint would be best for general users though

Edited_times_total
Back to top
View user's profile Send_private_message 
technosaurus


Joined: 18 May 2008
Posts: 4379

PostPosted: Mon 20 Dec 2010, 14:27    Post_subject:  

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.
_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send_private_message 
sc0ttman


Joined: 16 Sep 2009
Posts: 2386
Location: UK

PostPosted: Tue 21 Dec 2010, 11:25    Post_subject:  

TechGuruLive.com wrote:
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:
#!/bin/bash
# july 03 2007 – vertito
# this script retrieves data from mysql using bash

dbase=`mysql -uMYSQLUSENAME -pMYSQLPASSWORD -e”use MYDATABASE; select * from MYTABLE where id = 1;”`
for data in $dbase ;
do
echo $data
done

echo Done.

#chmod 700 yourscript.sh
#./yourscript.sh


Works like a charm!

Dont forget to change the following wordings:

MYSQLUSERNAME = your mysql username access with your mysql server
MYSQLPASSWORD = your mysql password
MYDATABASE = your running mysql database name
MYTABLE = your selected table name

_________________
Akita Linux, VLC-GTK, Pup Search, Pup File Search
Back to top
View user's profile Send_private_message 
big_bass

Joined: 13 Aug 2007
Posts: 1747

PostPosted: Wed 22 Dec 2010, 10:49    Post_subject:  

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

_________________
debian wheezy ,linux mint, slackware I use them all and they all have good points
Mint would be best for general users though
Back to top
View user's profile Send_private_message 
big_bass

Joined: 13 Aug 2007
Posts: 1747

PostPosted: Wed 22 Dec 2010, 11:04    Post_subject:  

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 Confused


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

_________________
debian wheezy ,linux mint, slackware I use them all and they all have good points
Mint would be best for general users though
Back to top
View user's profile Send_private_message 
technosaurus


Joined: 18 May 2008
Posts: 4379

PostPosted: Wed 22 Dec 2010, 12:02    Post_subject:  

... 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

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send_private_message 
big_bass

Joined: 13 Aug 2007
Posts: 1747

PostPosted: Wed 22 Dec 2010, 14:21    Post_subject:  

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:

# 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

_________________
debian wheezy ,linux mint, slackware I use them all and they all have good points
Mint would be best for general users though
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 1 of 5 Posts_count   Goto page: 1, 2, 3, 4, 5 Next
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1721s ][ Queries: 13 (0.0729s) ][ GZIP on ]