Never been to TextSnippets 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!)

About this user

Joel Dueck http://jdueck.net

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

Quick Links in Texter

Some examples of spiffy shortcuts for hyperlinks using Texter:

// hotstring = replacement text

aref  = <a href="%c">%|   // a quick html link with clipboard contents, and placing the cursor between the opening/closing tags)

bbref = [url=%c]%|[/url]      // same thing for bbcode

tref = "%|":%#8221;           // same thing for textile



TxtSnippets doesn't seem to know how to format that but you get the idea.

Complete backup of all domains to strongspace

#!/usr/local/bin/bash
# 
# comprehensive TextDrive backup to Strongspace
# Joel Dueck (http://jdueck.net)
#
# This script will backup all websites in your TextDrive account to Strongspace.
#
#         1. Save this script into your home dir,  chmod it to 700 for security
# 2. Create a pair of ssh keys; install the public key on your strongspace account and the private one in ~/.ssh
# 3. Change the configuration variables below

## Configuration section
#  [Don't forget trailing slashes for all directories!]

        MYSQL_USERNAME=name
        MYSQL_PW=password

        # Optional: Enter the path in your TextDrive account where your database backups are stored.
        # If found, this directory will be rsync'd to strongspace separately. If this folder does not exist then 
        # this feature will be ignored.
        # For a cron job that will create daily rolling MySQL backups, see http://textsnippets.com/posts/show/419
        DB_BACKUP_DIR=~/daily-sql-backup/

        STRONGSPACE_KEY=/home/YOURUSERNAME/.ssh/ss             # Private key file
        STRONGSPACE_USER=SSUSER                                  # Your strongspace login name
        STRONGSPACE_DOMAIN=SSDOMAIN.strongspace.com          # Your strongspace domain

        STRONGSPACE_WEB_BACKUP_DIR=private/backup/web/               # strongspace path for storing web file backups
        STRONGSPACE_DB_BACKUP_DIR=private/backup/databases/  # optional strongspace path for storing SQL backups
## End of configuration section

DOMAINS=`ls ~/domains`
for dom in $DOMAINS
do
        /usr/local/bin/rsync -azq --delete -e "ssh -i $STRONGSPACE_KEY" ~/domains/$dom/public_html/ $STRONGSPACE_USER@$STRONGSPACE_DOMAIN:/home/$STRONGSPACE_USER/$STRONGSPACE_WEB_BACKUP_DIR/$dom
done

if [ -d ~/public_html ]; then
        /usr/local/bin/rsync -azq --delete -e "ssh -i $STRONGSPACE_KEY" ~/public_html/ $STRONGSPACE_USER@$STRONGSPACE_DOMAIN:/home/$STRONGSPACE_USER/$STRONGSPACE_WEB_BACKUP_DIR/$dom
fi

if [ -d $DB_BACKUP_DIR ]; then
        /usr/local/bin/rsync -azq --delete -e "ssh -i $STRONGSPACE_KEY" $DB_BACKUP_DIR $STRONGSPACE_USER@$STRONGSPACE_DOMAIN:/home/$STRONGSPACE_USER/$STRONGSPACE_DB_BACKUP_DIR
fi

Running Mutt w/Maildirs (not IMAP) on TxD servers via ssh

I modified Pteron's muttrc file to use my local Maildir rather than login via IMAP.

This is A) Faster/better since it cuts out the bother of an imap connection to localhost and accesses your mail directly, B) It actually works (the imap method always failed on a segfault for me at least), C) You gotta like not having to store your username/password in the clear since there's no imap login to perform D) More responsive than webmail for quick email checks, and works even when webmail doesn't.

To use, change the realname line and save with filename ".muttrc"; upload this to your home directory, then login via ssh and type "mutt".

# For TextDrive accounts (running mutt on the server)

set mbox_type=Maildir
set folder="~/Maildir/"
set spoolfile="~/Maildir/"
set mask="!^\\.[^.]"
set record="+.Sent"
set postponed="+.Drafts"

set realname="Yourname"

mailboxes `\
echo -n "+ "; \
for file in ~/Maildir/.*; do \
  box=$(basename $file); \
  if [ ! $box = '.' -a ! $box = '..' -a ! $box = '.customflags' \
      -a ! $box = '.subscriptions' ]; then \
    echo -n "+$box "; \
  fi; \
done`

macro index c "?" "open a different folder"
macro pager c "?" "open a different folder"

set allow_8bit  # Don't do any Quoted-Printable encoding on 8-bit data!
set copy=yes    # Ask me if I want to save a copy of my outgoing messages.
set delete=yes
set noaskcc
set nomark_old
set reverse_alias
set reverse_name
set reply_to
set attribution="On %d, %n wrote:"
set envelope_from
set noconfirmappend
set print=ask-no
set print_cmd="echo Nix printi printi!"
set nosave_empty
set sort=threads
set read_inc=10
set write_inc=10
set noprompt_after
set status_format="%r %v [%?M?%M/?%m] %?n?%n new, ?%?p?%p postponed, ?%?t?%t +tagged, ?%?d?%d delet ed, ?(%h:%f) %?b?%b more to go.?%> %r"

#set alias_file="~/.aliases"
set quote_regexp="^([A-Za-z ]+>|[]>:|}-][]>:|}-]*)"
set include
set hdr_format="%4C %Z %{%b %d} %-15.15n (%4l) %s"
set nomove
set tilde
set noautoedit
set pager_context=1
set pager_stop
set pipe_decode
set postponed="+postponed"
set to_chars="b .c>"

set fast_reply

color header brightcyan black .
color header yellow black Subject:
color body brightyellow black [_a-z\.\$A-Z0-9-]+@[a-zA-Z0-9\./\-]+
color body yellow black (http|ftp)://[_a-zA-Z0-9\./~\-]+
color quoted green black
color signature brightblue black
color attachment yellow black
color tree red black
color indicator black cyan
color status yellow blue
color tilde blue black

bind pager 'w' previous-page
bind pager 'j' next-line
bind pager 'k' previous-line
bind index '#' tag-entry
bind index '{' previous-thread
bind index '}' next-thread

# Headers to ignore
ignore *
unignore date from to cc subject x-mailer resent-from reply-to

Daily MySQL backups on Textdrive, rotated weekly

This cron job will create a compressed backup of all the mysql databases under your account. The backup will be stored as "\daily-backup\Mon.gz" - and so forth, one for each day of the week. In this way you will have rotating backups going back seven days.

First, create the "daily-backup" folder under your home directory.

Go into the System - Cron Jobs section in webmin and paste this in as a new cron job (all one line)

/usr/local/bin/mysqldump --skip-opt -uUSERNAME -pPASSWORD --quote-names --complete-insert --extended-insert --quick --compact --lock-tables=false --skip-add-locks --all-databases | gzip > /home/USERNAME/daily-backup/sql-alldb-`date "+%a"`.gz 


Make sure to replace the USERNAME and PASSWORD with your own info.

You can set it up to run on any kind of daily schedule; I have it set to run daily at an early-morning time that I picked randomly.

Testing if this is NOT a category listing

The new releases of textpattern tend to use the new "yoursite.com/category/ZZZ" url format for category listing links. Which means that those category-filtered archives use the "default" template for formatting & so forth.

To handle this on the front page, you need to be able to test if the current view IS a category search, and you also need to test if this ISN't a category search (to display normal front-page content). To do this I had to modify the glx_if plugin - very easy really.

In Textpattern, go to admin > plugins, and click the "edit" link for glx_if. Add the following function anywhere it would seem to fit:

function glx_if_not_category_list($atts, $thing)
{
        global $pretext, $is_article_list;
        return (empty($pretext["c"]) && $is_article_list == true) ? parse($thing) : "";
}


A use for this is shown in this snippet.

Low-Overhead Archives By Month

You used to have to use rss_suparchive to get an archive of articles broken out by month, but this plugin produces an ungodly number of db queries when dealing with large archives (e.g., hundreds or thousands of articles).

Textpattern 4.0.2 allows you to get the same effect using the good ol' tag, which uses a LOT FEWER database queries.

You can see this in action at Not Far North.

First, you need the glx_if plugin installed.

put this in your "article" page template:

<txp:glx_if_section_frontpage>
   <h2>Archivesh2>
   
/> dl> </txp:glx_if_section_frontpage> <txp:if_individual_article> <txp:article /> txp:if_individual_article>


If you were attentive, you see that we also need an article_archive form. Create that form and put this in it:

<txp:if_different>
  <dt><txp:posted format="%B %Y" />dt>
</txp:if_different>

<dd><txp:permlink><txp:title />txp:permlink>

/><txp:excerpt />dd>


Now, "yoursite.com/article" will display a list of articles broken out by month, and "yoursite.com/article/2/helloworld" will display only that article using the "default" form.

To handle category listings, install the upm_category_title plugin and add this to your front page ("default") template:

<txp:glx_if_category_list>
   <h2>Articles in <txp:upm_category_title />h2>
   

/article/">View all articles

"archivelist"> "article" form="article_archive" />
"2" form="article_newest" />


Note that using the above bit of code requires you to modify the glx_if plugin a bit - more about that in another snippet (it's really easy).
« Newer Snippets
Older Snippets »
6 total  XML / RSS feed