Friday, January 31, 2020

Autocomplete using jquery javascript snippet



//please correct the angular brackets
<  link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<  script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js">
<  script src="http://code.jquery.com/jquery-1.9.1.js">

< script  >
  $(function() {
var contentvalues=[{"state":"AL","value":"Autauga","zipcode":"36003","county":"01001"},{"state":"AL","value":"Baldwin","zipcode":"36507","county":"01003"}]

var jsonObj = [];
$.each(contentvalues, function(index) {
        item = {}
        item ["state"] = contentvalues[index].state;
        item ["value"] = contentvalues[index].value + ' - ' + contentvalues[index].state;
        item ["zipcode"] = contentvalues[index].zipcode;
        item ["county"]= contentvalues[index].county;
        item ["countyname"]= contentvalues[index].value;
        jsonObj.push(item);

    });



    $( "#searchbox" ).autocomplete({
      minLength: 3,
      source: jsonObj,
      focus: function( event, ui ) {
        $( "#searchbox" ).val( ui.item.value  );
        return false;
      },

      select: function( event, ui ) {
var state=ui.item.state;
var county=ui.item.county;
var zipcode=ui.item.zipcode;
var countyname=ui.item.countyname;

       var url='https://www.yoursite.com/?state=' +  state + '&countyname=' + countyname + '&zipcode='+ zipcode + '&county=' + county;
   window.location.href = url;
        return false;

      }

  });
  });

</  script >

< form action="search" method="post" >
< input  name="searchbox" id="searchbox"   />
<   /form   >

Thursday, January 30, 2020

Wednesday, January 29, 2020

handy aws amazon rekognition snippets

These are handy amazon rekognision snippets. Make sure you have loaded the aws sdk from amazon for php

I have developed such applications and utilized these stuffs in php and python. Its pretty straight forward.

Snippets below!

Create collection

$result = $client->createCollection([
    'CollectionId' => 'mycollectionid',
]);

Results

[
    'CollectionArn' => 'aws:rekognition:us-west-

2:13234342323:collection/mycollectionid',
    'StatusCode' => 200,
]

Index faces
$result = $client->indexFaces([
    'CollectionId' => 'myphotos',
    'DetectionAttributes' => [
    ],
    'ExternalImageId' => 'myphotoid',
    'Image' => [
        'S3Object' => [
            'Bucket' => 'mybucket',
            'Name' => 'myphoto',
        ],
    ],
]);


$result = $rekognitionClient->searchFacesByImage([
                    'CollectionId' => ''.$collection_id.'', // REQUIRED
                    'FaceMatchThreshold' => 25.0,
                    'Image' => [ // REQUIRED
                            'S3Object' => [
                                'Bucket' => 'facetracking',
                                'Name' => 'test.jpg',
                                'Key' => 'test.jpg',
                                'Version' => 'latest',
                            ],
                    ], 'MaxFaces' => 2,
                ]);



Video

$result = $client->startFaceDetection([
    'ClientRequestToken' => '',
    'FaceAttributes' => 'DEFAULT|ALL',
    'JobTag' => '',
    'NotificationChannel' => [
        'RoleArn' => '', // REQUIRED
        'SNSTopicArn' => '', // REQUIRED
    ],
    'Video' => [ // REQUIRED
        'S3Object' => [
            'Bucket' => '',
            'Name' => '',
            'Version' => '',
        ],
    ],
]);



$result = $client->getFaceDetection([
    'JobId' => '', // REQUIRED
    'MaxResults' => ,
    'NextToken' => '',
]);
GetFaceDetection returns an array of detected faces (Faces) sorted by the

time the faces were detected.



$result = $client->getFaceSearch([
    'JobId' => '', // REQUIRED
    'MaxResults' => ,
    'NextToken' => '',
    'SortBy' => 'INDEX|TIMESTAMP',
]);



make you android phone a webcam or ipcamera

you can easily make your old/new android phone a webcamera

Step 1. Install DroidCam Wireless Webcam app on your Android smartphone
Step 2. Install the DroidCam Client app on your Windows PC
or  you can directly run the browser cam address on browser directly

Also if the webcam is on its also detected in other softwares as long as windows client is on! I have tested it using the windows client and also via web.


Search Google for droidcam wireless webcam apk and you will get the download link easily. It hardly takes 5 minutes to setup

Ref:
https://www.digitalcitizen.life/turn-android-smartphone-webcam-windows

Saturday, January 18, 2020

simple csv reader in python

import csv
datafile = open('touristspot-final.csv', 'r')
myreader = csv.reader(datafile)

for row in myreader:
    print(row[0], row[1], row[2])

Please make sure to install csv package in python.

install nvm in udumbu


apt-get update
apt-get install build-essential libssl-dev

curl https://raw.githubusercontent.com/creationix/nvm/v0.25.0/install.sh | bash

Ref:
https://github.com/creationix/nvm/releases (see version latesT)
Ref: https://www.liquidweb.com/kb/how-to-install-nvm-node-version-manager-for-node-js-on-ubuntu-12-04-lts/
Ref:
https://www.sitepoint.com/quick-tip-multiple-versions-node-nvm/

Install Jquery module in your IONIC 3 app

Install Jquery module in your IONIC-3 app,

npm install jquery --save
npm install @types/jquery
Import JQuery in HomePage.ts

import * as $ from "jquery";

Use $ to call jquery methods.


ngAfterViewInit(){
    $(document).ready(function(){
        alert('JQuery is working!!');
    });
}