Open Side Menu Go to the Top

11-01-2018 , 11:18 PM
Can you link to the on-the-fly code example?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
150% up to $2,000 Welcome Bonus on CoinPoker
Join the action now
Daily Rewards ? Splash Pots ? CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
11-02-2018 , 12:33 AM
Dunno what really worked for anyone. You know how SO is.

http://pdfkit.org/docs/images.html

The docs say you can do it and I should probably try base64 encoding or decoding something.

Quote:
Adding images to PDFKit documents is an easy task. Just pass an image path, buffer, or data uri with base64 encoded data to the image method along with some optional arguments.
But they don't have an example other than from the filesystem.

https://stackoverflow.com/questions/...ges-from-a-url

I may have done something wrong, but I basically tried to copy this other than using https

Code:
http.get('YOUR URL TO GET THE IMAGE').on('response', function(res)
    res.setEncoding('binary');
    res.on('data', function(chunk){
       buffer += chunk;
    });
    res.on('end', function(){

    fs.writeFile('PATH TO SAVE IMAGE', buffer, 'binary', function (err) {
        if (err){
           throw err;
        }
        doc = new PDFDocument({ size: 'LETTER or any other size pdfkit offer' });
        doc.image('PATH TO SAVE IMAGE', 0, 0, { fit: [WIDTH, HEIGHT] })
        .fontSize(10).text('text 1', 100, 170)
        .fontSize(16).text('text 2', 60, 120)

    }); //After file is download and was write into the HD will use it

}).end(); //EO Downloading the file
Here's another one

https://stackoverflow.com/questions/...-url-to-pdfkit

Code:
request({ url, encoding: null }, (error, response, body) => {

    if (!error && response.statusCode === 200) {
        pdf.pipe(fs.createWriteStream('out.pdf'));

        var img = new Buffer(body, 'base64');
        pdf.image(img, 0, 0);

        pdf.end();
    }
});
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2018 , 12:36 AM
The first one is doing what I described. fs.writeFile saves the downloaded image to file, then doc.image reads the file as input. As I suspected, the first argument to doc.image() is just the path to the saved file.

The second one might accomplish what you want. pdf.pipe() is the key I think as it sets up a buffer to the file, which accepts the buffer from the request. Think of a stream running from the response - all the way to the output file.

The idea with streams/buffers is that they can handle a lot of data from a request and still function - because they're only passing along small chunks at a time and never trying to store the whole response in memory at once.

Last edited by suzzer99; 11-02-2018 at 12:45 AM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2018 , 12:50 AM
Oh yeah - on the first.

I tried something like the second one, but not too hard because I don't think it works for https and it will have to be https. I tried to redo it with https.request. Probably should work and I'll try again - but I'm too sleepy now and I have to get up early.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2018 , 12:54 AM
https shouldn't make a difference. That's all handled between the browser and website.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2018 , 10:31 AM
I guess this is partly luck that I've only had a few relatively minor incidents in construction but generally computer work is more painful. In the past month or so I've had fingers, elbows, hip, eye, headache all hurt bad enough that it is a little hard to sleep.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2018 , 03:29 PM
Microservices architecture question.

Background: Our app is using an AWS Cognito user pool for identity management and authentication. We might be sharing this pool with other apps in the future. Cognito only lets you add up to 25 custom fields, and once you add one you can't remove it or change the name. Also you can't easily migrate users from one pool to another.

The primary source of record for the user data is a back end CRM system which we share with other groups. C# lambdas will interact with it, supplying a CRM user id. On the CRM system side there are components kind of like stored procedures that the C# lambdas call.

However neither of these is a good choice to store our local app/user-specific data, like say mapping the authenticated user to said CRM id. And assuming more things, like user preferences, in the future that would be specific to just our app. Cognito seems like a bad choice to store this because of the limitations mentioned.

So the upshot on that is we probably need some kind of local user database to handle user data. I'm thinking a dynamodb with one lambda that acts as gatekeeper? For read only, we could automatically tack on the user info to all other lambda invocations (kind of like how node tacks on user session to all request objects). But if a lambda needs to update user info. then it would have to save to this gatekeeper lambda. This feels like maybe an anti-pattern, but I can't think of any other way that makes sense.

Any thoughts much appreciated.

Last edited by suzzer99; 11-02-2018 at 03:34 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2018 , 03:33 PM
My electrical/solar work was cancelled today due to the LADWP guy not leaving a meter spot - neither here nor there, but I'm here.

I think it's a network problem. I've gotten an error:

Code:
events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: connect ECONNREFUSED 127.0.0.1:443
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14)
I'm running node on my local windows machine. I'm not offline or anything. I'm successfully using another api that I included by doing this:

Code:
const ****** = require("*****-api")({ key:process.env.******_KEY });
and using their functions I'm getting a response from the internet.

But, when doing the https.request and giving it the url, is it looking on 127.0.0.1?

In the latter example from my post above I'm telling it url
is maps.googleapis.com/maps/api/staticmap?alotofparameters
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2018 , 03:46 PM
I thought you meant you were grabbing the image from an https url somewhere.

127.0.0.1 is your local machine. Https isn't going to work to your local machine unless you install an SSL cert - which is a pain. Although maybe not as much anymore. Others on this forum might know an easy way to set it up.

I would skip HTTPS if you're just testing against your local machine. Test it when you host this somewhere.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2018 , 03:50 PM
Quote:
Originally Posted by suzzer99
I thought you meant you were grabbing the image from an https url somewhere.

127.0.0.1 is your local machine. Https isn't going to work to your local machine unless you install an SSL cert - which is a pain. Although maybe not as much anymore. Others on this forum might know an easy way to set it up.

I would skip HTTPS if you're just testing against your local machine. Test it when you host this somewhere.
Your first understanding was right. I'm trying to get a static image from google's map api. If I put the url in my browser I get the image and if I change the parameters I get a different image. I just want to get that from the https.request in my node code with node running on my local machine.

But, based on that error message, I wonder if node is looking at my machine even though I gave google's url. Maybe that's not the problem though.

And also it doesn't have to do with https. I did a http version for an image on http from somewhere and got the same error, but with 127.0.0.1:80 instead of 127.0.0.1:443.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2018 , 03:50 PM
Yeah 127.0.0.1 is always local machine - equivalent to localhost (unless you remap it).

:443 is the correct port for HTTPS - although browsers hide it in the url bar (same as 80 for HTTP).
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2018 , 04:34 PM
Quote:
Originally Posted by microbet
I guess this is partly luck that I've only had a few relatively minor incidents in construction but generally computer work is more painful. In the past month or so I've had fingers, elbows, hip, eye, headache all hurt bad enough that it is a little hard to sleep.
I think you're a little older than me, but none of this should be happening. Especially within only a month!

I'd suggest to take a good look at the ergonomics of your coding situation, and check prescription for glasses. Turn the brightness way down on your monitor(s). Use dark mode maybe.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2018 , 05:20 PM
someone tell me what this outputs. I just took a stupid coding test for a job, and Im pretty sure the answer wasnt one of the multiple choice options

** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2018 , 05:28 PM
just off the top of my head, wouldn't it be 16 8 4 2 1 ?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2018 , 05:30 PM
oh wait, there is an assignment in the if statement.

So just "world."

when using equality operators in if statements, we use the convention:

if (5 == i)
/* do something */

because it catches this type of typo.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2018 , 05:32 PM
bah, god damn it.

I can't even blame being rushed cuz I stared at it for 5 minutes trying to figure out wtf I was missing *sigh*

I cant believe I ****ed that up, pretty sure I bombed the rest of the test too. It was a bunch of stupid questions on what I can only assume are from SCRUM or AGILE or whatever stupid ****ing acronym methodolgy is in vogue and I'm guessing is all nonsense you can learn in an afternoon and is completely meaningless in terms of your hireability. I was banking on getting all the code questions right....bahbahbah

Last edited by Alobar; 11-02-2018 at 05:38 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2018 , 05:40 PM
Deliberately sized small to bias against the olds.

Squints... lol bit arithmetic. jmakin seems right though.

Does anyone actually use bit arithmetic?

Edit: lol I noticed that assignment instead of evaluation too - but figured it was just a C++ thing. Any linter should also warn about that.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2018 , 05:45 PM
We use bit arithmetic but we program basically right next to bare metal. I had a bit arithmetic problem on my take home test for my job.

But alobar is right, the correct answer is not there - it's actually "compiler warning."

Lol you don't want to work for any place that gives a test like that. That's not testing any actual programming ability other than attention to detail. It's a skill set that comes in handy for some things but not every single programming discipline.

I mean I'm guessing it's testing your ability to understand how a c-based compiler evaluates boolean statements? There's a little of that in the for loop too, with (; i; /*bit arithmetic*/)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2018 , 05:48 PM
Quote:
Originally Posted by Alobar
bah, god damn it.

I can't even blame being rushed cuz I stared at it for 5 minutes trying to figure out wtf I was missing *sigh*

I cant believe I ****ed that up, pretty sure I bombed the rest of the test too. It was a bunch of stupid questions on what I can only assume are from SCRUM or AGILE or whatever stupid ****ing acronym methodolgy is in vogue and I'm guessing is all nonsense you can learn in an afternoon and is completely meaningless in terms of your hireability. I was banking on getting all the code questions right....bahbahbah
don't beat yourself up. Two years of CS undergrad is basically filled entirely with "tricky" questions like these, so you learn very early on to look suspiciously at any test code given to you.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2018 , 05:54 PM
If they want to give "Tricky" c questions why don't they give something actually relevant and actually a little tricky:

Code:
#include <stdio.h>
int array[] = { 1, 2, 3, 4, 5 };
#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))

main()
{
    int d = -1;

    if (d <= TOTAL_ELEMENTS)
         printf("Foo\n");
    else
         printf("Bar\n");

}
What is output and why?

the bug here is extraordinarily easy to make.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2018 , 05:59 PM
Quote:
Originally Posted by jmakin
don't beat yourself up. Two years of CS undergrad is basically filled entirely with "tricky" questions like these, so you learn very early on to look suspiciously at any test code given to you.
yeah I imagine I'll never fail another similar question again, just sucks Im making these on job interview tests not some dumb midterm.

It's for a Java job too, I haven't even looked at c++ code in years, so that kind of sucked too.

The only two problems that were actually writing code and not multiple choice, were so ****ing stupid they were pointless, it was like CS 110 intro to programing exercises.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2018 , 06:36 PM
Quote:
Originally Posted by microbet
I believe I could successfully do that, but this should be possible and isn't saving to filesystem and then reading it pretty bad? It's not like this is going on Instagram or anything, but (should the code not be rejected) it will be in production and potentially used in many places.
This worked. I had the stream getting closer to working and not getting the 127.0.0.1 error and then fighting with not recognizing the image format, which I assume does have to do with encoding/headers or something. I need to fundamentally understand images better - but I want to get through this for now. I guess just give the image file a unique name so it can't get messed up with another image file.

I have to rewrite some stuff because the image generation and pdf creation are asynchronous, but that would have come whether it was a stream or a file.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2018 , 10:49 PM
Quote:
Originally Posted by jmakin
What is output and why?

the bug here is extraordinarily easy to make.
This is honestly a bit of a guess, but sizeof() returns unsigned values. If -1 gets cast to unsigned it'll be the maximum unsigned value of whatever unsigned type it is. (sizeof returns size_t, the actual width of which varies by compiler/archtecture)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2018 , 10:58 PM
Quote:
Originally Posted by RustyBrooks
This is honestly a bit of a guess, but sizeof() returns unsigned values. If -1 gets cast to unsigned it'll be the maximum unsigned value of whatever unsigned type it is. (sizeof returns size_t, the actual width of which varies by compiler/archtecture)


Yea. I thought it was really tricky, for me, but my clump mate got it within like two seconds

We have a C convention where we only use uint64_t
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2018 , 11:10 PM
Quote:
Originally Posted by jmakin
Yea. I thought it was really tricky, for me, but my clump mate got it within like two seconds

We have a C convention where we only use uint64_t
I also got it pretty quickly, but I code firmware in C and C++ for a living.

Using uint64_t everywhere probably works fine in a desktop environment, but in an embedded system not so much.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
150% up to $2,000 Welcome Bonus on CoinPoker
Join the action now
Daily Rewards ? Splash Pots ? CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

      
m