Never been to CodeSnippets before?

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!)

Compile & install git on Mac OS X

Requires Xcode.

export PATH=/usr/local/bin:/usr/local/sbin:/usr/local/lib:/usr/local/include:/usr/bin:/bin:/usr/sbin:/sbin
export IFS=$' \t\n'


# rudix
# http://rudix.org

cd ~/Desktop
curl -L -O http://downloads.sourceforge.net/rudix/rudix-1.5.2-0.dmg
hdiutil mount ~/Desktop/rudix-1.5.2-0.dmg
ls -1 /Volumes/* | egrep -i rudix
open -a Installer /Volumes/rudix/rudix.pkg
hdiutil unmount /Volumes/rudix

which rudix
man rudix


# expat
# also available via http://rudix.org

cd ~/Desktop
curl -L -O http://downloads.sourceforge.net/expat/expat-2.0.1.tar.gz
tar -xvzf expat-2.0.1.tar.gz 
cd expat-2.0.1
./configure --prefix=/usr/local
make
make check
sudo make install

find /usr/local -iname "*expat*"


# Python 2.5.2

cd ~/Desktop
curl -L -O http://downloads.sourceforge.net/rudix/python-2.5.2-1.dmg
hdiutil mount ~/Desktop/python-2.5.2-1.dmg
sudo rudix -i /Volumes/python/python.pkg
hdiutil unmount /Volumes/python

which python
python -V     # Python 2.5.2


# python-docs

cd ~/Desktop
curl -L -O http://downloads.sourceforge.net/rudix/python-docs-2.5.2-1.dmg
hdiutil mount ~/Desktop/python-docs-2.5.2-1.dmg
sudo rudix -i /Volumes/python-docs/python-docs.pkg
hdiutil unmount /Volumes/python-docs

man /usr/local/share/man/man1/python.1
ls -1 /usr/local/share/doc/python/*
find /usr/local/share/doc/python -mindepth 1 -maxdepth 1
find /usr/local/share/doc/python/doc -mindepth 1 -maxdepth 1
find /usr/local/share/doc/python/mac -mindepth 1 -maxdepth 1


# asciidoc
# asciidoc 8.3.0 requires Python 2.4 or newer

cd ~/Desktop
curl -L -O http://www.methods.co.nz/asciidoc/asciidoc-8.3.0.tar.gz
tar -xvzf asciidoc-8.3.0.tar.gz
cd asciidoc-8.3.0
open -e ~/Desktop/asciidoc-8.3.0/INSTALL
sudo ./install.sh

which asciidoc
man asciidoc


# GPG

cd ~/Desktop
curl -L -O http://downloads.sourceforge.net/rudix/gnupg-1.4.9-2.dmg
hdiutil mount ~/Desktop/gnupg-1.4.9-2.dmg
sudo rudix -i /Volumes/gnupg/gnupg.pkg
hdiutil unmount /Volumes/gnupg

which gpg
gpg --version
man gpg



# GetText

cd ~/Desktop
curl -L -O http://downloads.sourceforge.net/rudix/gettext-0.17-1.dmg
hdiutil mount ~/Desktop/gettext-0.17-1.dmg
sudo rudix -i /Volumes/gettext/gettext.pkg
hdiutil unmount /Volumes/gettext

which gettext
gettext --version
man gettext
open /usr/local/share/locale




# git 
# http://rudix.org

cd ~/Desktop
curl -L -O http://downloads.sourceforge.net/rudix/git-1.5.6.2-1.dmg
hdiutil mount ~/Desktop/git-1.5.6.2-1.dmg
sudo rudix -i /Volumes/git/git.pkg
hdiutil unmount /Volumes/git

which git
git --version
man git

sudo rudix -r git.pkg



# git
# http://git.or.cz

cd ~/Desktop
curl -L -O http://kernel.org/pub/software/scm/git/git-1.6.0.4.tar.gz
tar -xzf git-1.6.0.4.tar.gz
cd git-1.6.0.4
./configure
make
sudo make install

which git
git --version


# git man pages

cd ~/Desktop
curl -L -O http://kernel.org/pub/software/scm/git/git-manpages-1.6.0.4.tar.gz
sudo tar -C /usr/local/share/man -xzf git-manpages-1.6.0.4.tar.gz


git --help

git help add
git help bisect
git help shell
git help git-svn
git help git-daemon


cd ~/Desktop
mkdir -p ~/Desktop/git-test
cd ~/Desktop/git-test
openport 9418   # cf. http://codesnippets.joyent.com/posts/show/1747
git clone git://git.kernel.org/pub/scm/git/git.git
closeport 9418
open ~/Desktop/git-test
find ~/Desktop/git-test/git -mindepth 1 -maxdepth 1 -ls


# To configure git see:
# - http://dysinger.net/2007/12/30/installing-git-on-mac-os-x-105-leopard/
# - http://git.or.cz/gitwiki/GitTips


References:

- Git - Fast Version Control System
- Wikipedia: Git
- Rudix
- Install git on Mac OS X 10.4 (expat, asciidoc)
- Installing GIT on Mac OS X 10.5 Leopard (GPG, GetText)
- Compiling Git and git-svn on OSX Tiger (git-svn, Perl)
- git-osx-installer
- GitTips
- Git User's Manual
- Tag: git
- Git Quick Reference
- Git Guide
- Git Internals: Source code control and beyond
- The Git Community Book
- Setting up Git on OSX
- Git and Binaries
- Git cheat sheet
- Setting up a new remote git repository
- Sharing git repositories via OS X's built-in web sharing
- GitHub Tips: Removing a Remote Branch
- Using git in the Finder
- GitX - a git GUI for Mac OS X

prevent script execution upload directories php shtml

// description of your code here

<Directory "/Library/MediaWiki/web/images">
   # Ignore .htaccess files
   AllowOverride None
 
   # Serve HTML as plaintext, don't execute SHTML
   AddType text/plain .html .htm .shtml
 
   # Don't run arbitrary PHP code.
   php_admin_flag engine off
 
   # If you've other scripting languages, disable them too.
</Directory>

md5 compute compare files

// description of your code here

md5sum <filename>

recursive find grep

// description of your code here

printf junk avoids problems with single quotes in results returned by find

find . -name "*.txt" -printf '"%p"\n' | xargs grep some_pattern


This example will show path+file but not matching lines.
find . -name "*.php" -printf '"%p"\n' | xargs grep "http://rst.void.ru" | cut -d: -f1


make a script of it and place it in .bashrc
deepfind () { echo "Searching for $1"; find . -type f -printf '"%p"\n' | xargs grep "$1" | cut -d: -f1;}

postfix mail queue watch monitor outgoing email

// description of your code here

postcat

The postcat command displays the content of a message in a mail queue.

To read a message in a mail queue, you need its queue ID. Run mailq for a list of queue IDs. For example, the queue ID of the following message is F2B9715C0B3:

After obtaining a queue ID, use it as an option to postcat to see the contents of the queue file:

mailq
F2B9715C0B3 2464 Mon Oct 13 15:29:39 markus.herrmann@example.com
            (connect to mail.example.com[217.6.113.151]: Connection timed out)
            torsten.hecke@example.net
-- 2 Kbytes in 1 Requests.

postcat -q F2B9715C0B3


Delete all mail in queue
postsuper -d ALL

ubuntu linux date time set update adjust

// description of your code here

date mmddHHMMYYyy

so
date 121520152005
Dec 15 8:15 2005

kill linux process

// description of your code here

find process id first via

ps -alx | grep <string>


then kill it with

kill <PID>


or kill stubborn processes with

kill -9 <PID>

argument list too long rm delete in directory

// description of your code here

find . -maxdepth 1 -name '*.jpg' -exec rm {} \;

Compiling GNU sed 4.1.4 on Mac OS X

path='
/usr/local/bin 
/usr/local/sbin
/usr/local/lib
/usr/local/include
/usr/local/man
/usr/bin
/bin
/usr/sbin
/sbin
'

path="$(printf "%s" "${path// /}" | /usr/bin/tr '\n' ':' | /usr/bin/sed -E 's/^:|:$//g')"

printf "%s\n" "$path" | tr ':' '\n'

export PATH="${path}"


cd ~/Desktop

curl -L -O http://ftp.gnu.org/gnu/sed/sed-4.1.4.tar.gz
cd ~/Desktop/sed-4.1.4

# cf. Compiling GNU coreutils on Mac OS X, 
# http://codesnippets.joyent.com/posts/show/1799
./configure --prefix=/usr/local/gnucoreutils
  
make

/usr/bin/sudo /usr/bin/make install



ls -l /usr/local/gnucoreutils/bin/sed
/usr/local/gnucoreutils/bin/sed --version
man /usr/local/gnucoreutils/man/man1/sed.1

/usr/bin/sudo /bin/ln -is /usr/local/gnucoreutils/bin/sed /usr/local/bin/gnused

# use GNU sed with case insensitive option
echo Tool | sed 's/[Tt]/c/'
echo Tool | gnused 's/t/c/i'


# cf. "Extract title from HTML web page" on http://bosetsu.org/pub/docs/shell_cheatsheet.html
curl -L -s http://codesnippets.joyent.com/posts/show/1835 | \
     gnused -n 's/.*<[tT][iI][tT][lL][eE]>\(.*\)<\/[tT][iI][tT][lL][eE]>.*/\1/p;T;q'

# cf. http://www.pixelbeat.org/cmdline.html
curl -L -s http://codesnippets.joyent.com/posts/show/1835 | \
     gnused -n 's/.*<title>\(.*\)<\/title>.*/\1/ip;T;q'

.bashrc v2008-10-31

.bashrc file

# mb, v2008-10-31
# navi
alias ll="ls -l"
alias la="ls -la"
alias lx="ls -CF"
alias u="cd .."
alias back="cd $OLDPWD"

# misc
alias du1="du -sk .[A-z]* *|sort -n" # better du
alias off="logout;exit" 
alias rm_x="rm * .[A-z]* ._*" # also remove hidden files ...
alias ebr="pico ~/.bashrc" # quick edit of .bashrc
alias p="ps xa | grep " 
alias topc="top -o cpu"
alias mud5="telnet 9.63.227.146 3000" # 3kingdoms