Random code snippets

Random but oddly useful code snippets that I use from time to time.

  • To display images as a preview and a clickable link in HTML:
<a href="http://dl.dropbox.com/u/54881717/screenshots/DSL/dsl2.jpg"><img alt="DSL Creeper BG" src="http://dl.dropbox.com/u/54881717/screenshots/DSL/dsl2.jpg" width="400" height="300" /></a>

Width and height need to be manually set.

 

  • Main function for a “do something to every file (including those in subdirectories) within specified folder”, written in bash:
#!/bin/sh

echo "Enter target dir"
read -p ">" workdir
while [ ! -d $workdir ]; do
echo "That directory does not exist. Please enter target dir"
read workdir
done
cd $workdir
for i in $(find -type f -name '*'); do
echo "Ho." > $i
done
Advertisements