Posts

Showing posts with the label c programming

Create worker in rails by sidekiq and redis

Add sidekiq to your Gemfile: Add this to your Gemfile gem 'sidekiq' Run bundle install bundle install Create worker rails g sidekiq:worker Test #will create app/workers/test_worker.rb class TestWorker   include Sidekiq::Worker   def perform(id, name)     # do something   end end Call worker without any time boundation TestWorker.perform_async(5, 'rahul') //use this anywhere from your rails app(controller, model, helpers..) Call worker within particular time period TestWorker.perform_in(5.minutes, 5, 'rahul')  //use this anywhere from your rails app(controller, model, helpers..) Call worker after specific time interval once only TestWorker.perform_at(5.minutes.from_now, 5, 'rahul')  //use this anywhere from your rails app(controller, model, helpers..) Start sidekiq on development bundle exec sidekiq Start sidekiq on production bundle exec sidekiq -d //run this first if you get some error then use second one bundle exec si

Searching on Select Box and Check Box || List

Searching on Select Box and Check Box Searching on List <input type="text" id="myInput" onkeyup="filterFunction()" placeholder="Search.." > <ul id="myulli">   <li><a href="#">abc</a></li>   <li><a href="#">xyz</a></li>  <li><a href="#">demo</a></li> <li><a href="#">testing</a></li> </ul> <script> function filterFunction(){    var input, filter, ul, li, a, i;    input = document.getElementById("myInput");    filter = input.value.toUpperCase();    div = document.getElementById("myulli");    a = div.getElementsByTagName("li");    console.log(a);    for (i = 0; i < a.length; i++) {        if (a[i].innerHTML.toUpperCase().indexOf(filter) > -1) {            a[i].style.display = "";        }

DmL command || Sql Tutorial -7

DML Command Insert Command Its used to insert the record into table example- Command for inserting single record insert into <table name> values(value1, value2...) Command for inserting multiple command at a time insert into <table name> values(&col1, &col2...., &coln); whenever you enter query like this it will ask you to like this - enter a value for column1- value1.. and then hit enter  - enter a value for column2- value2.. and then hit enter - enter a value for column3- value3.. and then hit enter Now it will show 1 row created  if you want to create more record use / and hit enter SQL> /   hit enter // it will Execute most recent query again //this will so again and so on... - enter a value for column1- value1..  and then hit enter  - enter a value for column2- value2..  and then hit enter - enter a value for column3- value3..  and then hit enter // if you will miss any value here that will be inserted as NULL value Update command Used to upda

DDL command || Sql Tutorial -6

DDL Command CREATE Command It is used to create any data base object like tables, views, indexes, sequences, synonyms , users, functions, procedures, triggers, packages and so on. HOW TO CREATE A TABLE?            syn: CREATE TABLE <table_name>             (              <colname1> DATATYPE (size),               <colname2> DATATYPE (size),                : : : :,                : : : :,             ); INSERT Command This command is used for inserting new records into the tables          Syntax:           INSERT INTO <table_name>[(col1, col2,...., col n)]           VALUES(val1, val2,.....,val n);                  NOTE:  i) If number of columns in the table and number of values inserting in to the table      are equal, then no need to specify column names while inserting records.            ii) Char, Varchar2 and date type values should be enclosed in Single Quotes.            iii) If Number of inserting values are less than the

DATATYPES in sql || Sql Tutorial -5

DATATYPES IN SQL  The data type represents the type of data to be entered into a column and Db engine can assign memory for thevalue entered into the column. There are 5 types of DataType in sql. String DataTypes Numeric DataTypes Date Datatypes Binary DataTypes LOB--Large Objects String Data Types These data types support sequence of character, digits and any symbol from keyboard. CHAR(size) It is used to store fixed length character strings. By default the size is 1 character, and max size is 2000 chars orbytes. Ex: student_id, email, address and so on VARCHAR2(size) It is used to store variable length character strings. No default size. we should specify size and max size is 4000 chars /bytes. Ex: emp names, addresses, descriptions, city names. LONG It is used to store variable length char data(similar to varchar2 data type) but max size is 2 GB NOTE: Only one long type column is allowed per a table. 1) NUMBER(Precision, [Scale])    It is used to store numb

SQL COMMANDS || Oracle SQL COMMANDS Sql Tutorial -3

Types of SQL commands 1) DDL(data definition language) commands:       Used to create or change or delete any data base objects CREATE ALTER DROP TRUNCATE RENAME 2) DML(data manipulation language) COMMANDS       Used to fetch data / enter new data/ changing existed data / deleting the data from table. INSERT  UPDATE  DELETE  TRUNCATE 3) DRL(dataretrieval language) Command     SELECT (logicalcommand) 4) DCL(DATA CONTROL LANGUAGE) COMMANDS     Used to control the access of data base objects. These commands are used by DBA (databaseadministrator) GRANT  REVOKE 5) TCL(TRANSACTION CONTROL LANGUAGE) COMMANDS      Used to save or cancel the actions/transactions made on table data. COMMIT  ROLLBACK  SAVEPOINT

Features of Sql * Plus

Features of Sql * Plus At a time only one query is allowed to execute Sql queries are not case sensitive Each query is terminated with ; ( semi colon ) SQL commands are ANSI standard ( American National standard institute )

What is sql definition(Structured query language). Sql Tutorial -2

Image
Structured query language It is a collection of pre defined commands and constructs with syntactical rules. 1. Sql is a client tool to interact with ORACLE DB /any DB 2. Sql is to be installed in to the system whenever we have installed the db software. 3. Client [Technical] requests should be submitted in the form of "Queries". 4. Queries are executed by SQL STMT EXECUTOR ( Oracle Db Engine ) 5. Queries are executed against database and output will be displayed on the Sql * plus window.

What is sql in Deep(Structured query language). Sql Tutorial -1

What is sql in Deep(Structured query language) Oracle was the first company to release a product that used the English-based Structured Query Language, or SQL. This language allows end users to extract information themselves, without using a systems group for every little report. Oracle’s query language has structure, just as English or any other language has structure. It has rules of grammar and syntax, but they are basically the normal rules of careful English speech and can be readily understood. What is SQL QUERIES It is known as data base language. It is used to communicate with any database. We can use this language constructs to write SQL QUERIES. What is SQL* PLUS SQL * PLUS is a default client tool and acts as an interface between client and database. What is SQL It is a collection of pre defined commands and constructs with syntactical rules

File inclusion in c

There are two ways to include a file in c # include ”filename” #include<filename> 1st one  is search in  current directory  and  specify list of directory  and  it also take full qualified file name. 2nd one  is search in  specify list of director y. But It has a advantage that is it can take  multiple file Name  at a time that is separated by semicolon ( ; ). Example- #include<file 1; file 2; file 3>

Connect to printer by C Program

#include<stdio.h> #include<conio.h> #include<stdlib.h> void main() { FILE *fp; char ch; fp=fopen(" full qulified file name that you want to read ","r"); if(fp==NULL) { printf("can not open file\n"); exit(1); } while((ch=fgetc(fp))!=EOF) { fputc(ch,stdprn); } fclose(fp); getch(); }

Types of constants in c

There are  two  types of constants available in c language. Primary constants  - intreger constants, real constants, character constants. Secondary constants - array, pointer, structure, union, enum. etc

Is-a and Has-a RelationShip

In java or other object oriented programming language is-a and has-a are two type of relationship under the concepts of inheritance. suppose we have three class Car. subaru. engine. subaru is a car — its a is-a  relationship  between  class  subaru and  class  car. car has a engine — its a has-a  relationship  between  class  car and  class  engine.

Exponential function in c

The exp() function computes the exponential (Euler's number) raised to the given argument. C exp() Prototype double exp(double arg); The exp(arg) takes a single argument and returns the value in type   double . — maths e^x = exp(x) [in c programming] It is defined in  <math.h> header file. EXAMPLE- #include <stdio.h> #include <math.h> int main () { double x = 12.0 , result ; result = exp ( x ); printf ( "Exponential of %.2lf = %.2lf" , x , result ); return 0 ; } Output Enter the value of x to find e ^ x : 12 Exponential of 12.00 = 162754.79

What is the difference between structure and union?

A   structure   enables us to treat a number of different variable stored at different places in memory. A  union   enables us to treat the same space in memory as a number of different variable.

Fibonacci series without using recursion?

#include<stdio.h> #include<conio.h> void printFibonacci(int n){ static int n1=0,n2=1,n3; if(n>0){ n3 = n1 + n2; n1 = n2; n2 = n3; printf("%d ",n3); printFibonacci(n-1); } } void main(){ int n; clrscr(); printf("Enter the number of elements: "); scanf("%d",&n); printf("Fibonacci Series: "); printf("%d %d ",0,1); printFibonacci(n-2); //n-2 because 2 numbers are already printed getch(); } Enter the number of elements : 15 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

Most efficient way to store flag values?

A flag is a value used to make a decision between two or more options in the execution of a program. For instance, the /w flag on the MS-DOS dir command causes the command to display filenames in several columns across the screen instead of displaying them one per line. In which a flag is used to indicate which of two possible types is held in a union. Because a flag has a small number of values (often only two), it is tempting to save memory space by not storing each flag in its own  int  or  char . Efficiency in this case is a tradeoff between size and speed. The most memory-space efficient way to store a flag value is as single bits or groups of bits just large enough to hold all the possible values. This is because most computers cannot address individual bits in memory, so the bit or bits of interest must be extracted from the bytes that contain it. The most time-efficient way to store flag values is to keep each in its own integer variable. Unfortunately, this method can w

Are bit fields portable? || Bit fields portable

Bit fields are not portable . Because  bit fields cannot span machine words , and because the number of bits in a machine word is different on different machines, a particular program using bit fields might not even compile on a particular machine. Assuming that your program does compile, the order in which bits are assigned to bit fields is not defined. Therefore, different compilers, or even different versions of the same compiler, could produce code that would not work properly on data generated by compiled older code. Stay away from using bit fields, except in cases in which the machine can directly address bits in memory and the compiler can generate code to take advantage of it and the increase in speed to be gained would be essential to the operation of the program.

what is bit field

Image
Bit fields are used in Data Structure and it is partial size member variables inside a structure. When we use number programming that time we use Bit fields. Example- Decimal to Binary Conversion In the Bit fields left most bit is called sign bit.

C program to print Armstrong numbers from 1 to 1000?

  #include<stdio.h> #include<conio.h> void main() { int i=153,n,temp,num,r,sum=0; clrscr(); while(i<=1000) { n=i; temp=n; while(n>0) { r=n%10; sum=sum+(r*r*r); n=n/10; } if(temp==sum) { printf("the armstrong number is %d\n",sum); } i++; } getch(); }