converting webm to mp3s ffmpeg

for FILE in *.webm; do
    echo -e "Processing file '\e[32m$FILE\e[0m'";
    ffmpeg -i "${FILE}" -vn -ab 128k -ar 44100 -y "${FILE%.webm}.mp3";
done;

nJoy πŸ˜‰

Snapshot backup using cp -al and rsync

This script requires genuine cp -al capable gnu and rsync commands together with a hardlink capable FS + OS.

 

 

#!/bin/bash

[ $# -ne 2 ] && echo "Incorrect usage : $0 <source path> <target path>" && exit 128 ;

SOURCEFOLDER=$1
TARGETFOLDER=$2

SF_LEN=${#SOURCEFOLDER}-1
TF_LEN=${#TARGETFOLDER}-1

#echo "Last character in source folder is ${SOURCEFOLDER:SF_LEN}"
if [ "${SOURCEFOLDER:SF_LEN}" != "/" ] ; then
   echo "Adding trailing slash"
  SOURCEFOLDER=$SOURCEFOLDER"/"
fi



#echo "Last character in target folder is ${TARGETFOLDER:TF_LEN}"
if [ "${TARGETFOLDER:TF_LEN}" != "/" ] ; then
   echo "Adding trailing slash"
  TARGETFOLDER=$TARGETFOLDER"/"
fi



echo $SOURCEFOLDER
echo $TARGETFOLDER

LOCKFILE=/tmp/`echo $0 $SOURCEFOLDER $TARGETFOLDER | sed "s/[^[:alnum:]]/_/g"`.lck
echo "Lockfile : $LOCKFILE"



[ ! -d $SOURCEFOLDER ] && echo "Source does not exist !! $SOURCEFOLDER exitting with error" && exit 1;

TIMESTAMP=$(date --utc +%Y%m%d%H%M )
#echo $TIMESTAMP



if [ ! -d $TARGETFOLDER ]; then 

mkdir $TARGETFOLDER

rsync -av --delete  $SOURCEFOLDER $TARGETFOLDER/$TIMESTAMP/

else 

[ -d $TARGETFOLDER/$TIMESTAMP/ ] && echo "Folder already there !! Leaving.. " && exit 0;  

 LASTBACKUP=$(ls $TARGETFOLDER | sort -rn | head -1)
 echo "Link copying $TARGETFOLDER/$LASTBACKUP to $TARGETFOLDER/$TIMESTAMP/"
 cp -al $TARGETFOLDER/$LASTBACKUP $TARGETFOLDER/$TIMESTAMP/
 rsync -av $SOURCEFOLDER $TARGETFOLDER/$TIMESTAMP/

fi

echo " OK !! Done"

 

 

 

Simple page to redirect to https from index.html

<html>
<head>
<title>
Redirecting...</title></head>
<script language="JavaScript">
function redirectHttpToHttps()
{
    var httpURL= window.location.hostname + window.location.pathname + window.location.search;
    var httpsURL= "https://" + httpURL;
    window.location = httpsURL;
}
redirectHttpToHttps();
</script>
<body>
</body>
</html>

 

nJoy πŸ˜‰

Installing node on old version of Ubuntu 10.04

 curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash

logoff and log on

nvm ls-remote
nvm install v7.9.0
npm -v
node -v

Caveat : Β  Lots of node stuff fails to compile and run on such an oldΒ version of linux be warned…
Thats it you now have node and npm installed. nJoy πŸ˜‰

Saving a million documents in Mongo using Nodejs and mongodb module

/**
* Created by davidsaliba on 13/03/2017.
*/
var MongoClient = require('mongodb').MongoClient
, format = require('util').format;

var url = 'mongodb://localhost:27017/test';
var async = require ('async');

var entry = {
data : "skdlfjsdf",
array : [ {id:"arr_obj1"} , {id:"arr_obj2"} ]
};

var entries = [];

var total_entries = 1000000

for (var j = 0 ; j <= total_entries ; j ++){
console.log (j);
entries.push({"_id":j ,entry:entry});
}

console.log ("Number of entries", entries.length);

MongoClient.connect(url, function(err, db) {
// Get the collection
var col = db.collection('articles');
//

var bulk = col.initializeOrderedBulkOp();
var counter = 0;

async.whilst(
// Iterator condition
function() { return counter < total_entries },

// Do this in the iterator
function(callback) {
counter++;

bulk.insert(entries[counter] );

if ( counter % 1000 == 0 ) {
bulk.execute(function(err,result) {
bulk = col.initializeOrderedBulkOp();
callback(err);
});
} else {
callback();
}
},

// When all is done
function(err) {
if ( counter % 1000 != 0 )
bulk.execute(function(err,result) {
console.log( "inserted some more" );
});
console.log( "I'm finished now" );
db.close();
}
);
});

nJoy πŸ˜‰

Installing git on Debian 8.x

You should edit your sources.list , by adding the following line:

deb http://ftp.ca.debian.org/debian/ jessie main contrib

Then upgrade your package and install git:

apt-get update &amp;&amp; apt-get upgrade &amp;&amp; apt-get dist-upgrade
apt-get -f install
apt-get install git

nJoy ;-)

(more…)