Code Snacks
***********some coding tips***********
Friday, 15 March 2019
Codes 4 U: How to Invert an SVG image using CSS ?
Monday, 10 December 2018
How to Check whether a string is match with Patterns or regex(Regular Expression) using JavaScript ?
Checking for Patterns or regex(Regular Expression) using JavaScript
Here I would like to share a method for check whether a string is match with a regex(regular expression) using Java Script. This method will Output a boolean result(true or false).
The Method is ,
regex.test('string to check')
eg :- cosider a regix /^([a-z0-9]{5,})$/ (a string which contains number or letters and the minimum number of elements should be 5)
the code will be ,
/^([a-z0-9]{5,})$/.test('string to check');
Out Put :-
/^([a-z0-9]{5,})$/.test('abc1'); //will return false
/^([a-z0-9]{5,})$/.test('abc12'); //will return true
/^([a-z0-9]{5,})$/.test('abc123'); //will return true
Thursday, 6 December 2018
How to Select Immediate Next HTML Element Using JavaScript?
How to Select Immediate HTML Element Using JavaScript?
Assume that you have two HTML tags and they are immediate neighbours , both of them are on the same line and if the first element have an id you then you can access the second element by using the first elements id.Here I will explain a method using JavaScript.Before that you should know about on which elements you can apply this and on which elements you can't.Conside the example below
tag1
tag2....../tag2
tag3....../tag3
tag4....../tag4
/tag1
On the above example you cannon't apply this methode for tag1 and tag2 ,because they are on different level (ie, here tag2 is child of tag1).You also not able to apply this method to tag2 and tag4 ,because even they are same level they are not immediate elements.Here you can apply this methode for tag2 and tag3 or tag3 and tag4 ,because they are on same level and immediate neighbour elements .
So the Technique is to use JavaScript nextSibling Preperty.The Syntax is given below , assume that the id of tag1 is 'first element',then you can select tag2 by using the following code
Syntax:
document.getElementById('first-element').nextSibling
Wednesday, 5 December 2018
How to check the string only contain Numbers using Java Script ?
Here I'm sharing some methods for text boxes(number type text boxes) to ensure that they only contain numbers.
The Primary and most basic method is to add an attribute type with value number to your input text box.
ie, <input type='number'/>,
this is very effective but on some occasions which will not give the proper output.
Here I would like to share a method using Java Script ,
to check a string is number you can use the following code
var isNum = /^\d+$/.test(value);
if(isNum)
alert(value + 'is a number');
else
alert(value + 'is not a number');
here 'value' is the input test sample,if the input string only contains the digits this code will alert that is a number.else which alerts that is not a number
eg:-
value = 5 output :- 5 is a number
value = jkljk output :- jkljk is not a number
value = h5ht output :- h5ht is not a number
value = #%$@ output :- #%$@ is not a number
which also detect the float number as not a number
ie,
value = 2.5 output :- 2.5 is not a number
so in case of float numbers we use a different script
var isFloatNumber = /^\d+\.\d+$/.test(value);
if(isFloatNumber){
alert(value + 'is a float number');
}
else {
alert(value + 'is not a float number');
}
eg:-
value = 2.5 output :- 2.5 is a float number
value = 5 output :- 5 is not a float number
value = jkljk output :- jkljk is not a float number
value = h5ht output :- h5ht is not a float number
value = #%$@ output :- #%$@ is not a float number
Sunday, 2 April 2017
Artificial Neural Network
Saturday, 1 April 2017
Comparison Computer Neural Network v/s Biological Neural Network
- Biological Network is Slow in Processing Information ,It will Take a few Nano Seconds to Process an Information.
- But a Computer Neural Network Take in Millie Seconds Range thus Computer Process Information a Million Time Faster.
- Biological Neural Network Can Perform Parallel Operations Massively.
- Most Programs have Large no of Instructions and They Process Sequentially in Conventional Computer.
- A Biological Neural Network have Large no of Computing Elements & Computing is not Restricted with in a Neuron.(no of Neurons in brain 10^11,total no of Neurons about 10 ^ 15.
- It will Give the Brain to Understand & Perform the Complex Pattern Reorganization can't be Possible by Computer.
- Biological Neural Networks Store Information in Strengths of Interconnection.
- In Computer the Information is Stored in Memory ,Which is Addressed by Its Location
- In Computer the new Information stored by Overriding old Information.
- But in Biological Neural Networks the new Information is Stored by Adjusting Strengths ,this Information in the Brain is Adaptable.
- Biological Neural Network Exhibits the Fault Tolerance Since the Information is Distributed.
Features of Biological Neural Network
Robustness or Fault Tolerance : -
Ability to Deal With A Variety of Situations :-
Friday, 31 March 2017
Different Computer Graphics Operations on Cube
To compile the program, type
"g++ cube.cpp -lGL -lGLU -lglut"
========================KEY BOARD CONTROLS============================
ESC : Close the Program
Arrow keys : Rotate the Cube
Shift + Arrow keys : Translate the cube
Ctrl + Up arrow : Expand the cube in all the 3 directions
Ctrl + Down arrow : Shrink the cube in all the 3 directions
========================================================================
Program : -
Priority Scheduling Using C
#include <stdio.h>
#include <string.h>
struct well
{
int prio[2];
char name[10];
}d[10];
void main()
{
int n,k,i,j,r,l,m,q,e,f,v,s;
char a[50],b[50],c[50];
printf("enter no of data elements");
scanf("%d",&k);
printf("enter data and priority");
for(i=0;i<k;i++)
{
printf("data...priority");
scanf("%d",&d[i].name);
scanf("%d",&d[i].prio);
}
printf("enter the no of symbols");
scanf("%d",&n);
printf("enter the symbols");
q=strlen(a[i]);
while(q>0)
{
for(i=0;i<n;i++)
{
scanf("%c",&a[i]);
for(i=0;i<n;i++)
for(j=0;;)
{
for(l=0;l<10;l++)
if(a[i]==d[l].name)
{
r=d[l].prio;
break;
}
s=i+1;
for(l=0;l<10;l++)
if(a[s]==d[l].name)
{
m=d[l].prio;
break;
}
b[j]=0;
j++;
b[j]=a[i];
j=j+1;
if(r>m)
{
b[j]=0;
j++;
}
else if(r<m)
{
b[j]=1;
j++;
}
else
{
b[j]=2;
j++;
}
e=j;
}
e=e-1;
for(j=0;j<e;j++)
{
if(b[j]=='1')
{
v=j;
f=j;
while(b[f]!='0')
{
f--;
}
v=v+1;
for(j=f;v<e;j++,v++)
{
b[j]=b[v];
}
}
}
}
}
if(q==0)
printf("accepted");
else
printf("rejected");
}
Tuesday, 10 January 2017
Grid Properties
- grid :- generates a block level grid. Define the element as grid container abd establishes a new grid formatting context for it's contents.
- Inline-grid:- generates an inline-level grid.
- Sub-grid:-if your grid container itself a grid item ,you can use this property .
- grid-template-columns:- grid-template-columns used to set the width for the grid items.Syntax:- grid-template-columns : <track-size> | <line-name> <track-size>
- grid-template-rows:- grid-template-rows used to set the height for the grid items.Syntax:- grid-template-rows : <track-size> | <line-name> <track-size>
- grid-row-gap:- which is used to specify the gap between grid columns.
- grid-column-gap:- which is used to specify the gap between grid rows.
- grid-gap:-Which is used to specify grid-row-gap and grid-column-gap in common.
|
Browser
|
Indirect
Support
|
Direct
Support
|
|
IE
|
(using
-ms) 10
|
|
|
Fire
Fox
|
|
52
|
|
Chrome
|
|
57
|
|
Safari,Android
|
No
Support
|
No
Support
|
|
Edje
|
(using
-ms) 12
|
|
|
Opera
|
|
43
|
