Bottle: Python Web Framework

I really like Bottle: Python Web Framework. Bottle is very simple, fast and powerful Python micro-framework. It is perfect for small web applications and rapid prototyping where you need simple/small API server.

Bottle is a fast, simple and lightweight WSGI micro web-framework for Python.

Installation

Install Bottle with pip install bottle or download the source package at PyPI.

Download and Install

Install the latest stable release (Bottle runs with Python 2.7 and 3.3+.)

#pip install bottle

Or

#easy_install -U bottle

Or

download bottle.py (unstable) into your project directory.

– app.py
– bottle.py

Example: “Hello World” (app.py)

from bottle import route, run

@route(‘/hello/:name’)
def index(name=’World’):
return ‘Hello %s!‘ % name

run(host=’localhost’, port=8080)

Bottle Python

Point your browser to http://localhost:8080/hello/sandeep

Links

https://github.com/bottlepy/bottle
https://raw.githubusercontent.com/bottlepy/bottle/master/bottle.py

Below find simple routing, template, static CDN, Ajax, redirect functions

Test URL for above bottle python code run on port 7800

# python bottle_example.py

http://localhost:7800/
http://localhost:7800/hello
http://localhost:7800/ajax
http://localhost:7800/redirect
http://localhost:7800/404
http://localhost:7800/upload
http://localhost:7800/tpl (“test” is text file on [Web-App-Root])
http://localhost:7800/static/god.jpg (“god.jpg” saved on [Web-App-Root])

FFMPEG make Video Lyrics using JPG MP3 SRT File

FFMPEG make Video Lyrics using JPG MP3 SRT File

Input Files

– Image (test.jpg)
– MP3 File (test.mp3)
– SRT Lyrics (test.srt)

FFMPEG Command

# ffmpeg -loop 1 -y -i test.jpg -i test.mp3 -vf subtitles=”f=test.srt:force_style=’FontName=Arial,FontSize=14″ -shortest test1.mp4

Output File: test1.mp4

SRT Lyrics Preview

1
00:00:00,330 --> 00:00:04,936
Hello Feifei. I didn't know you shopped at this supermarket too.

2
00:00:05,354 –> 00:00:12,303
Hi Finn. Usually I don’t. But it’s close to the office and I have to rush home to welcome an important guest.

3
00:00:13,378 –> 00:00:15,321
Who is it? Someone I know?

4
00:00:15,402 –> 00:00:29,763
No, it’s my landlady. She’s coming to collect some of her post and… well, I want to make her like me because next month, the contract on my flat is due to be renewed and she might want to increase the rent.

5
00:00:30,426 –> 00:00:34,919
Yeah, I see what you mean. So you’d better butter her up then!

6
00:00:35,450 –> 00:00:43,498
Butter? Oh, yes. But I’m a pretty bad cook. If I baked a cake it would probably be horrible!

7
00:00:44,474 –> 00:00:56,703
No. I don’t mean butter for a cake. In English, when you say you’ll ‘butter someone up’, you mean you’ll be especially nice to them in the hope they’ll do something good for you in return.

8
00:00:57,498 –> 00:01:08,424
Oh, I see. So I’ll be nice to her and pay her compliments so that she likes me and keeps the rent low. I’ll ‘butter her up’! But isn’t it a bit insincere?

9
00:01:09,522 –> 00:01:22,522
Well, it can have a negative connotation, yes. Let’s hear some examples of how to use ‘to butter someone up’ or ‘to butter up someone’, which is today’s expression in The English We Speak.

How to add MP3 audio delayed in MP4 video?

FFMPEG Command: Add MP3 Audio file delayed in MP4 video file

# ffmpeg.exe -i “fox-story.mp4” -itsoffset 5.00 -i “fox-story.mp3” -map 0:v -map 1:a -vcodec copy -acodec copy “The Fox and Crow Story.mp4”

Input: fox-story.mp4 and fox-story.mp3
Output: The Fox and Crow Story.mp4

-itsoffset 5.00 -i “movie.mp3”
Offsets timestamps of audio streams by 5.00 seconds

-map 1:v -map 0:a
Takes audio stream from the second (delayed) input and video stream from the first input

Song Lyrics: lrc2srt and srt2json

LRC2SRT.php

<?php

function lrc2srt( $lrc ) {
	$lrc = explode( "\n", $lrc );
	$srt = "";
	$lines = array();
	foreach ( $lrc as $lrcl ) {
		if ( preg_match( "|\[(\d\d)\:(\d\d)\.(\d\d)\](.+)|", $lrcl, $m ) ) {
			$lines[] = array(
				'time' => "00:{$m[1]}:{$m[2]},{$m[3]}0", // convert to SubRip-style time
				'lyrics' => trim( $m[4] )
			);
		}
	}
	for ( $i = 0; $i < count( $lines ); $i++ ) {
		$n = $i + 1;
		$nexttime = isset( $lines[$n]['time'] ) ? $lines[$n]['time'] : "99:00:00,000";
		$srt .= "$n\n"
		     .  "{$lines[$i]['time']} --> {$nexttime}\n"
		     .  "{$lines[$i]['lyrics']}\n\n";
	}
	return $srt;
}

echo "<pre>";
echo lrc2srt( file_get_contents("FileName.lrc") );
echo "</pre>";

?>

SRT2JSON.php

<?php

define('SRT_STATE_SUBNUMBER', 0);
define('SRT_STATE_TIME',      1);
define('SRT_STATE_TEXT',      2);
define('SRT_STATE_BLANK',     3);

$lines   = file("FileName.srt");

$subs    = array();
$state   = SRT_STATE_SUBNUMBER;
$subNum  = 0;
$subText = '';
$subTime = '';

foreach($lines as $line) {
    switch($state) {
        case SRT_STATE_SUBNUMBER:
            $subNum = trim($line);
            $state  = SRT_STATE_TIME;
            break;

        case SRT_STATE_TIME:
            $subTime = trim($line);
            $state   = SRT_STATE_TEXT;
            break;

        case SRT_STATE_TEXT:
            if (trim($line) == '') {
                $sub = new stdClass;
                $sub->number = $subNum;
                list($sub->startTime, $sub->stopTime) = explode(' --> ', $subTime);
                $sub->text   = $subText;
                $subText     = '';
                $state       = SRT_STATE_SUBNUMBER;

                $subs[]      = $sub;
            } else {
                $subText .= $line;
            }
            break;
		
    }
		
}

echo "<pre>";
print_r($subs);
echo "</pre>";


$count = count($subs);
 
for($i=0;$i<$count;$i++)
{


$playlist['ID'.$i] = array($subs[$i]->text, $subs[$i]->startTime, $subs[$i]->startTime, $subs[$i]->stopTime);


}

echo  json_encode($playlist);

?>

Amazon Simple Notification Service Command Lines

Install the AWS CLI Using the Bundled Installer

Download the AWS CLI Bundled Installer.

# curl “https://s3.amazonaws.com/aws-cli/awscli-bundle.zip” -o “awscli-bundle.zip”
# unzip awscli-bundle.zip
# chmod a+x ./awscli-bundle/install
# ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

Configure AWS CLI

# aws configure
AWS Access Key ID [None]: XXXXXXXXXXXXXXXXXXXXX
AWS Secret Access Key [None]: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Default region name [None]: us-east-1
Default output format [None]: json

# cat ~/.aws/credentials

[default]
aws_access_key_id=XXXXXXXXXXXXXXXXXXXXX
aws_secret_access_key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

# cat ~/.aws/config

[default]
region=us-east-1
output=json

AWS SNS Common actions

– Create a communication channel to send messages and subscribe to notifications
– Create a platform application for mobile devices
– Subscribe an endpoint to a topic to receive messages published to that topic
– Publish a message to a topic or as a direct publish to a platform endpoint
– Publish a text message (SMS) to a phone number

Create AWS SNS Topic

# aws sns create-topic –name My-Blog
{
“TopicArn”: “arn:aws:sns:us-east-1:xxxxxxxxxxxx:My-Blog”
}

Now you can subscribe to Topic using these protocols

http, https, email, email-json, sms, sqs, application, lambda

check more here: http://docs.aws.amazon.com/cli/latest/reference/sns/subscribe.html

Subscribe to AWS SNS Topic by email

# aws sns subscribe –topic-arn arn:aws:sns:us-east-1:xxxxxxxxxxxx:My-Blog –protocol email –notification-endpoint email@domain.com
{
“SubscriptionArn”: “pending confirmation”
}

AWS SNS Confirm

After Subscription Confirmed it provide SubscriptionArn like arn:aws:sns:us-east-1:xxxxxxxxxxxx:My-Blog:4e2a8654-6b5d-43fe-bf14-2237c8c849f7

AWS SNS Pending Confirm

Subscribe to AWS SNS Topic by Mobile (SMS)

# aws sns subscribe –topic-arn arn:aws:sns:us-east-1:xxxxxxxxxxxx:My-Blog –protocol sms –notification-endpoint 919912345678
{
“SubscriptionArn”: “arn:aws:sns:us-east-1:xxxxxxxxxxxx:My-Blog:a0bb38ca-ece1-4adb-897b-5a21010889e9”
}

Publish message to Topic

# aws sns publish –topic-arn arn:aws:sns:us-east-1:xxxxxxxxxxxx:My-Blog –message “Welcome to My Blog!”
{
“MessageId”: “9f280eb4-b561-5d34-b8c3-5f3be74515b2”
}

AWS SNS Push Message

AWS SNS SMS

Unsubscribe to AWS SNS Topic

# aws sns unsubscribe –subscription-arn “arn:aws:sns:us-east-1:xxxxxxxxxxxx:My-Blog:4e2a8654-6b5d-43fe-bf14-2237c8c849f7”

You can find Available Commands for AWS SNS here
http://docs.aws.amazon.com/cli/latest/reference/sns/index.html#cli-aws-sns

Delete AWS SNS Topic

# aws sns delete-topic –topic-arn “arn:aws:sns:us-east-1:xxxxxxxxxxxx:My-Blog”

Uninstalling AWS CLI

# rm -rf /usr/local/aws
# rm /usr/local/bin/aws

Install the AWS Command Line Interface on Microsoft Windows
http://docs.aws.amazon.com/cli/latest/userguide/awscli-install-windows.html#install-msi-on-windows

Amazon DynamoDB PHP CRUD using aws.phar

DynamoDB is fully managed, fast and low cost NoSQL database service by Amazon. DynamoDB allows you to offload the administrative operations and scale highly distributed database cluster.

The AWS SDK PHP enables you to use Amazon Web Services like Amazon S3, EC2, RDS, CloudFront, Redshift, DynamoDB, Push Notification Service (SNS) and more from your PHP code project.

AWS.PHAR Now Download aws-php-sdk Packaged Phar from http://pear.amazonwebservices.com/get/aws.phar

# wget http://pear.amazonwebservices.com/get/aws.phar

You can also download the packaged phar here http://docs.aws.amazon.com/aws-sdk-php/v3/download/aws.phar

Include the SDK in your PHP project require ‘/path/to/aws.phar’;

Now download simple dynamodb-php-wrapper from here https://github.com/masayuki0812/dynamodb-php-wrapper/blob/master/DynamoDBWrapper.php

<?php

require_once 'aws.phar';
require_once 'DynamoDBWrapper.php'; 

$ddb = new DynamoDBWrapper(array(
    'key'    => 'XXXXXXXXXXXXXXXXXXXXX',
    'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
    'region' => 'us-east-1'
));

createTable

$result = $ddb->createTable(‘Session’, ‘UserId::N’);
// Create a table ‘Session’, which has a hash key ‘UserId’ as NUMBER.

deleteTable

$result = $ddb->deleteTable(‘Session’);

putItem

$item = array(
‘UserId’ => 1,
‘Name’ => ‘Sandeep’,
);
$result = $ddb->put(‘Session’, $item);

updateItem

$key = array(
‘UserId’ => 1,
);
$update = array(
‘Name’ => array(‘PUT’, ‘SVNLabs’)
);
$result = $ddb->update(‘Session’, $key, $update);

deleteItem

$key = array(
‘UserId’ => 1,
);
$result = $ddb->delete(‘Session’, $key);

Query

$keyConditions = array(
‘UserId’ => 1,
);
$result = $ddb->query(‘Session’, $keyConditions);

Scan

$filter = null;

$result = $ddb->scan(‘Session’, $filter, 1000);

Scan with between date filter

$filter = array(
‘userType’ => “member”,
“date” => array(“BETWEEN”, array(“2016/08/01″,”2016/08/17”))
);
$result = $ddb->scan(“Session”, $filter, 1000);

Other Links

https://docs.aws.amazon.com/aws-sdk-php/v3/guide/getting-started/installation.html
https://github.com/masayuki0812/dynamodb-php-wrapper/wiki
https://github.com/svnlabs/aws-dynamodb-php

Top 10 Tutorials for your Drupal Website

Drupal is one of the most popular and powerful content management systems. Creating your website with Drupal will allow you endless options for design and function. Use these 10 Drupal tutorials to easily give your website features and options you may have never thought possible.

1. Tutorial For Site Setup

Every Drupal website owner should begin with a basic site-building tutorial. The first thing to do, after getting Drupal-compatible web hosting, is to review such a tutorial to create your site’s key elements. This site-setup tutorial will walk you through building your website’s administration menu, site editor, pages, menus, and slideshows.

2. Update Drupal Using Minor Updates and Patches

There are a few types of updates you will come across as a Drupal website owner including, minor, major and patch updates. This tutorial will show you how to keep your installation current to avoid bugs and errors, and maintain the latest module compatibility. Patch updates are often aimed at fixing bugs or security issues and may be released at any time. Minor updates fix site functions errors, and are released less often.

3. Autoloading Awesomeness

This tutorial will show you how to take advantage of autoloading in your visitors web browsers. This is helpful when you want to display video or other media without the user having to click ‘Play.’ Use the Auto-loading Awesomeness tutorial to follow in the steps of major media and social companies who know rely on the feature, such as Facebook and Instagram.

4. Preparing Your Site for Drupal 8

The latest release of Drupal, as of 2017, is Drupal 8. This tutorial will help you get prepared for a major update to any outdated Drupal sites. IT discusses manual site audits, security updates and audit modules. While your updated your Drupal and installing Drupal 8, you should check that you have Drupal optimized web hosting, so that you can make the most of your Drupal installation.

5. Installing and Editing Drupal Themes

This tutorial is perhaps among the most important for any Drupal user. It shows you how to install and modify themes for your Drupal site by giving you the basics on how themes work. After reviewing this tutorial, even a beginner will be able to choose and install a Drupal theme that’s right for their site. Those with just a few minutes on their hands can learn how to change colors, module positions and add or remove elements.

6. Drupal SEO Tutorial

If you’re focused on marketing and Search Engine Optimization, then this is the Drupal tutorial for you. It will teach you how to create SEO-friendly posts, tags, and headers. Beginning with a focus on mobile Drupal templates and themes, this handy guide will ensure your site doesn’t get buried in the search results.

7. Drupal Modules Tutorial

This tutorial is invaluable for those who want to begin developing Drupal modules and backend coding. It will show you how to use Object-Oriented PHP to create Drupal modules with function in the backend of your site and interactive features for your website’s frontend. Some PHP knowledge is required for this tutorial. Object-Oriented PHP will keep your Drupal site coding from being redundant, and save you time behind the keyboard.

8. Use Node.js with Drupal

Many web developers are used to node.js and want full javascript integration on their Drupal based website. This tutorial will teach you to seamlessly integrate the popular node.js package with Drupal to use them inherently together. Using Node.js on your Drupal site will allow you to build web applications that are as scalable as you need them to be. This would work great for any new social media site or mobile application.

9. Create a Custom Slideshow

Slideshows have many purposes on websites, including rotating content to keep the site fresh, and ensuring certain content has a front-page standing. This tutorial will show you how to easily create a slideshow on your Drupal site using theme libraries and the Slick module. It involves some simple HTML markup and Java which you can copy and paste or make modifications to. Your finished product will look great on any business website, and will rotate three or more images or embedded media modules at your desired speed.

10. Loop Over Objects

This tutorial is among the more advanced on the list, but should appeal to anyone with even a little coding background. It will show you how to loop over objects using the built-in tag IteratorAggregate. If you’re looking to get started practicing your PHP skills on a live site, this tutorial is a great choice and will provide convenient, functional results.

Drupal can be used for personal websites, business and corporate sites, and even blogs. It’s a diverse CMS that allows countless customizations. By following these tutorials you will gain a better understanding of your Drupal interfaces, and be able to add creative elements to your website.

Linux – Delete Files Or Directories Older Than x Days

First find files older than X Days

-mtime n => File was last modified n*24 hours ago.

-atime n => File was last accessed n*24 hours ago.

-ctime n => File status was last changed n*24 hours ago.

+n More than n.
n Exactly n.
-n Less than n.

# files modified greater than 24 hours ago
find /location/ -mtime +0

# files modified between now and 1 day ago
find /location/ -mtime 0

# files modified less than 1 day ago
find /location/ -mtime -1

# files modified between 24 and 48 hours ago
find /location/ -mtime 1

# files modified more than 48 hours ago
find /location/ -mtime +1

-type f => For Files
-type d => For Directories

Now delete all files modified time greater than 24 hours ago (keep today’s files)
# find /var/www/html/recorded/files/* -type f -mtime +0 -exec rm {} \;

Activate Free SSL Certificate for Website – Cloudflare

Google will soon shame all websites that are unencrypted also Google count HTTPS for ranking factor. Cloudflare provide Free SSL Certificate in your website DNS system. You just need to edit your DNS records / Name-servers

Cloudflare HTTPS protects website from Security Vulnerabilities and DDoS attacks.

Origin Server (Your Domain) ===== HTTP =====> CloudFlare ===== HTTPS =====> Visitors

Setting up your free Cloudflare Flexible SSL

1. Sign up to Cloudflare.com

2. Enter your domain name and Begin Scan

3. Verify all Your DNS Records for your domain

4. Select Free Cloudflare Plan then follow all steps

5. Change Your Nameservers in your domain control panel

6. Goto Crypto tab then activate free SSL. Choose Flexible Type.
Cloudflare will take approx 24 hours to activate new SSL certificate.

7. Other Cloudflare settings for caching

8. For wordpress websites add Page Rules in CloudFlare

You can use WordPress Plugins

CloudFlare Flexible SSL

Cloudflare

WordPress Force HTTPS

Really Simple SSL

SSL Insecure Content Fixer

OR

1. http://www.svnlabs.in/wp-admin/*
Always Online: On, Cache Level: Bypass

2. http://www.svnlabs.in/wp-login.php*
Always Online: On, Cache Level: Bypass

3. http://svnlabs.in/*
Forwarding URL: (Status Code: 301 – Permanent Redirect, Url: https://www.svnlabs.in/$1)

Free SSL