Wednesday, 26 September 2018

Restlet example

https://stackoverflow.com/questions/19341019/how-to-convert-a-json-type-input-of-a-restlet-request-to-a-pojo



@Put
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Device b(Device device) {
    // Do something with the POJO!!!
    return device;
}

Tuesday, 25 September 2018

throw exception in php 7

<?php
echo 'Current PHP version: ' . phpversion();
try {
    $num=1;
    echo $num;
    if($num) {
    throw new Exception("This is an exception");
    }
} catch(Throwable $e) {

    echo $e->getFile();
}

?>

Monday, 24 September 2018

How to remove repeated elements from ArrayList?

https://beginnersbook.com/2014/10/how-to-remove-repeated-elements-from-arraylist/

java read json file

https://crunchify.com/how-to-read-json-object-from-file-in-java/



import java.io.FileReader;
import java.util.Iterator;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
/**
* @author Crunchify.com
*/
public class Main {
    @SuppressWarnings("unchecked")
    public static void main(String[] args) {
        JSONParser parser = new JSONParser();
        try {
            Object obj = parser.parse(new FileReader(
                    "./sample.json"));
            JSONObject jsonObject = (JSONObject) obj;
            String name = (String) jsonObject.get("Name");
            String author = (String) jsonObject.get("Author");
            JSONArray companyList = (JSONArray) jsonObject.get("Company List");
            System.out.println("Name: " + name);
            System.out.println("Author: " + author);
            System.out.println("\nCompany List:");
            Iterator<String> iterator = companyList.iterator();
            while (iterator.hasNext()) {
                System.out.println(iterator.next());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
{
    "Name": "crunchify.com",
    "Author": "App Shah",
    "Company List": [
        "Compnay: eBay",
        "Compnay: Paypal",
        "Compnay: Google"
    ],
    "ERR404":{
      "errorCode":"404",
      "message":"requested file not found"
    }
}

Friday, 21 September 2018

java directory strature import

https://stackoverflow.com/questions/22806638/importing-in-java-from-a-different-directory-inside-a-directory

Thursday, 20 September 2018

aws permission code

{
 "Version": "2008-10-17",
 "Statement": [
  {
   "Sid": "AllowPublicRead",
   "Effect": "Allow",
   "Principal": {
    "AWS": "*"
   },
   "Action": "s3:GetObject",
   "Resource": "arn:aws:s3:::MYBUCKETNAME/*"
  }
 ]
}


{
  "Version":"2008-10-17",
  "Statement":[{
        "Sid":"Allow Public Access to All Objects",
         "Effect":"Allow",
           "Principal": {
             "AWS": "*"
          },
       "Action":["s3:GetObject"],
       "Resource":["arn:aws:s3:::example.com/*"
      ]
    }
  ]
}

Tuesday, 18 September 2018

Monday, 17 September 2018

return data from curl as json

https://stackoverflow.com/questions/24939326/php-curl-request-data-return-in-application-json


curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));

curl example

http://codular.com/curl-with-php

curl library

http://docs.guzzlephp.org/en/stable/quickstart.html#sending-requests

Friday, 14 September 2018

Tuesday, 11 September 2018