Menus

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




Wednesday, 24 February 2021

Android code for Displaying a video with VideoView



By the help of MediaController and VideoView classes, we can play the video files in android.

 - Dsiplaying loacal videos


- Create an application that displays a video clip, which is stored locally 

in our applications “res” directory


- Create a row directory

      Paste video file to raw directory


-  Add VideoView to your UI


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">

<VideoView
android:id="@+id/videoView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java
package com.lb.videoplay;

import androidx.appcompat.app.AppCompatActivity;

import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity extends AppCompatActivity {

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

VideoView videoView = (VideoView) findViewById(R.id.videoView);

//Attach a media controller to video view
MediaController mediaController = new MediaController(this);
videoView.setMediaController(mediaController);
mediaController.setAnchorView(videoView);

//Specify the location of media file
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.favicon);

videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();



}
}





Android playing video from url with video view






previous tutorial we are discuss about

how to play video on videoview from local file


First set to internet permission


  your manifest must include the permissions:

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


Then and to video url


Check this code


package com.lb.videoplay;

import androidx.appcompat.app.AppCompatActivity;

import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity extends AppCompatActivity {

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

VideoView videoView = (VideoView) findViewById(R.id.videoView);

//Attach a media controller to video view
MediaController mediaController = new MediaController(this);
videoView.setMediaController(mediaController);
mediaController.setAnchorView(videoView);

//add your video URL
Uri uri = Uri.parse("Add URL here..");


videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();



}
}



videoView can't open this video Online video


Create file res/xml/network_security_config.xml


<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>



New in the AndroidManifest.xml file under application:



android:networkSecurityConfig="@xml/network_security_config"











Sunday, 4 October 2020

LAMP install on Ubuntu

 

Install php 7 and apache 2


sudo apt update && upgrade
sudo apt-get install php



Install MySql and phpMyAdmin


sudo apt-get install mysql-server mysql-client
Then install phpmyadmin
sudo apt-get install phpmyadmin -y 


Then check phpmyadmin

The requested URL /phpmyadmin was not found on this server



sudo -H gedit /etc/apache2/apache2.conf

add following line to end of apache config file

Include /etc/phpmyadmin/apache.conf

Then restart apache:

/etc/init.d/apache2 restart
More details - https://askubuntu.com/questions/668734/the-requested-url-phpmyadmin-was-not-found-on-this-server






Solutions for Access Denied For User Localhost on Ubuntu Linux

How to change MySQL 'root' password