Install Ruby Slate NodeJS on CentOS 7

Slate is Beautiful static documentation for your API

Slate

Required

– Linux or OS X or Windows
– Ruby version 2.3.1 or newer
– NodeJS
– Bundler — gem install bundler

# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)

Install Ruby 2.4 – CentOS 7

# yum update
# yum groupinstall “Development Tools”
# yum install epel-release

# yum install readline-devel zlib-devel libffi-devel libyaml-devel openssl-devel sqlite-devel

RVM (Ruby Version Manager) Allow you to install and manage multiple ruby environments.

# curl -sSL https://rvm.io/mpapis.asc | gpg --import -
# curl -L get.rvm.io | bash -s stable

# source /etc/profile.d/rvm.sh
# rvm reload

# rvm requirements run

Show available ruby versions
# rvm list known

Install Ruby 2.4

# rvm install 2.4
# rvm use 2.4 --default

Install Ruby Bundler

# gem install bundler

Install NodeJS for JavaScript Run-time Environment

# yum install nodejs npm

# cd /home/centos

Fork / Clone repository

# git clone https://github.com/svnlabs/slate.git

# cd slate

Allow / Open firewall port 4567 for Slate

# systemctl status firewalld

Like firewall-cmd –add-port=[YOUR PORT]/tcp

# firewall-cmd --permanent --add-port=4567/tcp

# systemctl restart firewalld

Run Slate locally

# bundle install
# bundle exec middleman server

Open URL in Browser http://server-ip-address:4567/#introduction

Now edit source files here “/home/centos/slate” as you need 😉

Facebook Delight Text Keywords

Facebook Delight Text display celebration balloons on Facebook Page / Post. Facebook have selected Greeting Text Keywords from different languages. Facebook Delight Text give celebration feel to Facebook Users.

Keywords:[“Congrats”,”تهانينا”,”مبروك”,”ألف مبروك”,”مبارك”,”Glückwunsch”,”Gratuliere”,”Enhorabuena”,”Felicitaciones”,”Félicitations”,”बधाई”,”Selamat”,”Congratulazioni”,”おめでとう”,”축하해”,”축하해요”,”Мои поздравления”,”Поздравляем”,”Поздравляю”,”ยินดีด้วย”,”Tebrikler”,”恭喜”,”Geluk”,”অভিনন্দন”,”Gratulace!”,”Til lykke”,”Tillykke”,”Συγχαρητήρια”,”Paljon onnea”,”Onnea”,”અભિનંદન”,”מזל טוב”,”Gratula”,”Čestitam”,”Čestitke”,”Čestitamo”,”അഭിനന്ദനങ്ങൾ”,”ಶುಭಾಶಯ”,”Tahniah”,”Grattis”,”अभिनंदन”,”ਵਧਾਈਆਂ”,”Parabéns”,”Gratki”,”Gratulacje”,”Felicitări!”,”Gratulujem”,”Blahoželám”,”Gefeliciteerd”,”வாழ்த்துகள்”,”வாழ்த்துக்கள்”,”అభినందనలు”,”مبارکباد”,”Chúc mừng”,”Честитам”,”Hongera”]

What is a Self-XSS scam?

A Self-XSS scam usually works by promising to help you access somebody else’s account. Instead, the scammer tricks you into gaining access to your account for fraud, spam and tricking more people into a scam.
Scammers will usually target your friends by posting to your Timeline.
To avoid Self-XSS attacks, never copy and paste suspicious links.
(Source: Facebook)

This is a browser feature intended for developers. If someone told you to copy-paste something here to enable a Facebook feature or “hack” someone’s account, it is a scam and will give them access to your Facebook account.

ZRUYR1S8XUa.js: https://www.facebook.com/rsrc.php/v3/y0/r/ZRUYR1S8XUa.js

See https://www.facebook.com/selfxss for more information.
(Source: Chrome Console)

JavaScript Detecting Internet Connection

Offline.js automatically alerts users for their internet connection using AJAX requests.

Download offline.min.js

offline.html

<script src="offline.min.js"></script>
<script>

Offline.options = {checks: {xhr: {url: 'offline.html'}}};

var run = function(){

// check internet connection
Offline.check();

// return internet connection state  
console.log(Offline.state);

document.getElementById("status").innerHTML = Offline.state; 
 
}

setInterval(run, 5000);

</script>

<div id="status">up</div>

Download Gmail Blocked Email Attachments

Anti-virus warning – 1 attachment contains a virus or blocked file. Downloading this attachment is disabled.

blocked-attachment

Gmail says …. File types you can’t include as attachments
.ADE, .ADP, .BAT, .CHM, .CMD, .COM, .CPL, .EXE, .HTA, .INS, .ISP, .JAR, .JS (NEW), .JSE, .LIB, .LNK, .MDE, .MSC, .MSI, .MSP, .MST, .NSH .PIF, .SCR, .SCT, .SHB, .SYS, .VB, .VBE, .VBS, .VXD, .WSC, .WSF, .WSH

I know my zip file “portfolio-1.zip” have .JS files

Note: Gmail warned you that attachment is not safe. So make 100% sure that email attachments is safe for download before follow below process.

email-show-original

Click on email option “Show original”, it will open a new browser window with MIME encoded message. Now you have to “Download Original” OR “Copy to clipboard” save text file “original_msg.txt”

In file “original_msg.txt” you can find attached file name

Content-Type: application/zip; name=”portfolio-1.zip”
Content-Disposition: attachment; filename=”portfolio-1.zip”
Content-Transfer-Encoding: base64
X-Attachment-Id: f_iqui8p0t0

Create new Python script named “getAttachments.py” and write below code in it

import email
import sys

if __name__=='__main__':
    if len(sys.argv)<2:
        print "Please enter a file to extract attachments from"
        sys.exit(1)

    msg = email.message_from_file(open(sys.argv[1]))
    for pl in msg.get_payload():
        if pl.get_filename(): # if it is an attachment
            open(pl.get_filename(), 'wb').write(pl.get_payload(decode=True))

D:\>python –version
Python 2.7.6

D:\>python getAttachments.py original_msg.txt

You will find zip file attachment “portfolio-1.zip” in the same folder!

You can also open Mime Encoded Text file “original_msg.txt” in Outlook or any email client just rename it to “original_msg.eml” then open email file and download attachment.

Suggestion: If your files are safe, you can upload the file to Google Drive, then send shareable link as Drive attachment.

Extract attachments from emails that Gmail doesn’t allow you to download.

jPlayer playbackRate Audio Speed Control for Podcast Player

Today one of my customer need Audio PlayBack Speed Control for HTML5 Audio Player. His requirement is that many people speak too slow on
podcasts. He wants to speed up the playback so that he don’t have to take so much time to listen to the podcast.

He actually wants button for speed [ 0.5x, 1x, 1.5x, 2x, 2.5x ] on HTML5 Audio using jPlayer.

jPlayer playbackRate

jPlayer playbackRate
Number : (Default: 1) : Defines the playback rate. Recommend that the jPlayer({defaultPlaybackRate}) matches this value during initilization.
http://jplayer.org/latest/developer-guide/#jPlayer-option-playbackRate

jQuery(“#jplayer”).jPlayer(“option”,”playbackRate”, 1.5);

jQuery(“#jplayer”).jPlayer(“options”,{defaultPlaybackRate : 1.5});

<script type="text/javascript">

var currentSpeedIdx = 1;  
var speeds = [ 0.5, 1, 1.5, 2, 2.5 ];

function jpSpeedControl()
{

currentSpeedIdx = currentSpeedIdx + 1 < speeds.length ? currentSpeedIdx + 1 : 0;

jQuery("#jplayer").jPlayer("option","playbackRate", speeds[currentSpeedIdx]);

jQuery("#jpSpeedControl").html( speeds[currentSpeedIdx] + 'x' );

}

</script>

<div id="jpSpeedControl" title="Speed" style="cursor:pointer;" onclick="jpSpeedControl();">1x</div>

Wowza Live Stream Countdown

Live Stream Time

<?php

function timeElapsed($originalTime){

        $timeElapsed=$originalTime-time();
		
		return $timeElapsed;
}


//$Details['datetimepicker'] = "06/26/2014 11:42 am";  // coming from database

$dtp = timeElapsed( strtotime($Details['datetimepicker']) );

?>
var myCountdownTest = new Countdown({
			time: <?php echo $dtp; ?>,
			width	: 300, 
			height	: 50,
			style:"boring",
			rangeHi:"day",
			labelText	: 	{
			second 	: "SECONDS",
			minute 	: "MINUTES",
			hour	: "HOURS",
			day 	: "DAYS",
			month 	: "MONTHS",
			year 	: "YEARS"			
			},
			onComplete : doneHandler
			});

Live Video Stream will be coming

Download Code: live-stream-countdown.zip

Radio Song Album Artwork Cover by YouTube

An album cover is the front / other side of the packaging of a commercially released audio recording product, or album.

You can find online APIs or Websites where artwork available

– Amazon
– LastFM
– Soundcloud
– Apple iTune
– Google Play
– Gracenote
– Free Music Archive

And many more ….

But YouTube is the best source where you can get Album / Song Cover Image for every Title

YouTube provide gdata API to search songs as video title to get image

Deprecated Features for YouTube API v2.0

YouTube Data API (v3)

http://gdata.youtube.com/feeds/base/videos?q=title:<search term>

youtube-artwork.php

<?php
$q = isset($_REQUEST['q'])?$_REQUEST['q']:"";

//thumbnail -> sqDefault, hqDefault

// orderby -> title, relevance, published

?>
 
 
<div id="videos"></div>
 
<!-- Include the latest jQuery library -->
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
 
<script type="text/javascript">

jQuery.getJSON('https://gdata.youtube.com/feeds/api/videos?q=<?php echo $q; ?>&max-results=1&v=2&alt=jsonc&orderby=relevance', function(data) {
    var output="<ul>";
    for (var i in data.data.items) {
        
		output+="<li><img src='" + data.data.items[i].thumbnail.hqDefault + "' /></li>";
		output+="<li>" + data.data.items[i].title + "</li>";
		
    }
	var output="</ul>";
	
    document.getElementById("videos").innerHTML=output;
	
	});

</script>

How you can get cover image?

http://www.domain.com/youtube-artwork.php?q=Ek%20Villain%20-%20Galliyan

song album artwork

MP3 waveforms with PHP

If you are thinking how soundcloud.com generates the waveform for sound MP3 player?

soundcloud-waveform

There are some audio processing libraries used to process MP3 files to WAV and then PNG / SVG images..

MP3 to WAV to PNG

1. LAME MP3 encoder/decoder

$ lame input.mp3 -f -m m -b 16 –resample 8 resampled.mp3 && lame –decode resampled.mp3 output.wav

2. SOX – Sound eXchange

$ sox output.wav −n spectrogram
$ sox output.wav -n spectrogram -Y 140 -l -r -o output.png

3. wav2png – Creates waveform pngs out of audio files

$ sox mp3-song.mp3 -c 1 -t wav – | wav2png -o mp3-song.png /dev/stdin
$ wav2png –foreground-color=2e4562ff –background-color=00000000 -o  output.png   input.wav

4. wavesurfer.js is a customizable audio waveform visualization, built on top of Web Audio API and HTML5 Canvas

wavesurfer.js

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/wavesurfer.js/1.4.0/wavesurfer.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/wavesurfer.js/1.4.0/plugin/wavesurfer.playlist.min.js"></script>

<div id="waveform"></div>

<script>

var wavesurfer = WaveSurfer.create({
container: '#waveform',
waveColor: '#00FF00',
progressColor: '#FF0000'
});


wavesurfer.load([MP3-File-URL]);

wavesurfer.on('ready', function () {
wavesurfer.play();
$('.waveform__duration').text( formatTime(wavesurfer.getDuration()) );
});

wavesurfer.on('audioprocess', function () {
$('.waveform__counter').text( formatTime(wavesurfer.getCurrentTime()) );
});

</script>

WaveForm generated using SOX

WaveForm Generator using SOX

Links:

https://github.com/afreiday/php-waveform-png
https://github.com/afreiday/php-waveform-svg
https://github.com/beschulz/wav2png
https://github.com/beschulz/wav2json
http://www.rarewares.org/mp3-lame-bundle.php

Audiojs.swf?playerInstance audiojs instances [%27audiojs0%27]

If you are using audio.js as MP3 player or playlist …. on some browser it causing error 403 to access SWF file with player instance

http://yourdomain.com/audiojs/audiojs.swf?playerInstance=audiojs.instances[%27audiojs0%27]&datetime=1382426114401.4087

You need to make sure you have right permission on that SWF file and check JavaScript playerInstance below….

Firefox Error

403 Forbidden

http://yourdomain.com/audiojs/audiojs.swf?playerInstance=audiojs.instances[%27audiojs0%27]&datetime=1382426114401.4087

Solution:

Just replace code (Original audio.js)

flashSource: ‘\
<object classid=”clsid:D27CDB6E-AE6D-11cf-96B8-444553540000″ id=”$1″ width=”1″ height=”1″ name=”$1″ style=”position: absolute; left: -1px;”> \
<param name=”movie” value=”$2?playerInstance=’+audiojs+’.instances[\’$1\’]&datetime=$3″> \
<param name=”allowscriptaccess” value=”always”> \
<embed name=”$1″ src=”$2?playerInstance=’+audiojs+’.instances[\’$1\’]&datetime=$3″ width=”1″ height=”1″ allowscriptaccess=”always”> \
</object>’,

with

flashSource: ‘\
<object classid=”clsid:D27CDB6E-AE6D-11cf-96B8-444553540000″ id=”$1″ width=”1″ height=”1″ name=”$1″ style=”position: absolute; left: -1px;”> \
<param name=”movie” value=”$2?playerInstance=’+audiojs+’.instances[&quot;$1&quot;]&datetime=$3″> \
<param name=”allowscriptaccess” value=”always”> \
<embed name=”$1″ src=”$2?playerInstance=’+audiojs+’.instances[&quot;$1&quot;]&datetime=$3″ width=”1″ height=”1″ allowscriptaccess=”always”> \
</object>’,

This is not permission (0755 or 0777) error of SWF file, Make sure you have valid characters on some browsers…

instances[\’$1\’] => instances[&quot;$1&quot;] 😉