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!

Top Tags Alphabetically

actionscript (18)
administration (31)
ajax (25)
apache (34)
applescript (15)
backup (12)
bash (62)
cli (23)
css (44)
delphi (21)
dns (15)
dom (17)
effect (12)
email (19)
expressionengine (25)
fastcgi (14)
find (11)
flash (17)
freebsd (12)
html (41)
image (23)
java (15)
javascript (103)
js (11)
lighttpd (46)
linux (53)
mac (55)
mysql (60)
osx (108)
perl (19)
php (107)
prototype (15)
python (20)
rails (125)
recipe (16)
regex (26)
ruby (128)
rubyonrails (19)
shell (104)
sql (32)
ssh (45)
subversion (24)
svn (35)
sysadmin (14)
terminal (27)
textdrive (15)
textpattern (17)
tiger (11)
ubuntu (13)
unix (43)

« Newer Snippets
Older Snippets »
983 total  XML / RSS feed 

activate root in ubuntu after install

After this you can run su.

sudo passwd root

rename many files at once

This is where the bash variable handling makes it even more interesting. Instead of just doing something like "mv $var", we can replace text in the filename using this syntax:

${var/originaltext/replacetext}


So now, if we run this command on our directory:

for f in *;do mv $f ${f/test/prod};done

Subversion Configuration Script for Your Rails Application

// Configure SVN for your rails app.

#!/bin/sh
svn remove log/*
svn commit -m"removing log files" 
svn propset svn:ignore "*.log" log/
svn update log/
svn commit -m 'Ignoring all files in /log/ ending in .log'
svn move config/database.yml config/database.example
svn commit -m 'Moving database.yml to database.example to provide a template for anyone who checks out the code'
svn propset svn:ignore "database.yml" config/
svn update config/
svn commit -m 'Ignoring database.yml'
svn remove tmp/*
svn propset svn:ignore "*" tmp/
svn update tmp/
svn commit -m "ignore tmp/ content from now" 
svn propset svn:ignore ".htaccess" config/
svn update config/
svn commit -m 'Ignoring .htaccess'
svn propset svn:ignore "dispatch.fcgi" config/
svn update config/
svn commit -m 'Ignoring dispatch.fcgi'

Groovy XML Schema Validator

// Create a Schema and a sample document, then validate the document against the schema

def xsd = '''




'''

def xml = '''


'''

import javax.xml.XMLConstants
import javax.xml.transform.stream.StreamSource
import javax.xml.validation.SchemaFactory

def factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
def schema = factory.newSchema(new StreamSource(new StringReader(xsd)))
def validator = schema.newValidator()
validator.validate(new StreamSource(new StringReader(xml)))

Groovy XML Schema Validator

// Create a Schema and a sample document, then validate the document against the schema

def xsd = '''




'''

def xml = '''


'''

import javax.xml.XMLConstants
import javax.xml.transform.stream.StreamSource
import javax.xml.validation.SchemaFactory

def factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
def schema = factory.newSchema(new StreamSource(new StringReader(xsd)))
def validator = schema.newValidator()
validator.validate(new StreamSource(new StringReader(xml)))

Help!

I would like to know how to create a parsing using the class HTTP Connection, I have to get the data from / ip-do-server/cgi-bin/mailgraph.cgi and switch to
Another page in PHP.


// description of your code here

// insert code here..

ssh-copy-id for automated pubkey append

// it's simple to add one key but this helps when i'm on a machine w/ multiple authorized hosts
// use like `ssh-copy-id ww1.example.com` -- make sure you have `ssh-agent` running and have added keys w/ `ssh-add` (use `ssh-add -L` to check)
// got this from the OpenSSH in Ubuntu, don't have it on mac afaik?

#!/bin/sh

# Shell script to install your public key on a remote machine
# Takes the remote machine name as an argument.
# Obviously, the remote machine must accept password authentication,
# or one of the other keys in your ssh-agent, for this to work.

ID_FILE="${HOME}/.ssh/id_rsa.pub"

if [ "-i" = "$1" ]; then
  shift
  # check if we have 2 parameters left, if so the first is the new ID file
  if [ -n "$2" ]; then
    if expr "$1" : ".*\.pub" >/dev/null; then
      ID_FILE="$1"
    else
      ID_FILE="$1.pub"
    fi
    shift         # and this should leave $1 as the target name
  fi
else
  if [ x$SSH_AUTH_SOCK != x ] && ssh-add -L >/dev/null 2>&1; then
    GET_ID="$GET_ID ssh-add -L"
  fi
fi

if [ -z "`eval $GET_ID`" ] && [ -r "${ID_FILE}" ] ; then
  GET_ID="cat ${ID_FILE}"
fi

if [ -z "`eval $GET_ID`" ]; then
  echo "$0: ERROR: No identities found" >&2
  exit 1
fi

if [ "$#" -lt 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
  echo "Usage: $0 [-i [identity_file]] [user@]machine" >&2
  exit 1
fi

{ eval "$GET_ID" ; } | ssh $1 "umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys" || exit 1

cat <<EOF
Now try logging into the machine, with "ssh '$1'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

EOF

Add missing empty directories in .svn

Fix errors like
svn: Your .svn/text-base directory may be missing or corrupt; run 'svn cleanup' and try again
svn: Can't open file 'blabla/.svn/text-base/entries': No such file or directory

require 'pathname'

def recurse(dir)
  for child in dir.children
    next unless child.directory?              # ignore files
    next if child.basename.to_s == '.svn'     # ignore .svn directory
    next unless (child + '.svn').exist?       # ignore unadded directories
    text_base_dir = child + '.svn/text-base'  # path to text-base dir
    next if text_base_dir.exist?              # ignore existing text-base dirs
    text_base_dir.mkdir
    puts text_base_dir
    recurse child
  end
end

recurse Pathname.new('.')

moving subversion server to another machine

dump the repository to a text file
svnadmin dump repositoryPath > repository.dumpfile


create the new repository on the new machine
cd /path/to/new-repository-parent-directory
svnadmin create repository-name
svnadmin load repository-name < repository.dumpfile


transfer your local svn project to the new machine. Use absolute paths!
svn switch --relocate oldurl newurl


Example:

svn switch --relocate http://myoldcrapserver.com/svn/myfunkyproj svn+ssh://mykickingnewserver.com/var/svn/myfunkyproj

Tomcat connector for lighttpd:

To connect Tomcat to lighttpd use the following code:



server.modules  += ( "mod_proxy_backend_ajp13" )
$HTTP["url"] =~ "^/tomcat/" {
  proxy-core.balancer = "round-robin"
  proxy-core.protocol = "ajp13"
  proxy-core.backends = ( "localhost:8009" )
  proxy-core.max-pool-size = 16
}
« Newer Snippets
Older Snippets »
983 total  XML / RSS feed