As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/
Options

[Programming] Page overflow to new thread

12357101

Posts

  • Options
    zeenyzeeny Registered User regular
    edited May 2019
    import (
        "encoding/json"
        "log"
        "strings"
    )
    
    func poop(v interface{}) error {
        return json.NewDecoder(strings.NewReader("{\"this\":\"is poop\"}")).Decode(v)
    }
    
    type mepoop struct {
        This string
    }
    
    // Execute is going to get executed.                                                                                                                                                                                                           
    func Execute() {
        var b, a mepoop
        poop(a)
        poop(&b)
        log.Println(a)
        log.Println(b)
    }
    


    Edit: it's just a reader, you can readAll, but that's not your problem.

    zeeny on
  • Options
    Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    Ear3nd1l wrote: »
    I need a little Golang assistance. I'm building a very basic REST API client (long story) and when I get the response from the API, the json decoder is not populating the object. How do I see the response body?
    func (c *client) do(req *http.Request, v interface{}) (*http.Response, error) {
    	resp, err := c.httpClient.Do(req)
    	if err != nil {
    		return nil, err
    	}
    	defer resp.Body.Close()
    
    	err = json.NewDecoder(resp.Body).Decode(v)
    	return resp, err
    }
    

    This is in a test case run inside a docker container against a BrowserStack instance, so there's no way to debug it. Otherwise I probably would have already figured this out.

    Are you sure v is a pointer? I'd probably do a type assertion if you know what kind of pointer it should be.

    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
  • Options
    Ear3nd1lEar3nd1l Eärendil the Mariner, father of Elrond Registered User regular
    Ear3nd1l wrote: »
    I need a little Golang assistance. I'm building a very basic REST API client (long story) and when I get the response from the API, the json decoder is not populating the object. How do I see the response body?
    func (c *client) do(req *http.Request, v interface{}) (*http.Response, error) {
    	resp, err := c.httpClient.Do(req)
    	if err != nil {
    		return nil, err
    	}
    	defer resp.Body.Close()
    
    	err = json.NewDecoder(resp.Body).Decode(v)
    	return resp, err
    }
    

    This is in a test case run inside a docker container against a BrowserStack instance, so there's no way to debug it. Otherwise I probably would have already figured this out.

    Are you sure v is a pointer? I'd probably do a type assertion if you know what kind of pointer it should be.

    I'm fairly new to Go (and most of what I HAVE done has been test case scripts, so no actual development) and I haven't worked with pointers since the 90s. But I'm pretty sure this is being passed as a pointer, right?
    c.do(req, &authenticationResponse)
    

  • Options
    Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    edited May 2019
    Ear3nd1l wrote: »
    Ear3nd1l wrote: »
    I need a little Golang assistance. I'm building a very basic REST API client (long story) and when I get the response from the API, the json decoder is not populating the object. How do I see the response body?
    func (c *client) do(req *http.Request, v interface{}) (*http.Response, error) {
    	resp, err := c.httpClient.Do(req)
    	if err != nil {
    		return nil, err
    	}
    	defer resp.Body.Close()
    
    	err = json.NewDecoder(resp.Body).Decode(v)
    	return resp, err
    }
    

    This is in a test case run inside a docker container against a BrowserStack instance, so there's no way to debug it. Otherwise I probably would have already figured this out.

    Are you sure v is a pointer? I'd probably do a type assertion if you know what kind of pointer it should be.

    I'm fairly new to Go (and most of what I HAVE done has been test case scripts, so no actual development) and I haven't worked with pointers since the 90s. But I'm pretty sure this is being passed as a pointer, right?
    c.do(req, &authenticationResponse)
    

    Yes, & is the reference operator and gives you the pointer for a struct value.

    It's also important that the fields you are reading are actually exported (capitalized)

    https://play.golang.org/p/0xCoVSwpd1r

    Monkey Ball Warrior on
    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
  • Options
    Ear3nd1lEar3nd1l Eärendil the Mariner, father of Elrond Registered User regular
    zeeny wrote: »
    import (
        "encoding/json"
        "log"
        "strings"
    )
    
    func poop(v interface{}) error {
        return json.NewDecoder(strings.NewReader("{\"this\":\"is poop\"}")).Decode(v)
    }
    
    type mepoop struct {
        This string
    }
    
    // Execute is going to get executed.                                                                                                                                                                                                           
    func Execute() {
        var b, a mepoop
        poop(a)
        poop(&b)
        log.Println(a)
        log.Println(b)
    }
    


    Edit: it's just a reader, you can readAll, but that's not your problem.

    You got me on the right track, thank you. I got the JSON value with this:
    	r, e := ioutil.ReadAll(resp.Body)
    	if e != nil {
    		fmt.Println(e)
    	}
    	fmt.Println(string(r))
    

    Turns out I'm getting an authentication error. I've tested with the same payload in Postman and it works fine, so there must be a header value that is wrong. I'll compare the headers from the client with those in Postman and pester the guys who wrote the API if they match.

    Thanks everyone, I appreciate the help.

  • Options
    Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    Speaking of go, it's more or less official now that 1.13 is going to have nestable errors. Essentially they are going to add Wrap/Unwrap methods that can optionally store/fetch an underlying error. Kind of like Java exception "caused by" chains.

    The error system still needs a lot of work, but this is certainly progress.

    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
  • Options
    Jimmy KingJimmy King Registered User regular
    hey, rails people, help me out here. I've inherited some OLD rails stuff. Rails 3.2, ruby 1.9 in particular on this project (got one that's even older... wild). Anyway, it includes a controller which is making use of this: https://github.com/pelle/oauth-plugin/blob/v0.5.1/lib/oauth/controllers/provider_controller.rb

    Except the `authorize` action on it is not working, broken, something. The template it renders says that @token is nil... but there's no way to get to authorize.html.erb with a nil token. So, wtf?

    I've stripped my own controller using it down to this:
    require 'oauth/controllers/provider_controller'
    class MyOauthController < ApplicationController
      include OAuth::Controllers::ProviderController
    end
    

    so not much to go wrong there. Is there some wonkiness with instance vars, views (or templates to me, being a django guy), and included controllers like that which I am unaware of? All of the googling is failing to produce anything useful.

    What I really, really don't understand is that I can make my own `authorize` action, specifically define @token, and yet it STILL says that shit is null. But the stack trace shows that its definitely going to my controller. wtf?

    Rails and all of its magic "I just do stuff" can go fuck itself. Please help me.

  • Options
    LD50LD50 Registered User regular
    Jimmy King wrote: »
    hey, rails people, help me out here. I've inherited some OLD rails stuff. Rails 3.2, ruby 1.9 in particular on this project (got one that's even older... wild). Anyway, it includes a controller which is making use of this: https://github.com/pelle/oauth-plugin/blob/v0.5.1/lib/oauth/controllers/provider_controller.rb

    Except the `authorize` action on it is not working, broken, something. The template it renders says that @token is nil... but there's no way to get to authorize.html.erb with a nil token. So, wtf?

    I've stripped my own controller using it down to this:
    require 'oauth/controllers/provider_controller'
    class MyOauthController < ApplicationController
      include OAuth::Controllers::ProviderController
    end
    

    so not much to go wrong there. Is there some wonkiness with instance vars, views (or templates to me, being a django guy), and included controllers like that which I am unaware of? All of the googling is failing to produce anything useful.

    What I really, really don't understand is that I can make my own `authorize` action, specifically define @token, and yet it STILL says that shit is null. But the stack trace shows that its definitely going to my controller. wtf?

    Rails and all of its magic "I just do stuff" can go fuck itself. Please help me.

    I think we'll need more information. Can you give us the whole error?

  • Options
    EchoEcho ski-bap ba-dapModerator mod
    Speaking of go, it's more or less official now that 1.13 is going to have nestable errors. Essentially they are going to add Wrap/Unwrap methods that can optionally store/fetch an underlying error. Kind of like Java exception "caused by" chains.

    The error system still needs a lot of work, but this is certainly progress.

    We've been using github.com/pkg/errors for that. Looks like they'll pretty much roll that into the standard library.

  • Options
    Jimmy KingJimmy King Registered User regular
    edited May 2019
    LD50 wrote: »
    Jimmy King wrote: »
    hey, rails people, help me out here. I've inherited some OLD rails stuff. Rails 3.2, ruby 1.9 in particular on this project (got one that's even older... wild). Anyway, it includes a controller which is making use of this: https://github.com/pelle/oauth-plugin/blob/v0.5.1/lib/oauth/controllers/provider_controller.rb

    Except the `authorize` action on it is not working, broken, something. The template it renders says that @token is nil... but there's no way to get to authorize.html.erb with a nil token. So, wtf?

    I've stripped my own controller using it down to this:
    require 'oauth/controllers/provider_controller'
    class MyOauthController < ApplicationController
      include OAuth::Controllers::ProviderController
    end
    

    so not much to go wrong there. Is there some wonkiness with instance vars, views (or templates to me, being a django guy), and included controllers like that which I am unaware of? All of the googling is failing to produce anything useful.

    What I really, really don't understand is that I can make my own `authorize` action, specifically define @token, and yet it STILL says that shit is null. But the stack trace shows that its definitely going to my controller. wtf?

    Rails and all of its magic "I just do stuff" can go fuck itself. Please help me.

    I think we'll need more information. Can you give us the whole error?
    ActionView::Template::Error (undefined method `client_application' for nil:NilClass):
        1: <div class="container">
        2:   <h1>Authorize access to your account</h1>
        3:   <p>Would you like to authorize
        4:     <%= link_to @token.client_application.name, @token.client_application.url %>
        5:     (<%= link_to @token.client_application.url, @token.client_application.url %>)
        6:     to access your account?
        7:   </p>
      app/views/my_oauth/authorize.html.erb:4:in `_app_views_my_oauth_authorize_html_erb__863932734616812666_80623260'
      lib/invalid_uri_encoding_monster.rb:14:in `call'
    

    There is of course a whole giant stack trace, but I can't dig through it to redact anything referencing client names, etc.

    Debug info includes this, so I know it's not getting routed to some different controller or action than I think.
      * action_controller.instance                     : #<MyOauthController:0x00000009e3e7f8>
    

    My best guess at this point is that there is a filter or middleware or something which is routing it to some other controller, but I have no idea how the hell to find out what that might be.

    Jimmy King on
  • Options
    Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    Echo wrote: »
    Speaking of go, it's more or less official now that 1.13 is going to have nestable errors. Essentially they are going to add Wrap/Unwrap methods that can optionally store/fetch an underlying error. Kind of like Java exception "caused by" chains.

    The error system still needs a lot of work, but this is certainly progress.

    We've been using github.com/pkg/errors for that. Looks like they'll pretty much roll that into the standard library.

    Kind of like context.

    I still hold out hope that x/sync/errgroup will also be brought in. Honestly, that pattern deserves direct language support, but I'd settle for it being in the stdlib.

    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
  • Options
    Jimmy KingJimmy King Registered User regular
    Alright, no more need to solve this crazy Rails problem. Yay.

  • Options
    PeewiPeewi Registered User regular
    Here I am, thinking the Android app I'm making is close to being in a state worth showing to someone. Better test it on actual hardware.

    And it turns out things that work just fine on the Android emulator crashes on my phone.

    I don't get Android.

  • Options
    AngelHedgieAngelHedgie Registered User regular
    Peewi wrote: »
    Here I am, thinking the Android app I'm making is close to being in a state worth showing to someone. Better test it on actual hardware.

    And it turns out things that work just fine on the Android emulator crashes on my phone.

    I don't get Android.

    "Write once, debug everywhere."

    XBL: Nox Aeternum / PSN: NoxAeternum / NN:NoxAeternum / Steam: noxaeternum
  • Options
    bowenbowen How you doin'? Registered User regular
    It's especially bad if you don't have a flagship android like the pixel or a samsung one that you didn't buy directly from them.

    Phone providers have special android images they can deploy with all their custom shitware, so you've got other stuff toying around inside. Good shit.

    There is a real benefit to iOS sometimes.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    The Escape GoatThe Escape Goat incorrigible ruminant they/themRegistered User regular
    Quick terminology Q: I'm doing javascript crimes as is my job description, this time involving putting up several popups requiring user input in a row and then another, separate popup afterwards. Since it's all got to be in order but our popup functions are asynchronous I'm hacking together a makeshift loop by having the function handling all the logic put itself as the callback to the popup creator. Thus, one popup only comes up after the last has been closed by the user, and there's an exit condition that deals with the final popup.

    Does that count as recursion, even if the function is going through a middleman rather than directly calling itself?

    9uiytxaqj2j0.jpg
  • Options
    SoggybiscuitSoggybiscuit Tandem Electrostatic Accelerator Registered User regular
    So, I'm using this snippet of code that simply refuses to run correctly, not matter what I do (Python 3.7).
    gamTPH=gamTPHp1
    for n in range(np.size(gamTPH[0])):
        for m in range(np.size(gamTPHp2[0])):
            if gamTPHp2[0][m]==gamTPH[0][n]:
                gamTPH[1][n]=gamTPH[1][n]+gamTPHp2[1][m]
    

    For some odd reason, gamTPHp1 = gamTPH... after this executes. Can't figure it out, and I'm pretty sure it shouldn't do this. Maybe a bug?

    Steam - Synthetic Violence | XBOX Live - Cannonfuse | PSN - CastleBravo | Twitch - SoggybiscuitPA
  • Options
    BlazeFireBlazeFire Registered User regular
    I'm not familiar with the syntax, but after a quick google I'm wondering is that the right way to get the size? Or is it supposed to be gamTPH[0].size?

  • Options
    TheSmackerTheSmacker Registered User regular
    So, I'm using this snippet of code that simply refuses to run correctly, not matter what I do (Python 3.7).
    gamTPH=gamTPHp1
    for n in range(np.size(gamTPH[0])):
        for m in range(np.size(gamTPHp2[0])):
            if gamTPHp2[0][m]==gamTPH[0][n]:
                gamTPH[1][n]=gamTPH[1][n]+gamTPHp2[1][m]
    

    For some odd reason, gamTPHp1 = gamTPH... after this executes. Can't figure it out, and I'm pretty sure it shouldn't do this. Maybe a bug?

    You first line doesn't create a copy (if that's what you're going for), it just assigns both variables to the same object, so changing one also changes the other:
    >a = [1,2,3]
    >b = a
    >b[0] = 3
    >a
    [3, 2, 3]
    

    I haven't used numpy in forever, but I think you're looking for something like gamTPH = np.copy(gamTPH1)? There's some built in ways to do it, but I don't think they work on numpy objects if that's what gamTPH is.
    >a = [1,2,3]
    >b = list.copy(a)
    >b[0] = 3
    >a
    [1, 2, 3]
    >b
    [3, 2, 3]
    

  • Options
    Jimmy KingJimmy King Registered User regular
    edited May 2019
    So, I'm using this snippet of code that simply refuses to run correctly, not matter what I do (Python 3.7).
    gamTPH=gamTPHp1
    for n in range(np.size(gamTPH[0])):
        for m in range(np.size(gamTPHp2[0])):
            if gamTPHp2[0][m]==gamTPH[0][n]:
                gamTPH[1][n]=gamTPH[1][n]+gamTPHp2[1][m]
    

    For some odd reason, gamTPHp1 = gamTPH... after this executes. Can't figure it out, and I'm pretty sure it shouldn't do this. Maybe a bug?

    gamTPH is a reference to gamTPHp1. They are pointing at the exact same object/space in memory. When you modify one, the other is also being modified because they are the same thing.

    This is not how I would actually write this, but it's closer to what you've got up there than what I would do. In both cases I'd probably just iterate over the items directly along with using python's enumerate() if I need the index I am on... what np is for you might effect that, though.
    >>> x = [1,2,3,4]
    >>> y = x
    >>> for n in range(len(x)):
    ...   x[n] += 1
    ...
    >>> x
    [2, 3, 4, 5]
    >>> y
    [2, 3, 4, 5]
    

    In python, if you want to copy the values but have a new list, use:
    gamTPH = gamTPHp1[:]
    

    Even that might net you the same issue since the main list will be new, but it'll have references to the same underlying lists, now that I think about it.

    Depending on your data and end goal you might need this
    import copy
    gamTPH = copy.deepcopy(gamTPHp1)
    

    Jimmy King on
  • Options
    Jimmy KingJimmy King Registered User regular
    Got a rails question my googling is failing at. If I set the rails cache to
    config.cache_store = :mem_cache_store, "some server here"
    

    and use the same memcached server across multiple, separate rails sites, does it prefix the keys or something to ensure each sites keys do not get intermixed or do I need to use a separate memcached server for each separate rails site?

  • Options
    PeewiPeewi Registered User regular
    Turns out the crash in my Android app was because of language settings. I was putting a timestamp in a filename without specifying formatting. In some languages dates have slashes in them. You know, like English.

  • Options
    InfidelInfidel Heretic Registered User regular
    Jimmy King wrote: »
    Got a rails question my googling is failing at. If I set the rails cache to
    config.cache_store = :mem_cache_store, "some server here"
    

    and use the same memcached server across multiple, separate rails sites, does it prefix the keys or something to ensure each sites keys do not get intermixed or do I need to use a separate memcached server for each separate rails site?

    You need to separate them explicitly yeah. Use the namespace param in the constructor of your cache.

    OrokosPA.png
  • Options
    SoggybiscuitSoggybiscuit Tandem Electrostatic Accelerator Registered User regular
    edited May 2019
    TheSmacker wrote: »
    So, I'm using this snippet of code that simply refuses to run correctly, not matter what I do (Python 3.7).
    gamTPH=gamTPHp1
    for n in range(np.size(gamTPH[0])):
        for m in range(np.size(gamTPHp2[0])):
            if gamTPHp2[0][m]==gamTPH[0][n]:
                gamTPH[1][n]=gamTPH[1][n]+gamTPHp2[1][m]
    

    For some odd reason, gamTPHp1 = gamTPH... after this executes. Can't figure it out, and I'm pretty sure it shouldn't do this. Maybe a bug?

    You first line doesn't create a copy (if that's what you're going for), it just assigns both variables to the same object, so changing one also changes the other:
    >a = [1,2,3]
    >b = a
    >b[0] = 3
    >a
    [3, 2, 3]
    

    I haven't used numpy in forever, but I think you're looking for something like gamTPH = np.copy(gamTPH1)? There's some built in ways to do it, but I don't think they work on numpy objects if that's what gamTPH is.
    >a = [1,2,3]
    >b = list.copy(a)
    >b[0] = 3
    >a
    [1, 2, 3]
    >b
    [3, 2, 3]
    


    Jimmy King wrote: »
    So, I'm using this snippet of code that simply refuses to run correctly, not matter what I do (Python 3.7).
    gamTPH=gamTPHp1
    for n in range(np.size(gamTPH[0])):
        for m in range(np.size(gamTPHp2[0])):
            if gamTPHp2[0][m]==gamTPH[0][n]:
                gamTPH[1][n]=gamTPH[1][n]+gamTPHp2[1][m]
    

    For some odd reason, gamTPHp1 = gamTPH... after this executes. Can't figure it out, and I'm pretty sure it shouldn't do this. Maybe a bug?

    gamTPH is a reference to gamTPHp1. They are pointing at the exact same object/space in memory. When you modify one, the other is also being modified because they are the same thing.

    This is not how I would actually write this, but it's closer to what you've got up there than what I would do. In both cases I'd probably just iterate over the items directly along with using python's enumerate() if I need the index I am on... what np is for you might effect that, though.
    >>> x = [1,2,3,4]
    >>> y = x
    >>> for n in range(len(x)):
    ...   x[n] += 1
    ...
    >>> x
    [2, 3, 4, 5]
    >>> y
    [2, 3, 4, 5]
    

    In python, if you want to copy the values but have a new list, use:
    gamTPH = gamTPHp1[:]
    

    Even that might net you the same issue since the main list will be new, but it'll have references to the same underlying lists, now that I think about it.

    Depending on your data and end goal you might need this
    import copy
    gamTPH = copy.deepcopy(gamTPHp1)
    

    Super big thanks to both of you.

    Also, would never have figured that out. I'm switching from using MATLAB to do my analysis to Python, and in MATLAB, that first line always creates an explicit copy (that's why the results were confusing me).

    Soggybiscuit on
    Steam - Synthetic Violence | XBOX Live - Cannonfuse | PSN - CastleBravo | Twitch - SoggybiscuitPA
  • Options
    LD50LD50 Registered User regular
    Peewi wrote: »
    Turns out the crash in my Android app was because of language settings. I was putting a timestamp in a filename without specifying formatting. In some languages dates have slashes in them. You know, like English.

    Hah, at least it wasn't an emoji!

  • Options
    Jimmy KingJimmy King Registered User regular
    Infidel wrote: »
    Jimmy King wrote: »
    Got a rails question my googling is failing at. If I set the rails cache to
    config.cache_store = :mem_cache_store, "some server here"
    

    and use the same memcached server across multiple, separate rails sites, does it prefix the keys or something to ensure each sites keys do not get intermixed or do I need to use a separate memcached server for each separate rails site?

    You need to separate them explicitly yeah. Use the namespace param in the constructor of your cache.

    There we go, thank you. All of my googling kept resulting in information on using multiple memcached servers for one rails app rather than what I was looking for. Not sure how I missed just getting to the main rails docs on that in the first place.

    For most of my projects/clients there's just one project and so one thing with a db, cache, queue broker, etc. New client who I'm fixing infrastructure for has enough separate systems which all use similar services that it seems to make more sense to share some of those things like Redis and Memcached (and I can probably just scrap Memcached and use Redis for everything in the end). No need to pay aws for 10 separate 2% used ElasticCache instances.

  • Options
    dporowskidporowski Registered User regular
    edited May 2019
    Any advice in intermixing Kotlin into a Java project? Looks simple enough, I'm just unfamiliar with that whole "add the runtime or use the current plugin" bit. (https://kotlinlang.org/docs/tutorials/mixing-java-kotlin-intellij.html)

    That just the equivalent of setting/including a particular SDK version vs "use the latest"? Sure seems like it, but...

    Edit: Yeah I realise this seems like a dumb question. Even to me. But I am fundamentally reluctant to believe "it's simple" whenever the words "java" or "write once, run anywhere" are in the same zip code.

    dporowski on
  • Options
    thatassemblyguythatassemblyguy Janitor of Technical Debt .Registered User regular
    If you’re using IntelliJ then I believe the intermixing is fairly transparent, but I seem to remember a few gotchas when configuring upfront.

  • Options
    Jimmy KingJimmy King Registered User regular
    Ugh. Xamarin.Forms 4 change from pre-10 to official release made way more drastic of changes than I'd expect from final RC to release and broke a bunch of shit with the new Shell stuff I've been using in my toy xamarin.forms app.

    Unrelated update - having a bunch of fun yesterday and today at RVASec InfoSec conference.

  • Options
    Ear3nd1lEar3nd1l Eärendil the Mariner, father of Elrond Registered User regular
    Jimmy King wrote: »
    Ugh. Xamarin.Forms 4 change from pre-10 to official release made way more drastic of changes than I'd expect from final RC to release and broke a bunch of shit with the new Shell stuff I've been using in my toy xamarin.forms app.

    Unrelated update - having a bunch of fun yesterday and today at RVASec InfoSec conference.

    That happened to me with Angular2. I feel your pain.

  • Options
    MadpoetMadpoet Registered User regular
    edited May 2019
    Work moved me to a new project. Reworking a legacy app into .Net WebAPI with a React front-end. Great!

    Two weeks later they decide to scrap the rework, and just have the team work on the legacy app - which is VB WebForms on top of Oracle. I have zero Oracle experience and my exposure to Webforms is an Access front-end I wrote in 2008. I don't mind learning but... I really don't want to learn any of this.

    I spent yesterday tracking down a data access bug in my code. Everything looked to be in place, but where there should have been data, there was none. I brought it up in today's meeting, and it turns out whoever cloned our dev database didn't clone everything - the interface was there but the code wasn't. In my native languages this is a 5 minute fix. In this new land it cost days.

    I am getting paid waaaay too much to even think about quitting. But I do anyways.

    Madpoet on
  • Options
    EchoEcho ski-bap ba-dapModerator mod
    Man, I suck at SQL. I could use some pointers here for Postgres stuff.

    I have a table with domain data that looks something like this:

    n2npktf2chop.png


    Or in other words, this tree structure, where red is invalid, and green is valid:

    s7ela20jtndb.png

    Based on this, I want to get all the highest-level domains that are valid. In this case, it should be A and C.B. If example.com was valid, only that should be returned.

    Getting the whole tree I can do recursively:
    WITH RECURSIVE valid_domains AS (
      SELECT id, valid FROM domain
      WHERE parent_id IS NULL
        
      UNION ALL
        
      SELECT d.id, d.valid FROM domain d
      JOIN valid_domains vd ON d.parent_id = vd.id
    )
    
    SELECT * FROM valid_domains
    

    The stumbling block is breaking the recursion when I hit a valid domain. I've looked at window functions, but can't quite get those. I haven't found any examples that use window functions recursively - maybe I'm approaching it wrong by starting with a recursion here?

  • Options
    EchoEcho ski-bap ba-dapModerator mod
    Turns out I was reeeeally darn close:
    WITH RECURSIVE valid_domains AS (
      SELECT id, valid FROM domain
      WHERE parent_id IS NULL
        
      UNION ALL
        
      SELECT d.id, d.valid FROM domain d
      JOIN valid_domains vd ON d.parent_id = vd.id
      WHERE NOT valid
    )
    SELECT * FROM valid_domains
    

    I was just missing the "WHERE NOT valid" to stop going deeper into the branch.

  • Options
    Jimmy KingJimmy King Registered User regular
    Neat. I just learned about postgres recursive queries.

    An as to my Xamarin.Forms 4 Shell stuff, it turned out to be two issues. The first was the pretty crazy backwards incompatible changes, but those were easily dealt with. But it seems like when updating dependencies from nuget it's possible to somehow get your dependencies into some sort of weird half updated state and so it was building most of the code against one version of Xamarin.Forms and then at runtime part of the app was trying to use an older version and I could see the old version was still referenced in the main .csproj file.

  • Options
    EchoEcho ski-bap ba-dapModerator mod
    Jimmy King wrote: »
    Neat. I just learned about postgres recursive queries.

    Strictly speaking it's implemented as an iteration, but the SQL people call it recursive in the language because reasons.

    So I'm poking some stuff that sends data to Salesforce right now.

    Me: *uses the upsert call in their API*
    SF: OMG THIS ALREADY EXISTS ALERT ALERT SHIT THE BED

    ...that's not how an upsert works.

  • Options
    EchoEcho ski-bap ba-dapModerator mod
    Maybe Salesforce read it as UPSET.

    Yep, I worked on that joke for an hour.

  • Options
    Ear3nd1lEar3nd1l Eärendil the Mariner, father of Elrond Registered User regular
    Back in the day, I was writing a CMS and used a recursive SQL query to build the navigation tree. Then I wrote it in reverse for the breadcrumbs. It was kinda neat back then.

  • Options
    thatassemblyguythatassemblyguy Janitor of Technical Debt .Registered User regular
    Echo wrote: »
    Jimmy King wrote: »
    Neat. I just learned about postgres recursive queries.

    Strictly speaking it's implemented as an iteration, but the SQL people call it recursive in the language because reasons.

    So I'm poking some stuff that sends data to Salesforce right now.

    Me: *uses the upsert call in their API*
    SF: OMG THIS ALREADY EXISTS ALERT ALERT SHIT THE BED

    ...that's not how an upsert works.

    I'm at a loss.

    Has UPSERT been kept from most implementations this long because of a patent issue, or is it because of SQL purists not realizing how shitty it is, in practice, to work around the missing functionality?

  • Options
    ElaroElaro Apologetic Registered User regular
    What's UPSERT?

    Children's rights are human rights.
  • Options
    LD50LD50 Registered User regular
    Elaro wrote: »
    What's UPSERT?

    Hybrid update insert. Update the row if it exists, insert a new row if it does not.

This discussion has been closed.