:::: MENU ::::

Repetitive rsync

Some time ago I’ve been moving from one hosting provider to another. I had to transfer the files from A to B and used rsync for that. But unfortunately rsync command was crashing due to some timeouts. So I’ve found really nice script for auto restore.

rsync-auto.sh

#!/bin/bash

while [ 1 ]
do
    /usr/bin/rsync -avz --progress $1 $2
    if [ "$?" = "0" ] ; then
        echo "rsync completed normally"
        exit
    else
        echo "Rsync failure. Backing off and retrying..."
        sleep 10
    fi
done

Execute

rsync-auto.sh SOURCE DESTINATION

source: stackoverflow.com


Generating lottery codes – how many combinations will I have?

Here is a task. You have to prepare the schema for lottery codes. You have to generate lets say 1 000 000 codes that are 6 characters long. Client’s question is ‘Is that safe?’. This is a good question and you have to do some basic math to be sure that the combination of the code length and alphabet size give you enough combinations so users can’t guess other codes.

Simple example

Alphabet: A, B
Code length: 3 characters

So we have possible combinations:

AAA
AAB
ABA
ABB
BBB
BBA
BAA
BAB

So we have 8 possible combination for 3 characters code with 2 characters alphabet.

23 = 8

Later on, if we have 11 characters in our alphabet and 9 character code we will have

119 = 2 357 947 691

so if client wants 1 000 000 of codes, this scheme seems to be quite secure since is like 0,0424% of all possible combinations.








Removing .git / .svn directories

Sometimes you have to remove directories from your VCS tool.

find . -name .svn -exec rm -rf {} \;

Listing affected directories

find . -name .svn -exec echo {} \;

Pages:12345