Javascript string functions

Knowing string functions is always useful and saves time to Google the correct function. Hence I have prepared list of most useful, usually used string functions.

First of all definition of String

In computer programming, a string is traditionally a sequence of characters, either as a literal constant or as some kind of variable.

In JavaScript context it inherits prototype of String object.
A string can be any text inside double or single quotes.

List of almost all kinds of string manipulations.

Creating a String:
var name = new String (“sachin”)
Or simply
var name = “sachin”

Changing a String
replace replaces first occurrence only.

Change case

// Custom title case function

var fullName = name + ” ” + “Gaikwad”
var fullName = name.concat(” Gaikwad”)

Stuff String or Char
// No direct method to stuff string/char in string

Stat- counting


name.split(” “).length

Char at position
name.charAt(0) //s

Check Substring
name.includes(“chi”) // true

Get first occurrence index or last occurrence index of other string resp.

Extract another string 
name.slice(2) // chin

Trim whitespace
name.trim() // removes whitespace ” sachin ” to “sachin”


Export/Import from/to other data type

name.split(” “) // gives array
nameArray.join() // gives string

parseInt(“123”)// string to integer
parseFloat(“12.3”) // string to float
“”+123 // number to string



Auto Slug field in Django

While designing database, many times we need slug field which we populate from some other field of the same model.

We can set auto slug field so that we don’t need to code in order to populate slug field while insert or update.

You can use the field AutoSlugField from module django-autoslug.

1. Install module django-autoslug.
pip install django-autoslug

2. Import in models file where your model exists.
from autoslug import AutoSlugField

3. Set field in model
title = models.CharField(max_length=100)
slug = AutoSlugField(populate_from=’title’,default=None)

Install Jitsi Meet on ubuntu 14.04

To install jitsi meet we are going do setup for following components

  1. Jitsi Video-Bridge (Software video-bridge)
  2. Jitsi Jicofo (Component mandatory for jitsi conference)
  3. Prosody ( XMPP Server )
  4. Nginx (Web Server)
  5. Jitsi Meet (Web application – to which the end user will interact. )


Java dependency

Check if jdk installed on your ubuntu, it must be > 1.7

java -version
javac -version

Both above must be greater than 1.7

  1. To install jdk
sudo add-apt-repository ppa:webupd8team/java -y
sudo apt-get update
sudo apt-get install oracle-java8-installer
sudo apt-get install oracle-java8-set-default

Check again with same commands

java -version
javac -version

If versions are > 1.7 we are ready to go ahead.

If you have java installed already, but it points to some older version, you can select proper version using following

sudo update-alternatives --config java
sudo update-alternatives --config javac



Difference between JVM, JRE, JDK
Install JDK
Java alternatives in ubuntu
Check which JRE you are using

Install Prosody – XMPP server

apt-get install prosody

Configure it
1. Open file “/etc/prosody/conf.avail/”
2. Add following lines to config file

VirtualHost ""
    authentication = "anonymous"
    ssl = {
        key = "/var/lib/prosody/";
        certificate = "/var/lib/prosody/";
    modules_enabled = {

VirtualHost ""
    authentication = "internal_plain"

admins = { "" }

Component "" "muc"
Component ""
    component_secret = "YOURSECRET1"
Component ""
    component_secret = "YOURSECRET2"

3. Set above file in use

sudo ln -s /etc/prosody/conf.avail/ /etc/prosody/conf.d/

4. Generate certificates

sudo prosodyctl cert generate

5. Create conference user

sudo prosodyctl register focus YOURSECRET3

6. Restart prosody

sudo prosodyctl restart

Prosody XMPP server
Prosody configurations


Install Jitsi Video Bridge

Go to following URL

Check which version is good for your ubuntu 32/64 bit, using following

uname -a

If it says “x86_64” at the end, it is 64 bit.

unzip jitsi-videobridge-linux-{arch-buildnum}.zip

(If you dont have unzip installed, you can “sudo apt-get install unzip”)

Make .sip-communicator directory in user home directory

  1. cd ~
  2. mkdir .sip-communicator
  3. nano
  4. add lines

    to file and save it (Ctrl + o, Enter, Ctrl + x)

Run jitsi video bridge

  1. cd /path/to/extracted-folter-of-jistsi-video-bridge
  2. ./ --host=localhost --port=5347 --secret=YOURSECRET1

To auto start jitsi video bridge

/bin/bash /root/jitsi-videobridge-linux-{arch-buildnum}/ --host=localhost --port=5347 --secret=YOURSECRET1 </dev/null >> /var/log/jvb.log 2>&1



Check if your ubuntu is 32bit/64bit
Install and run jitsi video bridge

Install Jicofo

Install ant

sudo apt-get install ant

Clone jicofo repository

git clone
cd jicofo/lib

Download maven task pom and jar file from following location|ga|1|a%3A%22maven-ant-tasks%22

POM file


Jar file


Rename jar file

mv remotecontent\?filepath\=org%2Fapache%2Fmaven%2Fmaven-ant-tasks%2F2.1.3%2Fmaven-ant-tasks-2.1.3.jar maven-ant-tasks-2.1.3.jar

Remove ~/.m2/

sudo rm -R ~/.m2/

Change directory to jicofo

cd /path/to/jicofo-cloned-repo/
mvn -U clean package -DskipTests

( If maven not installed,  sudo apt-get install maven)

ant -lib lib dist.{os-name}

For 64 bit ubuntu use lin64 as {os-name}
(Here {os-name} is one of the ‘lin’, ‘lin64’, ‘macosx’, ‘win’, ‘win64’)

cd dist/{os-name}

(for ubuntu cd dist/linux)

cd jicofo-linux-x64-build.SVN/

Run Jicofo

./ --secret=YOURSECRET2 --user_name=focus --user_password=YOURSECRET3




ant dist class path

Build fail issue for maven dep


Nodejs dependency

Install nodejs using nvm

curl -o- | bash

exit the terminal and repoen it

Check the latest stable nodejs version

nvm install 4.4.1

(4.4.1 is the latest stable at this time, you may select another)

Use version

nvm use 4.4.1

sudo apt-get install build-essential


Install nodejs using nvm




Install Jitsi Meet


Clone jitsi-meet repository

git clone

cd /jitsi-meet

npm install


Edit the configuration file /config.js

var config = {
 hosts: {
 domain: '',
 muc: '',
 bridge: ''
 useNicks: false,
 bosh: '//', // FIXME: use xep-0156 for that
 desktopSharing: 'false' // Desktop sharing method. Can be set to 'ext', 'webrtc' or false to disable.
 //chromeExtensionId: 'diibjkoicjeejcmhdnailmkgecihlobk', // Id of desktop streamer Chrome extension
 //minChromeExtVersion: '0.1' // Required version of Chrome extension

Deploy jitsi-meet using nginx

sudo apt-get install nginx

cd /etc/nginx/sites-available

add new file

add following code

server_names_hash_bucket_size 64;

server {
    listen 80;
    # set the root
    root /path/to/jitsi-meet;
    index index.html;
    location ~ ^/([a-zA-Z0-9=\?]+)$ {
        rewrite ^/(.*)$ / break;
    location / {
        ssi on;
    # BOSH
    location /http-bind {
        proxy_pass      http://localhost:5280/http-bind;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $http_host;

cd /etc/nginx/sites-enabled
ln -s ../sites-available/
Restart sudo service nginx restart

Browse to the and you should be ready to use jitsi-meet !!!

jitsi meet nginx deploy

Create Postgres DB from command line in Ubuntu 14.04

On ubuntu shell,

sudo su postgres
createdb mydb -O dbownername

If it says “dbownername” role does not exist, you can create it with

createuser dbownername


If above commands does not work, you may be missing following

sudo apt-get update
sudo apt-get install postgresql postgresql-contrib


for more information  createdb manual  createuser manual


Cancel earlier http requests in angularjs

When we want data from last http request, data from earlier request (if any) need to be canceled.

// Code goes here

var canceller = $q.defer();
if(earlierRequest && earlierRequest.canceller)
  // Cancel earlier requests
var earlierRequest = $http({
  // Data received
earlierRequest.canceller = canceller;


Copy MongoDB database from remote host to your machine

You can use the mongo console to copy the database from one host (machine) to another host (machine). It is usually helpful when we are copying large database.

Start the mongo console

  1. by typing command “mongo”
  2. run following commands to copy database
    use admin
       copydb: 1,
       fromdb: "test",
       todb: "records",
       fromhost: ""

    For more information Mongo Documentation

Create Application Launcher on Desktop in ubuntu

  1. Create “your-application.desktop” file on desktop.
  2. Write follwing lines in that file
[Desktop Entry]
Comment=Back up your data with one click

3. Give executable permission to this file

4. Start using it

For More info UnityLaunchersAndDesktopFiles

Install Symfony 1.x on ubuntu 14.04

Follow link for installation,

In my case there were problems after installations

  1. 500 server error  – Create Virtual Host to fix this error – follow each step in guideline given.
  2. Build schema XSL and PHP accelerator error –
    1. for XSL  try “sudo apt-get install php5-xsl
    2. for PHP accelerator try “sudo apt-get install php-apc