Monday, 22 July 2019

Using Google Translate API (English to Punjabi)


Friday, 8 February 2019

HTML5/Javascript Canvas Animation


Falling Ball (Javascript / HTML5 Canvas)


Tuesday, 29 January 2019

Function to find Prime Numbers upto n (in Javascript)

function getPrime(n){
var primes=[];
var c;

if(n>1){
primes[0]=2;
if(n>2){
primes[1]=3;
c=2;
for(var i=5;i<=n;i+=2){
var notprime=false;
for(var j=1;j<primes.length;j++){
if(i<primes[j]*primes[j]) break;
if(i%primes[j]==0){
notprime=true;
break;
}

}
if(!notprime){
primes[c]=i;
c++;
}
}
}
}

return primes;
}

Saturday, 26 January 2019

Function to find duplicate values in an array (Javascript)

function findDuplicate(arr){
var arr1=[];   //for processing array
var arr2=[]; // for storing result
var c1; // for arr1
var c2=0; // for arr2
var dupli;
var length=arr.length;

while(length>0){
c1=0;
dupli=false;
arr1=[];
for(var j=1;j<length;j++){
if(arr[0]!=arr[j]){
arr1[c1]=arr[j];
c1++;
}
else{
if(!dupli){
arr2[c2]=arr[j];
c2++;
dupli=true;
}
}
}
arr=arr1;
length=arr.length;
}
return arr2;
}

alert('Result is : ' + findDuplicate([1,2,3,4,5]));

Saturday, 2 June 2018

JSON Writer in VB6 (Fast & Efficient)

'Please read disclaimer before using this code.

 Option Explicit
   
    Dim s As String                 ' Used for Storing JSON String
    Dim jsep As String              ' Used for Comma
    Const jencl = """"              ' Used for Double Quotes
    Public Enum JDataTypes
        JString
        JNumber
        JObject
    End Enum
           
   
    Public Sub addJArray(code As String, ar As Collection, JType As JDataTypes)
        Dim obj As Variant
        Dim Count As Integer
        If s <> "" Then jsep = ","
        s = s & jsep & jencl & code & jencl & ":["
        Count = 0
        For Each obj In ar
            If s <> "" Then jsep = ","
            If Count = 0 Then
                Count = 1
            Else
                s = s & jsep
            End If
            If JType = JString Then
                s = s & jencl & obj & jencl
            ElseIf JType = JObject Then
                s = s & obj.generateJSON
            Else
                s = s & obj
            End If
        Next
        s = s & "]"
    End Sub
   
    Public Sub addJString(code As String, value As String)
        If s <> "" Then jsep = ","
        s = s & jsep & jencl & code & jencl & ":" & jencl & Replace(value, """", "\""") & jencl
    End Sub
   
    Public Sub addJInteger(code As String, value As Integer)
        If s <> "" Then jsep = ","
        s = s & jsep & jencl & code & jencl & ":" & value
    End Sub
   
    Public Sub addJDouble(code As String, value As Double)
        If s <> "" Then jsep = ","
        s = s & jsep & jencl & code & jencl & ":" & value
    End Sub
   
    Public Sub addJObject(code As String, value As JSONWriter)
        If s <> "" Then jsep = ","
        s = s & jsep & jencl & code & jencl & ":" & value.generateJSON
    End Sub
   

    Public Function generateJSON() As String
        generateJSON = "{" & s & "}"
    End Function