Decimal to Binary
Decimal to Octal
Tech Programming Ideas is one of the best places on the programming for programmers. Learn coding with Tech Programming Ideas tutorials. We are covered android programming, php, yii2 framework, javascript, mysql, vb.net etc.
Decimal to Octal
#include<stdio.h>
void main()
{
int a[5] = {5,6,7,8,9};
int b[5] = {1,2,3,4,5};
int i,swap;
for(i=0;i<5;i++)
{
swap = a[i];
a[i] = b[i];
b[i] = swap;
}
printf("A = ");
for(i=0;i<5;i++)
printf("%d ",a[i]);
printf("\nB = ");
for(i=0;i<5;i++)
printf("%d ",b[i]);
printf("\n");
}
#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();
}
3. Comment on the following pointer declaration?
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?
1. Integer
2.
3. ptr is a pointer to integer, p is not.
4. func(&array);
5. None of the mentioned
#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();
}
This sample demonstrates how to use the vimeo video with exoplayer
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
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.
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:
Field | Allowed Values |
---|---|
minute | 0-59 |
hour | 0-23 |
Day of the month | 1-31 |
month | 1-12 or JAN-DEC |
Day of the week | 0-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
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
In advance template there is already a file yii. And there is no need to run it as php, it is Linux script.
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;
run it as
yii test