« Newer Snippets
Older Snippets »
Showing 41-44 of 44 total

Upload all .gif and .jpg files in a directory to textpattern

This will upload all files in the current directory ending in jpg jpeg or gif through your textpattern-admin panel to your site.

Save this as a shell script, adjust the first 3 variables and excute. (Note: LOGIN and PASS should be ascii only, or else manually url-encoded)

URL='http://www.mysite.com/textpattern/'
LOGIN='simplename'
PASS='yourpassword'

COOKIE=$(curl -s -D - -d "p_userid=$LOGIN&p_password=$PASS" \
    $URL | head -n10 | sed -n 's/^Set\-Cookie\: //p')

if [ -z $COOKIE ] 
then 
  echo "Can't log in."
  exit 1
else 
  echo "Cookie: "$COOKIE
fi


for file in $(ls -1|egrep '(gif)|(jpe?g)$') ; 
do
 echo "Sending "$file
 curl -s -H "Cookie: $COOKIE" -F "thefile=@$file" \
   -F "event=image" -F "step=image_insert" $URL > /dev/null
done


This will not output anything. But after it returns to the prompt, log in to textpattern and take a look into the image section.

Update: Added rudimentary check wether login is successful and basic progress meter.

delete a filename starting with a dash

Have you ever created a file by mistakenly adding a flag where you shouldn't? Find the inode number of the file and delete it using find:

[one:~/src/oops] ryanschwartz$ cp test -p
[one:~/src/oops] ryanschwartz$ ls
-p test
[one:~/src/oops] ryanschwartz$ rm -p
rm: illegal option -- p
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
[one:~/src/oops] ryanschwartz$ \rm -p
rm: illegal option -- p
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
[one:~/src/oops] ryanschwartz$ ls -li
total 0
5937393 -rw-r--r-- 1 ryanschwartz textdrive - 0B May 27 18:04 -p
5937392 -rw-r--r-- 1 ryanschwartz textdrive - 0B May 27 18:04 test
[one:~/src/oops] ryanschwartz$ find . -inum 5937393
./-p
[one:~/src/oops] ryanschwartz$ find . -inum 5937393 -exec rm {} \;
[one:~/src/oops] ryanschwartz$ ls -li
total 0
5937392 -rw-r--r-- 1 ryanschwartz textdrive - 0B May 27 18:04 test

Marten's .zshrc

export PATH=$PATH:/usr/local/bin:/opt/local/bin

# Aliases and functions {{{1

# Xterm resizing-fu. Note that these are utf-8 fonts
alias hide='echo -en "\033]50;nil2\007"'
alias tiny='echo -en "\033]50;-misc-fixed-medium-r-normal--8-80-75-75-c-50-iso10646-1\007"'
alias small='echo -en "\033]50;6x10\007"'
alias default='echo -e "\033]50;-misc-fixed-medium-r-semicondensed--13-*-*-*-*-*-iso10646-1\007"'
alias medium='echo -en "\033]50;-misc-fixed-medium-r-normal--13-120-75-75-c-80-iso10646-1\007"'
alias large='echo -en "\033]50;-misc-fixed-medium-*-*-*-15-*-*-*-*-*-iso10646-1\007"'
# This is a large font that has a corresponding double-width font for 
# CJK and other characters, useful for full-on utf-8 goodness.
alias larger='echo -en "\033]50;-misc-fixed-medium-r-normal--18-*-*-*-*-*-iso10646-1\007"'
alias huge='echo -en "\033]50;-misc-fixed-medium-r-normal--20-200-75-75-c-100-iso10646-1\007"'
alias normal=default
if [ "$TERM" = "xterm" ] && [ "$LINES" -ge 50 ] && [ "$COLUMNS" -ge 100 ]; then
        large
fi

# Allow for use of =command to test for commands below, w/o error messages.
setopt nonomatch

alias df='df -h -x none'
alias free='free -m'
alias cls=clear
# Do we have GNU ls of a new enough version for color?
(ls --help 2>/dev/null |grep -- --color=) >/dev/null && \
        alias ls='ls -b -CF --color=auto'
alias l=ls
alias dir='ls -lha'
alias du='du -h'
alias f=finger
alias edit=$EDITOR
alias e=$EDITOR
alias ftp=lftp
alias md=mkdir
# Put alive hosts at the bottom.
alias ruptime='ruptime -rt'
alias rd=rmdir
alias k=killall
alias mtr='mtr --curses'
[[ -x =reportbug ]] && alias bug='reportbug -b --no-check-available -x -M --mode=expert'
alias slrn='slrn -n'
alias menu=pdmenu
alias xchat='xchat -C'
alias stardate='date "+%y%m.%d/%H%M"'
if [[ -x =ytalk ]]; then
        alias ytalk='ytalk -x'
        alias talk=ytalk
fi
# Finger macros alias.
if [[ -e /proc/acpi ]]; then
        alias apm=acpi
fi
# I don't like the zsh builtin time command.
[[ -x =time ]] && alias time='command time'
alias dch="dch -p -D UNRELEASED"
alias bc='bc -l -q'
alias ytalk='ytalk -x'

# QX3 toy microscope
alias bottomlight="echo bottomlight: on >!/proc/cpia/video0; echo toplight: off >!/proc/cpia/video0"
alias toplight="echo toplight: on >!/proc/cpia/video0; echo bottomlight: ff >!/proc/cpia/video0";
alias nolight="echo toplight: off >!/proc/cpia/video0; echo bottomlight: off >!/proc/cpia/video0"
alias bothlights="echo toplight: on >!/proc/cpia/video0; echo bottomlight: on >!/proc/cpia/video0"

# Longrun stuff.
alias slow='longrun -f economy; longrun -s 0 50; longrun -p'
alias fast='longrun -f performance; longrun -s 0 100; longrun -p'
# useful for games with auto rate limiting
alias full='longrun -f performance; longrun -s 100 100; longrun -p'

# Stuff that I just don't want to run, because it sucks.
alias eview='echo "eview? No"'
# Argh, mf is so bloody annoying.
alias mf='echo "Er, if you want mv, type mv; if you want mf, I pity you."'

# Calculator
calc () { echo $* |bc -l }

# This fingers @host.
@ () { finger @$1 }


# Not for root.
if [[ "$USER" != root ]]; then
        alias cardctl='sudo cardctl'
        alias fetchnews='sudo fetchnews'
fi

# I don't like this for interactive use.
setopt nomatch

# Prompt {{{1

coreprompt="%n@%m"

# The extraprompt thing can be set when I have chroots and I want to keep
# track of which I am in.
if [ ! -e /etc/zsh.extraprompt ]; then
        baseprompt="$coreprompt:%~"
else
        baseprompt="$coreprompt(`cat /etc/zsh.extraprompt`):%~"
fi

# The prompt shows up in xterm titles too.
case $TERM in
   xterm|color_xterm|screen)
        # Beware: next line has embedded raw control characters..
        PROMPT="%{]0;$baseprompt%}$baseprompt> "

        # Before each command is run, throw the command line up into the
        # titlebar! (The only problem is that very quick commands flicker..)
        preexec () {
                print -nP '\033]0;'
                print -nP "$coreprompt: "
                # Truncate at 60 chars, escape %, escape invisibles
                print -nPR "%60>...>${(V)1//\%/%%}"
                print -n '\007'
                # Also set the screen window title to programs I run.
                if [ "$TERM" = screen ]; then
                        print -nP '\033k%'
                        print -nPR "%60>...>${(V)1//\%/%%}"
                        print -n '\033\\'
                fi
        }
        
        # Add to the prompt to unset screen window title after program
        # exits.
        if [ "$TERM" = screen ]; then
                PROMPT="%{kzsh\\%}$PROMPT"
        fi

  ;;
  *) PROMPT="$baseprompt>"
  ;;
esac
unset baseprompt
[[ UID -eq 0 ]] && PROMPT=${PROMPT/\}%n/\}%U%n%u}

# Misc {{{1

limit core 0          # no core dumps
umask 022        # no user groups any more
setopt nopromptcr # No cr before prompt
#setopt extendedglob      # Lots of cool extra wildcards
#setopt mailwarning       # New mail?
setopt correct            # Correct commands
# Note that the following comment makes me cringe now, but is left in for
# historical amusement value.
setopt autolist automenu nobeep     # Filename completion: the best of csh and 4dos!
setopt autocd             # Exec directory to cd there
setopt noclobber noflowcontrol
#setopt autoresume
setopt print_exit_value
setopt list_packed
unsetopt bgnice

# History setup
setopt share_history
setopt csh_junkie_history
setopt hist_ignore_dups
setopt hist_allow_clobber
setopt hist_reduce_blanks

# Force emacs editing mode.
[[ $TERM == "xterm" ]] && bindkey -e

# ctrl-s will no longer freeze the terminal.
#stty -ixon kill ^K
stty erase "^?"

# Work around ion/xterm resize bug.
#if [ "$SHLVL" = 1 ]; then
# if [ -x `which resize 2>/dev/null` ]; then
#         eval `resize 
# fi
#fi

eval `dircolors 2>/dev/null` # set up color-ls variables
watch=(notme)   # watch for everybody but me
LOGCHECK=120    # check every 2 min for login/logout activity

if [ -e ~/.security-environment ]; then
        printf "Current security environment: "
        cat ~/.security-environment
fi

# Turn on full-featured completion (needs 2.1) {{{2
if [[ "$ZSH_VERSION" == (3.1|4)* ]]; then
        autoload -U compinit
        compinit
        if [[ -e ~/.ssh/known_hosts ]]; then
                # Use .ssh/known_hosts for hostnames.
                hosts=(${${${(f)"$(<$HOME/.ssh/known_hosts)"}%%\ *}%%,*})
                zstyle ':completion:*:hosts' hosts $hosts 
        fi
fi
        
# Key bindings {{{1

bindkey '\e[A' history-search-backward
bindkey '\e[B' history-search-forward
bindkey '^K' kill-whole-line
bindkey -s '^L' "|less\n"         # ctrl-L pipes to less
bindkey -s '^B' " &\n"                        # ctrl-B runs it in the background
bindkey "\e[1~" beginning-of-line # Home (console)
bindkey "\e[H" beginning-of-line  # Home (xterm)
bindkey "\e[4~" end-of-line               # End (console)
bindkey "\e[F" end-of-line                # End (xterm)
bindkey "\e[2~" overwrite-mode            # Ins
bindkey "\e[3~" delete-char               # Delete

Generate secure ssh keys

Here's how to get to a quick secure shell login. On your computer (replace all values in CAPS of course):

cd ~
ssh-keygen -t dsa


(just hit return at any prompts, even if it asks for a password). Then:

scp ~/.ssh/id_dsa.pub YOURUSER@YOURSERVER.textdrive.com:~/.ssh/authorized_keys


And put in the password for your account when prompted. Next, add the following to ~/.ssh/config:

Host SOMESHORTCUT
Port 22
User YOURUSER
Hostname YOURSERVER.textdrive.com
KeepAlive yes                                                                   


Restart the local shell, and then whenever you want to login to your server, just type:

ssh SOMESHORTCUT


...and you'll zip right in.
« Newer Snippets
Older Snippets »
Showing 41-44 of 44 total