Hipchat API /code - hipchat

I want to send some json to hipchat upon error. well raw json is not very readable in the hipchat.
the hipchat client support /code and I want to have similar output using the API. i tried many ways (I already implemented one library in php that using the same class and html element that /code is generating and send it to the API) but it comes with it's own problems.
first the API has 100,000 character limit. there was some cases that my pretty print exceeded the limit(bcs of adding many html and css to the message).
also it's not easy to port it to other project. I created that library in PHP, now i want to integrate a .netCore application and I need to write the whole things again.
[Update 1]
it turned out that hipchat API support this by setting the header as Content-Type:text/plain and send the content with /code in front of the message
/code {yourcontent}
this way message will with color yellow. is there any way to set the color?

I could achieve this by sending json and setting "message_format":"text" previously it was set to html, that's why /code didn't work before

Related

Yii2 framework - reduce not used memory (files)

I want to set up new project in Yii 2.0.6 framework, which I will use for simple REST calls only (making requests and getting responses from DB).
I have downloaded the framework from their official site (basic pack from Archive file). Now initially I have empty project that initially take place of ~24MB. I'm not sure if this is a good idea, because every time I will make some request (from mobile devices), it will probably load all these 24MB from the server. Is it how it works?
Is there a way for setting up the Yii 2.0.6 project with minimal size on the disk? I really need everything to be optimized and to load as minimal code as possible.
PHP files will only be rendered in the server side where only required files will be loaded and used and all what your mobile is going to receive are the Json outputs if what you are going to build is a REST api.
To check the size in byte of a json file that your mobile is going to receive, you can use curl as described in Yii2 REST docs and add grep Content-Length to the request :
curl -i -H "Accept:application/json" "http://YOUR_RESOURCES_URL" | grep Content-Length
or you can use the network tab of a navigator dev tools instead :
here the json file's size is 392B and it took 179 ms to receive it from server
Also remember that by default Yii is installed with dev environment settings, there is optimizations to do before publishing the product in order to optimize time responses. check this for more details.
It is also good practice to use a tool like gzip to compress data before sending to mobile as described here : JSON REST Service: Content-Encoding: gzip
Of course not. Yii only load the required classes (and files) on the fly, thanks to the autoloading mechanism.
A few components are preloaded during the bootstrap phase (and you can add or remove some of them in the configuration file). Other classes won't clutter your memory as long as you don't use them.

Parse.com Mixed Content Error

I'm creating a web application using parse and have found that in order for a user to authenticate I need to make all requests using HTTPS. I'm able to switch this over and get it to work correctly, but when I do I get all kinds of mixed content errors because I'm retrieving PFFile objects which only return a non-secure URL.
This wouldn't even be a huge concern with Chrome or Safari but of course IE needs to present a message to the user and block all this content. Are there any potential work arounds? Why can't parse just put a setting in the app to enable files to be served from a secure url? This seems completely ridiculous. How do people get around this? Are you completely avoiding the use of PFFile?
Replace http:// with https://s3.amazonaws.com/.
So if you start with this:
http://files.parsetfss.com/b05e3211-bf8b-.../tfss-fa825f28-e541-...-jpg
The final url will look something like this:
https://s3.amazonaws.com/files.parsetfss.com/b05e3211-bf8b-.../tfss-fa825f28-e541-...-jpg

how to use Ajax to get content from JSON files dynamically in DART?

I know how to use JSON in dart also communicating with a server using the HttpRequest API from the dart:html library and parsing JSON data using the dart:convert !!https://www.dartlang.org/articles/json-web-service/
I am looking for Dynamic content loading using Ajax asynchronous methods or calls in DART! ..
like .. the web page need to load content dynamically if there is any change or update in JSON files in server! ..
And how to do this in Angular Dart!?
There's no way to be notified when something changes on the server without either a) polling for changes (this can be pretty wasteful) or b) having the server notify you.
For (a), you could create a periodic timer that fetches the JSON or checks whether it's been updated (you'd need some way of checking this with the server).
A better fit would be something like Web Sockets, with the server able to push your JSON to the client whenever it changes. However, this is quite an architecture change from pulling JSON from the server, because you would need to be holding web sockets open between the server and all clients that have the page loaded, so the server can send the data to them all whenever it changes.
There are some samples of using Web Sockets on the Dart site; but bear in mind you'll need something on the server, this won't work if you only have access to the client.

How to detect the last Docpad render pass?

Im currently writing a small Docpad plugin to output a documents contentRenderedWithoutLayouts into a separate .json file next to the .html version for loading it via an ajax request later.
The plugin works by overriding Baseplugin's render: (opts) -> method and doing a few checks whether we're rendering a document and to html.
I now noticed that this method gets called multiple times for some documents, which seems to be render pass related. So how can I detect the final render pass per document to avoid writing the .json multiple times per render?
Many Thanks
--
Edit:
found the answer after another look at Docpads events list: http://docpad.org/docs/events
The writeAfter event is the right place to get the final data and have the output directory tree set up so I can put my .json files next to the .html.
In case you're interested find the plugin here: https://github.com/field/docpad-plugin-jsonfragment
Another approach to this would be to use the serverExtend event, and write a router that detects if it is an ajax request (existance of the IS_XHR header) and then sends the necessary json data from that. This would require your hosting platform to support node.js as you'll be using the docpad server.

Servlet send image from server and save in client

I'm new and just developing on J2EE.
I am modifying an existing application (an OpenSource project).
I need to save an image on a client sent by the server, but I do not know how.
This activity must be done in a transparent manner without affecting the existing operation of the application.
From the tests done I get this error:
java.lang.IllegalStateException: getWriter () has Already Been Called for this response.
How should carry out this task, according to your own opinion?
How do I save on the client, locally, the image?
Update:
Thanks for the answers.
My problem is that:
the image is generated on the server, but not for direct client request (there is no link to click on web page), the picture is composed using other services on the Internet.
reconstruct the image on the server.
This image must be sent to the client to be saved locally.
so I'd like it to appear a window where you assign the destination image
plus I'd like the rest of the application were not affected by this activity.
The application is yet on production.
Thank you very much for your response.
From the tests done I get this error: java.lang.IllegalStateException: getWriter () has Already Been Called for this response.
In other words, you were trying to mix the binary data of the image with the character data of the HTML output, or you were trying to do this in a JSP instead of a Servlet. This is indeed not going to work. You need to send either the image or the HTML page exclusively in response to fully separate requests.
In your JSP/HTML page just have a link to the image, like so:
click to download image
Then, in a servlet listening on an url-pattern of /imageservlet/*, you just get the image as InputStream from some datasource (e.g. from local disk file system as FileInputStream) and then write it to the OutputStream of the response the usual Java IO way.
You only need to set at least the Content-Disposition response header to attachment to make sure that the client get a Save As popup dialogue, else it will be displayed straight in the browser. Setting the Content-Type and Content-Length are also important so that the browser knows what the server is sending and can predict how long the download may take.
response.setHeader("Content-Type", getServletContext().getMimeType(file.getName()));
response.setHeader("Content-Length", String.valueOf(file.length()));
response.setHeader("Content-Disposition", "attachment;filename=\"" + file.getName() + "\"");
You can find complete basic servlet example in this article.
Note: you cannot control where the client would save the image, this would be a security hole. This way websites would be able to write malicious files on client's disk unaskingly.
Update: as per your update, there are two options:
You need to let the client itself fire two HTTP requests (I've answered this in your subsequent question)
Create a client side application which does all the task directly at the client side and then embed this in your webpage, for example a Java Applet. With an applet you have full control over the client environment. You can execute almost all Java code you'd like to execute and you can write files to disk directly without asking client for the location to save. You only need to sign the applet by a 3rd party company or the client needs to confirm a security warning before running.
Its up to the browser how all types of output are handled. Web pages are given a content type of html which the browser understands and ends up rendering ass a page that we can see. Images are given content type of image/jpeg etc which are rendered as images when in a page etc. To force a download prompt one needs to use a content type of a binary file rather than that of an image so the browser forces the download rather than shows the image. To ensure this use something like "application/octetstream"... i cant recall exactly but its easy to google for.

Resources