Einfacher Rechner für die Bash

Da ich hier und da kleinere schnelle Berechung auf dem Numpad machen muss, stört im deutschen Tastaturlayout das Komma, da zum Beispiel bc kein Komma als Dezimaltrenner sondern einen Punkt erwartet. Wie das halt im englischen so üblich ist. Da her habe ich mir eine keine Funktion gebaut, bei der man Kommata ein und die diese auch wieder ausgibt.

Das ganze funktioniert nur mit einfachen Berechnungen und rundet auf die zweite Dezimalstelle.

Einfach in die .bashrc eintragen:

# simple calculator
calc () {
  echo "scale=2;$@" | sed "s/,/\./" | bc | sed "s/\./,/"
}

yab_cf_article_list - List and search a custom_field in admin article list

This Textpattern plugin lists a custom field in the admin article list. Additonally the article search/filter is extended with the custom field (see screenshot below).

yab_cf_article_list

Download compiled and source:
yab_cf_article_list_v0.2.tar.gz

yab_cf_article_list

List a custom_field in admin article list and search article list for this custom field.

Version: 0.2

Table of contents

  1. Plugin requirements
  2. Configuration
  3. Changelog
  4. License
  5. Author contact

Plugin requirements

Minimum requirements:

  • Textpattern 4.6.x

Configuration

Install and activate the plugin.

The function yab_cfal_config() in the plugin code contains an array with some config values:

'custom_field': Number of the custom field
Default: 1

'name_for_list': Name of the custom field in the table head and in article search.
Default: empty (The given name for this custom field will be shown.)

Changelog

  • v0.1: 2014-05-06
    • initial release
  • v0.2: 2017-02-18
    • bugfix: TXP 4.6.ready (required)

Licence

This plugin is released under the GNU General Public License Version 2 and above

Author contact

Linkhub #20

yab_copy_to_new - copy the current article content to a new one

This Textpattern plugin is a replacement for upm_savenew. It generates a button in the write tab. By clicking the button you can copy the article content to a new one.

Download compiled and source: yab_copy_to_new_v0.2.tar.gz

yab_copy_to_new

Displays a new button in article write tab to copy the current article to a new one.

Version: 0.2

Table of contents

  1. Plugin requirements
  2. Configuration
  3. Changelog
  4. License
  5. Author contact

Plugin requirements

yab_copy_to_new’s minimum requirements:

  • Textpattern 4.x
  • Modern browser capable of HTML5 sessionStorage

Configuration

Install and activate the plugin.

The following form fields will not be copied by default:

  • all of hidden type
  • an exclude array of posted day and time and the url_title
    You can modify this exclude array on your own,

The function yab_ctn_config() contains an array with some config values and a commented example of the array which places the button near the top »Create new button«.

  • 'exclude': Javascript array with field to excluded from copying
  • 'position_selector': a valid jQery selector (used by position_method)
  • 'position_method': any jQuery DOM insert method (after, prepend, append, before etc.)
  • 'class': html class applied to teh button
  • 'style': inline style attribute aplied to the button

Changelog

Install and activate the plugin.

The following form fields will not be copied by default:

  • all of hidden type
  • an exclude array of posted day and time and the url_title
    You can modify this exclude array on your own,

The function yab_ctn_config() contains an array with some config values and a commented example of the array which places the button near the top »Create new button«.

  • 'exclude': Javascript array with field to excluded from copying
  • 'position_selector': a valid jQery selector (used by position_method)
  • 'position_method': any jQuery DOM insert method (after, prepend, append, before etc.)
  • 'class': html class applied to teh button
  • 'style': inline style attribute aplied to the button

Licence

This plugin is released under the GNU General Public License Version 2 and above

Author contact

yab_remember_categories - Remembers the selected categories in write tab

This simple Textpattern plugin simply remembers the selected categories in the admin write tab while creating an article. It’s saves the values in the Browsers HTML5 localStorage.

Download compiled and source: yab_remember_categories_v0.2.tar.gz

Version: 0.2

Table of contents

  1. Plugin requirements
  2. Configuration
  3. Changelog
  4. License
  5. Author contact

Plugin requirements

yab_remember_categories’s minimum requirements:

  • Textpattern 4.x

Configuration

Install and activate the plugin. The Plugin remembers the previously selected category 1 and category 2 in write tab while creating an article by saving with HTML5 localStorage.

Changelog

  • v0.1: 2014-02-04
    • initial release
  • v0.2: 2014-02-06
    • bugfix: does now only work on article create step

Licence

This plugin is released under the GNU General Public License Version 2 and above

Author contact

yab_review_rating - A comment based rating system for Textpattern

This is (star) rating plugin for Textpattern. It’s a useful partner for yab_shop. It extends the comment system with a rating scala, so it can be used as reviews for products.

Download compiled and source: yab_review_rating_v0.6
Demo: yab_shop demo

yab_review_rating

A comment based rating system for articles.

Version: 0.6

Table of contents

  1. Plugin requirements
  2. Configuration
  3. Tags
  4. Examples
  5. Changelog
  6. License
  7. Author contact

Plugin requirements

yab_review_rating’s minimum requirements:

  • Textpattern 4.x

Configuration

Open the plugin code. the first function contains the configuration values. There is a min and a max values for the rating. Valid values are 0-255.

Tags

yab_review_rating

Place this in your comment form. It will show the rating of the current comment.
Can be used elsewhere. If not used in comment context as comments_form or recent_comments you have to fill the id attribute.

id: integer (comment id)
Default: no set
Show the rating of a comment with this ID. Useful in a non comment context.

char: a valid string
Default: no set
If empty (default) the output will be the rating number. If a char (e.g. a asterisk *) is set the output will be the n-times repeated char, where n is the rating.

yab_review_rating_input

The form element for the rating. Should be placed in the comment_form form.

type: input type (text, select, radio, number, range)
Default: text
The type of the form element for the rating. Valid value are text, select, radio, number and range.

html_id: HTML id name
Default: not set
The HTML id attribute applied to the element.

class: HTML class name
Default: not set
The HTML/CSS class attribute applied to the element.

reverse: integer|string (a non-null value)
Default: 0
If reverse is given the output of the select or radio type is displayed in reverse order.

break: breakpoint (br, empty)
Default: ‚br‘
Breakpoints für radio intputs. Can be empty or br.

default: integer
Default: not set
Preselected rating value (Could be any number between your min and max values).

yab_review_rating_average

Display the average rating for a given article.

id: integer (article id)
Default: no set
The ID of an article. If not set it must be placed in an article form (article context).

only_visible: integer|bool (1|0)
Default: 1
If set to 0 all comments (spam and moderated comments too) will be calculated.

exclude: string (a comma separated list of ratings)
Default: null
Exclude these ratings from the average rating calculation. So you can exclude ‚0‘ values for not rated articles, due 0 is the default value. Depending on your rating system setting.

default: string (Text)
Default: ‚not yet rated‘
The default text on articles without a rating.

decimals: integer
Default: 1
Define the decimal precision of the calculation and the output.

separator: string (string|empty)
Default: . (perdiod)
Choose your decimal separator. Can be empty (separator will be omitted) for HTML class friendly output.

round_to_half: string (up|down|)
Default: no net
Round to first half integer up or down or not at all. If not set the last decimal is automatically rounded up.

Examples

Example 1

Example of yab_review_rating_input in a comment_form form.

<txp:comments_error wraptag="ul" break="li" />
	<div class="message">
		<p><label for="name">Name:</label><br /><txp:comment_name_input /></p>
		<p><label for="email">Mail (not required, not visible):</label><br />
			<txp:comment_email_input /></p>
		<p><label for="yab-rr-rating">Rating</label><br />
			<txp:yab_review_rating_input html_id="yab-rr-rating" type="select" default="3" /></p>
		<p><label for="message">Review:</label><br />
			<txp:comment_message_input /></p>
		<p class="submit"><txp:comments_help /><txp:comment_preview /><txp:comment_submit /></p>
</div>

Will produce a comment form for article reviews (e.g. with yab_shop) select dropdown menu and the preselected rating value 3.

Example 2

Example of yab_review_rating in a comments form.

<h3 class="commenthead"><txp:comment_permlink>#</txp:comment_permlink> - <txp:comment_name /> wrote at <txp:comment_time />:</h3>
<span class="rating">Rating: <txp:yab_review_rating char="*" /></span>
<txp:comment_message />

Will produce a comment/review with the name, text and time of the comment and the rating with asterisks *.

Example 3

Example of yab_review_rating in a comments form.

<h3 class="commenthead"><txp:comment_permlink>#</txp:comment_permlink> - <txp:comment_name /> wrote at <txp:comment_time />:</h3>
<span class="rating rating-value-<txp:yab_review_rating />">Rating:</span>
<txp:comment_message />

Will produce a the a comment/review with the name, text and time of the comment and the rating as HTML/CSS class.

Example 4

Example yab_review_rating_average.

<txp:yab_review_rating_average id="12" exclude="0" decimals="2" separator="" round_to_half="down" />

Say the article with the ID 12 do have 3 reviews: One with a rating of 0 and two with a rating of 4 each. The output will exclude the 0 from the calculation. So only the two 4-ratings will be used 4+4 = 8÷2 = 4. Average rating is 4. But we have decimals precision of 2, so it will be 4.00. No rounding required but the separator will be ommitted: 400 will be displayed.
exclude=„0“ decimals=„2“ separator=“„ round_to_half=„down“ />

<txp:yab_review_rating_average id="12" decimals="2" separator="" round_to_half="down" />

Here we calculate an average from all reviews/ratings. Like above we have two 4 and 0-rating. So the rating is 0+4+4 = 8÷3 = 2.6666666667. Now we round to half down: 2.500000000 and use the decimal precision of 2: 2.50 and ommit the separator: 250.

Changelog

  • v0.1: 2013-12-24
    • initial release
  • v0.2: 2014-01-08
    • new: added a the tag <txp:yab_review_rating_average />
  • v0.3: 2014-01-12
    • new: added the id attribute to <txp:yab_review_rating />
    • modify: <txp:yab_review_rating /> can now be used in <txp:recent_comments />
  • v0.4: 2014-01-16
    • new: added reverse attribute to <txp:yab_review_rating_input />
    • new: added only_visible attribute to <txp:yab_review_rating_average />
    • modify: id attribute of <txp:yab_review_rating_average /> can now contain list of article ids
  • v0.5: 2017-02-10
    • TXP 4.6-ready
  • v0.6: 2017-03-09
    • bugfix: handle comment UI correctly, prevent rating resets to 0 if comment status is changed

Licence

This plugin is released under the GNU General Public License Version 2 and above

Author contact

Diceware Passwörter mit der Shell generieren

Ich hab mir ein kleines Shellskript geschrieben, dass mir sichere Diceware-Passwörter generiert. Wer nicht weiß, was Diceware ist und warum die relativ sicher sind, dem seien folgende Links ans Herz gelegt:

Das ist natürlich ein typischer Fall von NIH, weil es für die Bash/Shell oder auch online wahrscheinlich hundert andere und gut funktionierende Tools dafür gibt, aber selber programmieren und grübeln macht einfach deutlich mehr Spaß.

Die Benutzung ist relativ einfach:

$ ./roll_password.sh

gibt ein Passwort mit fünf Wörtern (english) aus. Folgende Argumente können mit übergeben werden:

  • -c bestimmt die Anzahl der Wörter, die das Passwort haben soll (standard: 5)
  • -l die minimale Zeichenanzahl des gesamten Passwortes (standard: 14)
  • -w Wortlistendatei aus denen sich das Passwort generieren soll (standard diceware_wordlist_en)

Für Schlüssel-Signierungen und Kryptographie würde ich die generierten Passwörter nicht benutzen, dafür ist die $RANDOM-Umgebungsvariable nicht zufällig genug, aber als Passwörter für typische Online-Dienste sind sie sehr gut geeignet.

Das Skript kann man hier herunterladen. Im Download enthalden sind das Shellskript, die englische und die deutsche Diceware-Wortlistendatei.

roll_password.tar.gz

Und hier noch ein bisschen Skript, für die, die nur daran interessiert sein sollten.

#!/bin/bash
#
# Name: roll_password.sh
# Description: This script rolls a random passphrase based of a wordlist (Diceware).
# Author: Tommy Schmucker
# Created: 2012-06-08
# Modified: 2012-09-25
# Version: 0.2
#

usage()
{
	cat << EOF

This script rolls a random pass phrase based of a wordlist (Diceware).

usage: $0 [-h] [-c number] [-l number] [-w file]

-h Show this message
-c Count of words in the pass phrase
-l Minimun length of the pass phrase
-w Wordlist file

EOF
}

count=5
wordlist=diceware_wordlist_en
min_length=14
phrase=

while getopts "hc:l:w:" option; do
	case $option in
		h)
			usage
			exit 1
			;;
		c)
			count="$OPTARG"
			;;
		l)
			min_length="$OPTARG"
			;;
		w)
			wordlist="$OPTARG"
			;;
		?)
			usage
			exit
			;;
	esac
done

[ -e "$wordlist" ] || { echo "$wordlist does not exists, exiting"; exit 1; }

roll_number()
{
	number=
	for i in `seq 5`; do
		roll=`expr $RANDOM % 6`
		digit[i]=`expr $roll + 1`
		number=$number${digit[i]}
	done
}

get_word()
{
	word=
	roll_number
	word=`cat $wordlist | grep $number | awk '{print $2}'`
}

get_phrase()
{
	for j in `seq $count`; do
		get_word
		if [ $j == 1 ]; then
			phrase="$word"
		else
			phrase="$phrase $word"
		fi
	done
}

get_phrase
length=`echo -e "$phrase\c" | wc -m`

if [ $length -lt $min_length ]; then
	echo $'\n'"Phrase \"$phrase\" is too short ($length chars)."$'\n'"You should run the command again!"$'\n'
else
	echo $'\n'"$phrase"$'\n'
fi

neuere Einträge | ältere Einträge