Friday, June 7, 2019

CSS tricks

Mixed paint in background:
background: linear-gradient(to right, #b6e358, #38b143)


Grid view:
display: grid;
grid-template-columns: auto auto;
justify-content: space-around;

Thursday, March 9, 2017

Javascript, How to find object types

In some cases we can't use typeof to find object of Object and object of Array.

You can use Object.prototype.toString to find object types in Javascript


Monday, March 6, 2017

Git frequent usage commands

git create new branch
git checkout -b 'branchName'

git switch to existing branch
git checkout branchName

git Tag with version
git tag -a v0.0.1 90a5435 -m ' Your Message'
git push origin v0.0.1

v0.0.1 - Version that you want to create
90a5435 - Commit id of the branch the you want to tag

git delete Tag
remote
git push --delete origin tagname

local
git tag --delete tagname

Git merge

git checkout master
git pull origin master
git merge test
git push origin master

Git delete branch
git push origin --delete branchname
git branch -d branchname

Thursday, February 2, 2017

PHP simple google OAuth in Linux

Steps involved!

1. Create a parent directory php-google-signin
2. Download google-api-php-client  library from Github to parent dir
3. Obtain OAuth 2.0 client credentials from the Google API Console. Save the json file as key.json  in to parent dir
4. Set your redirect URL in google api key console

Create a file index.php

<?php
    require_once __DIR__.'/google-api-php-client-2.1.1/vendor/autoload.php';
    date_default_timezone_set('asia/kolkata');
    session_start();

    // to find localhost and production server https
    if ($_SERVER['SERVER_NAME'] == "localhost") {
        $protocol = "http://";
    }else{
        $protocol = "https://";
    }
    $redirect_uri = $protocol . $_SERVER['HTTP_HOST'] . "/index.php";
    $client = new Google_Client();
    $client->setAuthConfigFile('key.json');
    $client->setRedirectUri($protocol . $_SERVER['HTTP_HOST'] . "/index.php");
    $client->setScopes('email'); // You want to retrieve email and domain name
    

// on logout
    if (isset($_REQUEST['logout'])) {
      unset($_SESSION['id_token_token']);
    }

// once you get code after auth success
    if (isset($_GET['code'])) {
      $token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
      $client->setAccessToken($token);
      $_SESSION['id_token_token'] = $token;
      header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
    }
    if ( !empty($_SESSION['id_token_token']) && isset($_SESSION['id_token_token']['id_token']) ) {
      $client->setAccessToken($_SESSION['id_token_token']);
    } else {
      $authUrl = $client->createAuthUrl();
    }
    // success
    if ($client->getAccessToken()) {
      $token_data = $client->verifyIdToken();

// print all the data related after auth
      print_r($token_data)
    }
?>

Wednesday, January 18, 2017

Convert sec to hh:mm:sec in Javascript


Convert seconds to hour:minute:seconds in javascript

This pattern can be used to calculate call duration

Number.prototype.calltimer = function () {
    var sec_num = parseInt(this, 10);
    var hours   = Math.floor(sec_num / 3600);
    var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
    var seconds = sec_num - (hours * 3600) - (minutes * 60);
    if (hours   < 10) {hours   = "0"+hours;}
    if (minutes < 10) {minutes = "0"+minutes;}
    if (seconds < 10) {seconds = "0"+seconds;}
    return hours+':'+minutes+':'+seconds;
}

var time = 120
time.calltimer()

will give you "00:02:00"


Wednesday, November 2, 2016

linux find and cp/mv to a path

If you want to find for a particular string/date and then do list/copy/move, then below command will help you out

Find .wav files created on Dec 30th
 find . -type f -name "*.wav" -newermt 2016-12-30 ! -newermt 2016-12-31 -exec ls -l {} \;

If above cmd shows proper output then try
find . -type f -name "*.wav" -newermt 2016-12-30 ! -newermt 2016-12-31 -exec cp  {} /dest/path/ \;


Wednesday, October 19, 2016

Node render html file and pass json data to html

Create a server.js file with below code
var express = require('express'),
app = express(),
        http = require('http'),
        httpServer = http.createServer(app);

app.use('/',express.static(path.join(__dirname, '/public')));
app.set('view engine', 'ejs'); // send HTML files
app.engine('html', require('ejs').renderFile);

app.get('test',function(req, res){
 res.render('hello.html',{ 'id' : 'w8m4r9vdfm' });
});

httpServer.listen(8000,"0.0.0.0",function(){
    console.log('http on 8000');
});

Folder structure:
app
  server.js
  public/hello.html

CSS tricks

Mixed paint in background: background: linear-gradient(to right, #b6e358, #38b143) Grid view: display: grid; grid-template-columns: a...