Open Side Menu Go to the Top
Register
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

08-21-2019 , 12:03 AM
Code:
module.exports.selectiveMerge = (defaultObj, newObj) => {
  const merged = Object.assign({}, defaultObj, newObj);
  for (let propName in merged) {
    if (defaultObj[propName] === undefined) delete merged[propName];
  }
  return merged;
};
I ended up doing this non-elegantness. I like the Set idea.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-23-2019 , 07:31 AM
You just need to extend a Set to add a method that only updates values and doesn't add keys when they don't exist.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-24-2019 , 08:40 PM
You have a user table with a username that has a constraint to be unique. If someone registers with that same username and you want to warn them that the username is taken do you:

(a) Check if the name is taken and put up the message if it is

(b) Read the warning code from the database

I’ve generally done (a), because it seems foolproof, but it also seems inefficient. Is trusting that the db will always throw the same error code for this error a problem? (mysql, well, actually MariaDB, but same diff I think)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-24-2019 , 08:42 PM
1) seems like its a table scan but i dont think performance really matters here
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-24-2019 , 09:07 PM
You’d have an index so you wouldn’t need to do a table scan. I think relying on the database is fine.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-24-2019 , 09:22 PM
Quote:
Originally Posted by jjshabado
You’d have an index so you wouldn’t need to do a table scan. I think relying on the database is fine.
If I follow this, you're basically saying either way is fine?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-24-2019 , 09:57 PM
Yeah, I think either way is fine. I’d probably do the insert and catch the exception.

Honestly, I feel like people worry about these types of situations where the difference isn’t meaningful one way or the other.

I guess technically the query the database approach is worse because you’d have a race condition where a username was created after your check but before you inserted the name. But again, probably never matters.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-24-2019 , 10:07 PM
I always default to “simplest” solutions and 2) seems simplest. I didnt even think about the race condition thing. Jj is way right anyway though these decisions rarely matter. If you’re servicing millions of users though - definitely 2)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-24-2019 , 10:45 PM
You have to check the insert result no matter what, so IMO I'd worry about that first. If you want to get fancy later, check before inserting. On the sites I work on, we do both, because from a UI perspective you want to give a user feedback on their actions ASAP, i.e. before they click submit.

Something to think about is that with some databases, failed inserts increment the table id, I ran into this myself. I found a case where it was way faster to insert and see if it failed than it was to check first. I ended up doing billions of failed inserts, which incremented the table id past it's limit, even though the table only held a few million rows. The proper solution ended up using mysql's "update if exists" instead of "ignore insert failure if exists"
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-24-2019 , 11:17 PM
Thanks all and check before submit is something I hadn't thought of and should maybe do.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-25-2019 , 11:45 AM
To further optimize it, look into bloom filters. It’s some fun stuff.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-25-2019 , 03:09 PM
Quote:
Originally Posted by Barrin6
To further optimize it, look into bloom filters. It’s some fun stuff.
I looked that up and its interesting, but seems like I'd need the database software to implement that and not my code. Maybe developing some database software that uses that?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-27-2019 , 02:35 PM
Is anyone good at RXJS and Observables? Normally I dont have trouble but this one is throwing me off.

Its really old code and the issue is that the subscriptions is not being managed properly so that there are 2 API calls in quick succession which results in the first call being (cancelled) and the 2nd call working.

So functionally, everything still works but its not very good code. If you were to open the network tab of the browser, everytime you navigate to the page it will say (cancelled) for th==

Heres the culprit, which is in the constructor of the component. So navigate to this page and this code runs.

Code:
filteredMyObjects$ = this.stateService.myObjects$
    .pipe(
      tap((myObjects) => {
        if (!myObjects || !myObjects.length) {
          this.stateService.requestMyObjects();
        }
      }),
      filter((myObjects) => myObjects && (myObjects.length !== 0))
    );
So this.stateService.requestMyObjects() dispatches the action which the epic (or effect) is listening for. The issue is that action gets dispatched twice in quick succession.

The epic is using a switchMap. So when the first action kicks off an API call, the second action occurs so quickly that the first action has not completed and the switchMap causes the first API call to (cancel). This can be "fixed" in the epic by changing the switchMap to a concatMap but I want to fix it so that the above code is only dispatching the action a single time.

its kind of weird bc I want to first check if the list is empty, and if it is, dispatch the action. then I want to wait until the list is not empty to set the value.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-28-2019 , 02:45 PM
Quote:
Originally Posted by Victor
Is anyone good at RXJS and Observables? Normally I dont have trouble but this one is throwing me off.
I wouldn't consider myself an expert exactly but here's a solution I wrote a little while ago for a similar problem. This is a service method that hits an API endpoint to fetch details about the logged in user. So it's used in a variety of places but I really only want it to make a single request and then cache the result.

The style is a bit different than what you're doing but it should be translateable

Code:
    
public getCurrentUserDetails() {
    // if current user record exists, return it
    if (!_.isNil(this.currentUser)) {
        return of(this.currentUser);
    }

    // if an HTTP request to fetch the user is in progress, return that
    if (!_.isNil(this.currentUserRequest)) {
        return this.currentUserRequest;
    }

    // Otherwise, generate a new multicastable HTTP request
    // publishReplay(1) together with refCount() allows multiple subscribers
    // to consume the observable while only generating a single HTTP request
    this.currentUserRequest = this.http.get<IJsonObject>(this.currentUserUrl).pipe(
        map((response) => this.setCurrentUserDetails(response)),
        tap({
            complete: () => {
                this.currentUserRequest = null;
            }
        }),
        catchError((response: HttpErrorResponse) => throwError(response.error)),
        publishReplay(1),
        refCount()
    );

    return this.currentUserRequest;
}
setCurrentUserDetails() does a few things but only relevant here is that it populates this.currentUser.

publishReplay and refCount are the RxJS operators that make this work the way you want, i.e. it allows a second caller to consume the same observable as the first.

Consumers of the service just call:

Code:
userService.getCurrentUserDetails().subscribe(...)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-28-2019 , 07:09 PM
Anyone ever use grouper for permission/role/group management? My boss wants me to evaluate it.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-28-2019 , 11:20 PM
i'm sure how to look up this concept to read up on best practices.

when you have data following a certain schema that's generated by various teams in your company, and let's say they tag their stuff with `source_id=101` or whatever, what mechanisms can you employ to ensure someone doesn't use a source_id they're not supposed to and mess up everyone's data?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-08-2019 , 12:43 PM
Joining new team on Monday. So I have to learn Erlang. It's been a while since I had to learn a new language for everyday use. How do you guys go about it? Read books? Write small programs? Dive into the existing code base?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-08-2019 , 12:47 PM
Check out udemy. I really liked them for learning AWS.

As for books I've always loved cookbooks. Once you have a bunch of languages under your belt - for the most part you just need examples of how to do stuff in a new language.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-08-2019 , 02:25 PM
Quote:
Originally Posted by muttiah
Joining new team on Monday. So I have to learn Erlang. It's been a while since I had to learn a new language for everyday use. How do you guys go about it? Read books? Write small programs? Dive into the existing code base?


Write an I/O stream program. Take in a bunch of data and write it somewhere else. That teaches you the gist of most languages.

If it’s more high level and a pointer is like a foreign concept, like JS, I like to look at code/project examples with the help of a beginner (or intermediate) book.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-08-2019 , 02:28 PM
Erlang reminds me
Of haskell. Good luck. Ignore my previous post.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-08-2019 , 02:29 PM
Quote:
Originally Posted by muttiah
Joining new team on Monday. So I have to learn Erlang. It's been a while since I had to learn a new language for everyday use. How do you guys go about it? Read books? Write small programs? Dive into the existing code base?
i've always found it harder than everyone says it is, so maybe that will give you some encouragement when you're struggling.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-08-2019 , 03:40 PM
Quote:
Originally Posted by iversonian
i've always found it harder than everyone says it is, so maybe that will give you some encouragement when you're struggling.
Lol. Dot character to end a statement is a kinky twist.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-09-2019 , 04:56 PM
Pluralsight has been good for me but nothing is better than actually writing code that does something. If I was learning for a job tgen of would just wait until they gave me a story card or business requirement.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-09-2019 , 10:23 PM
Quote:
Originally Posted by Victor
Pluralsight has been good for me but nothing is better than actually writing code that does something. If I was learning for a job tgen of would just wait until they gave me a story card or business requirement.
Yeah, I already got some tasks assigned to me. Mostly stuff like adding tests (some of them are in python) but it's helping me learn the codebase. Also the company recommends everyone read the "Learn some Erlang" book which is a pretty good read so far, and not too dry.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-10-2019 , 12:23 AM
anyone know an interview site that actually shows you the data set when it fails?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote

      
m