Skip to content

Instantly share code, notes, and snippets.

View ramsunvtech's full-sized avatar
💭
Full Stack Developer (Java, React, React Native)

Venkat.R ramsunvtech

💭
Full Stack Developer (Java, React, React Native)
View GitHub Profile
@ramsunvtech
ramsunvtech / nodejs-vhost.js
Created November 28, 2015 14:30
Vhost in NodeJS
var connect = require('connect'),
serveStatic = require('serve-static'),
vhost = require('vhost')
var mailapp = connect()
// add middlewares to mailapp for mail.example.com
// create app to serve static files on subdomain
var staticapp = connect()
@ramsunvtech
ramsunvtech / apicluster.js
Created November 28, 2015 14:34
Api Cluster Usage in NodeJS
var http = require('http'),
ApiCluster = require('apicluster');
ApiCluster
.defaults({
name: 'mydefault',
config: {
'employee': 'emp',
'details': 'details',
@ramsunvtech
ramsunvtech / index.html
Created November 29, 2015 02:17
Chat with Web Socket
<html>
<head>
<title>Social Message Board</title>
<link rel="stylesheet" type="text/css" href="css\style.css">
</head>
<body>
<div id="message-board">
<div id="messages"></div>
<form id="post-form">
<input type="text" id="message" />
@ramsunvtech
ramsunvtech / BubbleSort.js
Last active January 19, 2016 08:54
Bubble Sort in Javascript
function bubbleSort(arr){
var len = arr.length;
for (var i = len-1; i>=0; i--){
for(var j = 1; j<=i; j++){
if(arr[j-1]>arr[j]){
var temp = arr[j-1];
arr[j-1] = arr[j];
arr[j] = temp;
}
}
@ramsunvtech
ramsunvtech / SelectionSort.js
Last active January 19, 2016 08:54
Selection Sort in Javascript
function selectionSort(arr){
var minIdx, temp,
len = arr.length;
for(var i = 0; i < len; i++){
minIdx = i;
for(var j = i+1; j<len; j++){
if(arr[j]<arr[minIdx]){
minIdx = j;
}
}
@ramsunvtech
ramsunvtech / InsertionSort.js
Created January 19, 2016 07:49
Insertion sort
function insertionSort(arr){
var i, len = arr.length, el, j;
for(i = 1; i<len; i++){
el = arr[i];
j = i;
while(j>0 && arr[j-1]>toInsert){
arr[j] = arr[j-1];
j--;
@ramsunvtech
ramsunvtech / MergeSort.js
Last active January 19, 2016 08:54
Merge Sort in Javascript
function mergeSort(arr){
var len = arr.length;
if(len <2)
return arr;
var mid = Math.floor(len/2),
left = arr.slice(0,mid),
right =arr.slice(mid);
//send left and right to the mergeSort to broke it down into pieces
//then merge those
return merge(mergeSort(left),mergeSort(right));
@ramsunvtech
ramsunvtech / QuickSort.js
Last active November 5, 2021 11:09
Quick Sort in Javascript
function quickSort(arr, left, right){
var len = arr.length,
pivot,
partitionIndex;
if(left < right){
pivot = right;
partitionIndex = partition(arr, pivot, left, right);
@ramsunvtech
ramsunvtech / HeapSort.js
Last active October 16, 2020 19:41
Heap Sort in Javascript
function heapSort(arr){
var len = arr.length,
end = len-1;
heapify(arr, len);
while(end > 0){
swap(arr, end--, 0);
siftDown(arr, 0, end);
}
@ramsunvtech
ramsunvtech / Gruntfile.js
Created April 13, 2016 03:50
Grunt Watch
module.exports = function( grunt ) {
'use strict';
// Load grunt tasks automatically
require( 'load-grunt-tasks' )( grunt );
grunt.loadTasks( 'tasks' );
// Time how long tasks take. Can help when optimizing build times
require( 'time-grunt' )( grunt );