Menus

Saturday, 23 April 2022

Largest of three numbers in C

 #include <stdio.h>

int main()

{

 int x,y,z;

 clrscr();

 printf("Enter three numbers :");

 scanf("%d,%d,%d",&x,&y,&z);


 if(x>y)

 {

   if(x>z)

     printf("Largest value : %d ",x);

   else

     printf("Largest value : %d ",z);

 }

 else

 {

   if(y>z)

     printf("Largest value : %d",y);

   else

     printf("Largest value : %d",z);

 }


 getch();

}

Saturday, 5 March 2022

C language MCQ (Multiple Choise Questions)

Art of C Programming


1 . Address stored in the pointer variable is of type __________
 
 
 
 

 

2. "*" is called as ___________
 
 
 
 


3. Comment on the following pointer declaration?

     int *ptr, p;
 
 
 
 


4. Which of the following are correct syntaxes to send an array as a parameter to function

 
 
 
 


5. Which of the following is not possible in C?

 
 
 
 


 

Answers

1. Integer

2.  

3. ptr is a pointer to integer, p is not.

4. func(&array);

5. None of the mentioned



Wednesday, 23 February 2022

Printing Pattern in C | Inverted Half Pyramid

 


#include<stdio.h>

void main()

{

int i,j,r=6;

clrscr();


  for(i=1;i<=r;i++)

  {

   for(j=r;j>=i;j--)

   {

     printf("*");

   }

   printf("\n");

  }


getch();

}





Friday, 24 September 2021

How to integrate vimeo videos to android app

 

Vimeo-Player Using Exoplayer   


This sample demonstrates how to use the vimeo video with exoplayer

 


 

Prerequisites

 


Source Code

 

activity_main.xml

 

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">


<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="300dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Play"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

/>

</androidx.constraintlayout.widget.ConstraintLayout>


MainActivity.java

package com.logiclab.vimeo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.ui.PlayerView;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.TextHttpResponseHandler;
import com.vimeo.networking.Configuration;
import com.vimeo.networking.VimeoClient;


import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import cz.msebera.android.httpclient.Header;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

private static final String VIMEO_ACCESS_TOKEN = "access token";
private static final String VIMDEO_ID = "Your video id";

private PlayerView playerView;
private SimpleExoPlayer player;

//Release references
private boolean playWhenReady = false; //If true the player auto play the media
private int currentWindow = 0;
private long playbackPosition = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//Reference exoplayer view
playerView = findViewById(R.id.video_view);
Button playBtn = findViewById(R.id.button2);

playBtn.setOnClickListener(this);

//Build vimeo configuration
configVimeoClient();

} //onCreate


private void createMediaItem(String url) {
MediaItem mediaItem = MediaItem.fromUri(url);
player.setMediaItem(mediaItem);
}


private void initializePlayer() {

//To play streaming media, you need an ExoPlayer object.
//SimpleExoPlayer is a convenient, all-purpose implementation of the ExoPlayer interface.
player = new SimpleExoPlayer.Builder(this).build();
playerView.setPlayer(player);

callVimeoAPIRequest();

//Supply the state information you saved in releasePlayer to your player during initialization.
player.setPlayWhenReady(playWhenReady);
player.seekTo(currentWindow, playbackPosition);
player.prepare();
}


private void callVimeoAPIRequest() {

String videolink = "https://player.vimeo.com/video/" + VIMDEO_ID +"/config";

AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
//params.put("key", "value");
// params.put("more", "data");
client.get(videolink, params, new TextHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, String res) {
// called when response HTTP status is "200 OK"
try {

JSONObject jsonObject = new JSONObject(res);
JSONObject req = jsonObject.getJSONObject("request");
JSONObject files = req.getJSONObject("files");
JSONArray progressive = files.getJSONArray("progressive");

JSONObject array1 = progressive.getJSONObject(1);
String v_url=array1.getString("url");

Log.d("URLL ",v_url);

createMediaItem(v_url);

} catch (JSONException e){
e.printStackTrace();
}
}

@Override
public void onFailure(int statusCode, Header[] headers, String res, Throwable t) {
// called when response HTTP status is "4XX" (eg. 401, 403, 404)
}
}
);
}

private void configVimeoClient() {
Configuration.Builder configBuilder =
new Configuration.Builder(MainActivity.VIMEO_ACCESS_TOKEN) //Pass app access token
.setCacheDirectory(this.getCacheDir());
VimeoClient.initialize(configBuilder.build());
}

@Override
public void onClick(View v) {
player.setPlayWhenReady(true);
}

@Override
public void onStart() {
super.onStart();
initializePlayer();
}

}


Android Manifest.xml

set permissions

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />



build.gradle(:app)

add

compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
 
 dependencies
//Vimeo Network
implementation "com.vimeo.networking:vimeo-networking:1.1.3"
//Full ExoPlayer library
implementation 'com.google.android.exoplayer:exoplayer:2.12.0'
//Android Async Http Client
implementation 'com.loopj.android:android-async-http:1.4.9' 






 

 

 

 

 

 https://guides.codepath.com/android/Using-Android-Async-Http-Client


Sending a Network Request

Now, we just create an AsyncHttpClient, and then execute a request specifying an anonymous class as a callback:

import com.loopj.android.http.*;
import cz.msebera.android.httpclient.Header;

AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
params.put("key", "value");
params.put("more", "data");
client.get("http://www.google.com", params, new TextHttpResponseHandler() {
        @Override
        public void onSuccess(int statusCode, Header[] headers, String res) {
            // called when response HTTP status is "200 OK"
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, String res, Throwable t) {
            // called when response HTTP status is "4XX" (eg. 401, 403, 404)
        }	
    }
);

This will automatically execute the request asynchronously and fire the onSuccess when the response returns a success code and onFailure if the response does not.

 

Wednesday, 23 June 2021

Cron jobs

 

Cron Jobs in Ubuntu


Cron is a time-based job scheduling. Cron runs in the background and tasks scheduled with cron, referred to as “cron jobs,” are executed automatically, making cron useful for automating maintenance-related tasks.


Commands

crontab -e : Edit your cron jobs.
crontab -l : List the all your cron jobs.
crontab -r : Delete the current cron jobs.


The schedule component of the syntax is broken down into 5 different fields, which are written in the following order:

FieldAllowed Values
minute0-59
hour0-23
Day of the month1-31
month1-12 or JAN-DEC
Day of the week0-6 or SUN-SAT

Format like this

minute hour day_of_month month day_of_week command_to_run

 To define the time you can provide concrete values for

 minute (m), hour (h), day of month (dom), month (mon),

 and day of week (dow) or use '*' in these fields (for 'any').# 

 Notice that tasks will be started based on the cron's system

 daemon's notion of time and timezones.


Examples

Every minutes

* * * * * php /var/www/html/yiitest2.0.39/yii test

you can run a backup of all your user accounts at 5 a.m every week with:

0 5 * * 1 tar -zcf /var/backups/home.tgz /home/

12 * * * * - Run the command 12 minutes after every hour

0 4 * * * - Run the command every day at 4:00 AM.

*/15 * * * * - Run the command every 15 minutes


Cronjob in Yii2





Create console application

In advance template there is already a file yii. And there is no need to run it as php, it is Linux script.

Create cron service command

Create a controller in console/controllers

I have created as TestController.php

<?php

namespace console\controllers;

use yii\console\Controller;

/**
 * Test controller
 */
class TestController extends Controller {

    public function actionIndex() {
        echo "cron service runnning";
    }

    public function actionMail($to) {
        echo "Sending mail to " . $to;
    }

}

This controller should be use the console controller name space

use yii\console\Controller;

How to run it

run it as

yii test


Execute PHP Script Automatically at a Specified Time








Tuesday, 20 April 2021

C program to Count the Number of Digits





#include<stdio.h>


void main(){


int n,count=0;


printf("Enter an number ");

scanf("%d",&n);


while(n>0)

{

  

  n=n/10; 

  count++;

 

}


printf("Number of digits %d", count);

 


}


 

Saturday, 17 April 2021

Printing Pattern in C


Output



Source Code

 

#include<stdio.h>

void main()

{

int i,j,k,rows=7;

clrscr();

  for(i=1;i<=rows;i++)

  {

   //print blank space

   for(j=1;j<=rows;j++)

   {

     if((i+j)<=rows)

       printf(" ");

     else

       printf("*");

   }

   printf("\n");

  }

  getch();

}


Video