Welcome

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

What next?
1. Bookmark us with del.icio.us or Digg Us!
2. Subscribe to this site's RSS feed
3. Browse the site.
4. Post your own code snippets to the site!

Compile HTML Tidy on Mac OS X


open http://tidy.sourceforge.net

cd ~/Desktop

curl -L -o tidy.tar.gz 'http://tidy.cvs.sourceforge.net/viewvc/tidy/tidy/?view=tar'

tar -xzf tidy.tar.gz

# 1. 

cd ~/Desktop/tidy/build/gmake

make

ls -l ~/Desktop/tidy/bin/{tab2space,tidy}


# 2.

cd ~/Desktop/tidy/build/gnuauto

touch NEWS README AUTHORS ChangeLog COPYING

autoreconf -fvi

ln -s ~/Desktop/tidy/{console,CVSROOT,experimental,htmldoc,include,lib,src,test} \
          ~/Desktop/tidy/build/gnuauto 2>/dev/null
ln -s ~/Desktop/tidy/include/* ~/Desktop/tidy/build/gnuauto/include 2>/dev/null
ln -s ~/Desktop/tidy/lib/* ~/Desktop/tidy/build/gnuauto/lib 2>/dev/null
ln -s ~/Desktop/tidy/src/* ~/Desktop/tidy/build/gnuauto/src 2>/dev/null
ln -s ~/Desktop/tidy/console/* ~/Desktop/tidy/build/gnuauto/console 2>/dev/null

./configure --prefix=/usr/local

make

ls -1d ~/Desktop/tidy/build/gnuauto/src/.libs/*.dylib

sudo make install

ls -ld /usr/local/bin/{tab2space,tidy} /usr/local/lib/*tidy*.dylib


tidy -h
tidy -v   # 25 March 2009
tidy -help-config | less
tidy -show-config | less
tidy -xml-help | less
tidy -xml-config | less


# cf. http://tidy.sourceforge.net/docs/quickref.html#merge-spans

echo 'merge-spans: yes' >> config.txt
tidy -q -c -config config.txt file.html

# alternative
tidy -q -c --merge-spans yes file.html

Rent A Carr

// description of your code here

// insert code here..
Kiralik
Smile Rent A Car

Compile pty on Mac OS X


man 4 pty  #  pty -- pseudo terminal driver

open http://en.wikipedia.org/wiki/Pseudo_terminal

# Advanced Programming in the UNIX Environment, Second Edition
open http://www.apuebook.com

cd ~/Desktop

curl -L -O http://www.apuebook.com/src.tar.gz

tar -xzf src.tar.gz

cd apue.2e

wkdir="${HOME}/Desktop/apue.2e"

sed -E -i "" "s|^WKDIR=.*|WKDIR=${wkdir}|" ~/Desktop/apue.2e/Make.defines.macos

echo '#undef _POSIX_C_SOURCE' >> ~/Desktop/apue.2e/include/apue.h

str='#include   <sys/select.h>'
printf '%s\n' H 1i "$str" . wq | ed -s calld/loop.c

str='
#undef _POSIX_C_SOURCE
#include <sys/types.h>
'
printf '%s\n' H 1i "$str" . wq | ed -s file/devrdev.c

str='
#include <sys/signal.h>
#include <sys/ioctl.h>
'
printf '%s\n' H 1i "$str" . wq | ed -s termios/winch.c

make

~/Desktop/apue.2e/pty/pty ls -ld *

Backing Up MySQL to remote server via bash

via http://www.sitepoint.com/blogs/2004/04/30/backing-up-mysql/


#!/bin/bash ##################################### ### MySQL Configuration Variables ### ##################################### # MySQL Hostname DBHOST='localhost' # MySQL Username DBUSER='root' # MySQL Password DBPASSWD='password' ##################################### ### FTP Configuration Variables ##### ##################################### # FTP Hostname FTPHOST='www.example.com' # FTP Username FTPUSER='username' # FTP Password FTPPASSWD='password' # Local Directory for Dump Files LOCALDIR=/path/to/local/directory/ # Remote Directory for Offsite Backup REMOTEDIR=/path/to/remote/directory/ # Prefix for offsite .tar file backup TARPREFIX=db1 ##################################### ### Edit Below If Necessary ######### ##################################### cd $LOCALDIR SUFFIX=`eval date +%y%m%d` DBS=`mysql -u$DBUSER -p$DBPASSWD -h$DBHOST -e"show databases"` for DATABASE in $DBS do if [ $DATABASE != "Database" ]; then FILENAME=$SUFFIX-$DATABASE.gz mysqldump -u$DBUSER -p$DBPASSWD -h$DBHOST $DATABASE | gzip --best > $LOCALDIR$FILENAME fi done chmod 400 $LOCALDIR*.gz tar -cf $TARPREFIX-$SUFFIX.tar $SUFFIX-*.gz ftp -n $FTPHOST <


This second script is updated to use mysqlhotcopy and is specifically for use with ISAM/MYISAM tables only. This script below will NOT work with InnoDB tables.

#!/bin/bash ### Configuration Variables DBHOST='localhost' DBUSER='root' DBPASSWD='password' FTPHOST='ftp.example.com' FTPUSER='username' FTPPASSWD='password' LOCALDIR=/path/to/local/ REMOTEDIR=/path/to/local/ TARPREFIX=db1 ### Do not edit anything below this line cd $LOCALDIR SUFFIX=`eval date +%y%m%d` DBS=`mysql -u$DBUSER -p$DBPASSWD -h$DBHOST -e"show databases"` for DATABASE in $DBS do if [ $DATABASE != "Database" ]; then FILENAME=$SUFFIX-$DATABASE.tar.gz mysqlhotcopy -u $DBUSER -p $DBPASSWD $DATABASE $LOCALDIR tar -czf $LOCALDIR$FILENAME $LOCALDIR$DATABASE rm -rf $LOCALDIR$DATABASE rm -rf $LOCALDIR$DATABASE-replicate fi done chmod 400 $LOCALDIR*.tar.gz tar -cf $TARPREFIX-$SUFFIX.tar $SUFFIX-*.tar.gz ftp -n $FTPHOST <

Bash script for mysql db backups

For use in a cron job


#!/bin/sh
DATE=`/bin/date +"%G%m%d"` ;
mysqldump --host=localhost --user=YOURUSER --password=YOURPASSWORD --all-databases --single-transaction --quick | gzip > ./YOURFILEPATH/backup-$DATE.sql.gz ;

ocaml gcd

// description of your code here

let rec calculate_gcd a b =
    match a,b with
      | 0,0 -> failwith "bang"
      | 0,n | n,0 -> n
      | a,b when a < b -> calculate_gcd a (b mod a)
      | a,b when b < a -> calculate_gcd b (a mod b)
      | _ -> a

Log stderr from configure & make


# cf. http://wiki.bash-hackers.org/howto/redirection_tutorial

help command

# swap stdout and stderr stream to log stderr after tee command to log file
function ./configure() { 
   command ./configure "${@}" 3>&2 2>&1 1>&3 3>&- | tee /dev/stderr > stderr_configure.log
   #open -e stderr_configure.log
   return 0
}

function make() { 
   command make "${@}" 3>&2 2>&1 1>&3 3>&- | tee /dev/stderr > stderr_make.log
   #open -e stderr_make.log
   return 0 
}



#-----------------------------------



# log stdout & stderr separately
# See:
# - http://wiki.bash-hackers.org/howto/redirection_tutorial
# - "piping stdout and stderr to different processes?", 
#    http://groups.google.com/group/comp.unix.shell/browse_thread/thread/64206d154894a4ef/
#    ( code by Stephane CHAZELAS )	

unset -f ./configure
function ./configure() { 
   { 
      { 
         command ./configure "${@}" 3>&- | 
            tee stdout_configure.log 2>&3 3>&- 
      } 2>&1 >&4 4>&- | 
         tee  stderr_configure.log 2>&3 3>&- 
   } 3>&2 4>&1 

   return 0 
}


unset -f make
function make() { 
   { 
      { 
         command make "${@}" 3>&- | 
            tee stdout_make.log 2>&3 3>&- 
      } 2>&1 >&4 4>&- | 
         tee  stderr_make.log 2>&3 3>&- 
   } 3>&2 4>&1 

   return 0 
}

Page Bar

// description of your code herecheap cheap shoes

function pageBar($cat_id, $current, $perpage){
    $inCore = cmsCore::getInstance();
    $inDB = cmsDatabase::getInstance();
    $id = $inCore->request('id', 'int');
    global $_LANG;
	$html = '';
	$result = $inDB->query("SELECT id FROM faq WHERE id = $cat_id") ;
	$records = $inDB->num_rows($result);
	if ($records){
		$pages = ceil($records / $perpage);
		if($pages>1){			
			$html .= '<span class="pagebar_title"><strong>'.$_LANG['PAGES'].': </strong></span>';
			for ($p=1; $p<=$pages; $p++){
				if ($p != $current) {			
					$link = '/faq/'.$id.'-'.$p;
					$html .= ' <a href="'.$link.'" class="pagebar_page">'.$p.'</a> ';		
				} else {
					$html .= '<span class="pagebar_current">'.$p.'</span>';
				}
			}
		}
	}
	return $html;
}
true clothing store haight street

save in a base

// description of your code hereb moss clothing store locations

if ($_POST['save_in_base'] && !$warning) {
    foreach ($rules as $k => $v) {
      $name = $v['name'];
      $sql = "INSERT INTO rules (name,arg1,arg2,arg3,url,who_add,cat) VALUES ('$name','".$v[0]."','".$v[1]."','".$v[2]."','".$info['url']."','".$info['user']."','".$info['cat']."')";
      $q = mysql_query($sql) or die($sql.mysql_error());

    }
    echo "<br>save as...<br>";
  }
discount scuba wet suit

Common understanding of the fault phenomena

When the computer fails, the fault detection is the first step to rule out hardware failure is the most important step. Although the causes of computer failures are numerous and diverse, as long as the master relevant skills, identify the causes of failure or rule-based.

Computer repair in the past, we must first clear failure of the specific phenomenon of computer-generated, so as to accuracy, clarity to determine the causes of computer-generated. Computer failure, manifests itself in crashes, blue, black, Huaping, automatic restart, unable to enter the system, unable to enter the self-test state so. Common phenomenon of computer failures at a glance:



(1) Death: My computer crashed a soft one for the common fault, it mainly for the system and all applications are locked, the user can not manipulate their mouse or keyboard, the mouse can not move or even occur, the keyboard can not be Enter phenomenon.

(2) black: black screen mainly for the computer display suddenly shut down, or in the normal state displays no signal input which led to a black screen.

(3) blue: a blue screen computer monitors, and screen sections of the white English prompts. Through the VGP-BPS7 battery computer starts. Shut down or when running certain software, accompanied crash phenomenon.

(4) Huaping: Huaping normally run at startup or when the software program, the general performance for the display of the image disorders, usually accompanied by the phenomenon of Death.

(5) Automatic restart: automatic restart failure usually occurs when running certain programs, the general performance in the implementation of some operations, the system suddenly does not appear abnormal prompt or prompts, automatic re-start the operating system.

(6) The program runs slowly: which generally showed the computer running the program, the response time is unusually slow.

(7) can not boot: Can not boot failure mainly to press the computer's power switch, the computer does not power up start.

(8) keyboard can not enter: Press any key on the keyboard did not respond

(9) can not move the mouse: If the mouse is running in the system, unplug and then plug in from the host, the mouse will appear not to respond to the situation.

In addition to the common of the fault Xianxiangyiwai, the user Aspire 1680 battery process of using Zai Shi Ji, also often involve some 如 network connection status Wei disconnect, press the Xianshi Qi's power Wufadakai display such phenomena, these common fault Yi Ban Dushijiaowei simple computer failures, as long as careful observation, generally very quickly these troubleshooting.