DevLog.at

Discover

Latest Posts

Welcome to DevLog

The open thought platform for developers.

Share your work as you work on it. Easier than a blog, handier than Twitter.

Sign in and write down valuable thoughts that would otherwise be forgotten.

Figuring out ecto's upsert behavior was a major pain. Take the following example:

%User{}
|> User.changeset(attrs)
|> Repo.insert!(
  on_conflict: :replace_all,
  conflict_target: :github_id
)

Here, :replace_all tells ecto to update the existing record in the db with your data from the changeset (when a conflict occurs).

This is great. However, the unexpected part is that :replace_all also includes the id column in its updates. In other words, when a conflict occurs, ecto updates the existing record with a new incremental id. What??

I don't know when you'd want this. But to stop it, you need to explicitly tell ecto to exclude id:

Repo.insert!(
  on_conflict: {:replace_all_except, [:id]},
  conflict_target: :steam_appid
)

11d

My company is a SaaS but there's a lot of manual DB querying that we need to do on each customer environment. I want to automate that.

Stack

  • Tornado and various SQL sauce
  • Mithril and Construct-UI
  • Vanilla JS otherwise

2m

Finished the unity tutorial finally! https://www.youtube.com/watch?v=IypPRsuA2yg

2m

still dont know how to do ssr with auth

4m

Just wanted to share that I am currently writing up a blog post for this process as when I was searching for materials as to how to implement it, every tutorial I came across showed how to generate the QR code, and add it to Google authenticator, however none actually showed how to verify the code from the authenticator.

I will link it here if afterwards and hopefully it helps someone who is in the same situation that I found myself in :)

4m

Been thinking about dask vs Husky vs Spark

4m

Making sure proper error codes and messages are returned by the API.

4m

A mate of mine is a writer by trade but around 2-3 years ago started mucking about with front-end web tech - HTML, CSS, Javascript. He's just about finished making his portfolio website and asked for a hand testing / reviewing from a technical angle and sorting out some finer points. It is such a joy seeing a consumately designed indie website. I'm looking at 4000 lines of hand-written CSS and it really takes me down memory lane.

4m

A cli that randomly clicks around and messes with a website and reports what it is doing as a highly detailed tsv file.

Then you can see if any exceptions occur, read the reported tsv logs and decide if it warrants further investigation.

4m

Some other functions you can call on your Map include:

map.set('cat','tofu');

map.has('cat'); //true

map.get('cat'); //tofu

map.delete('dog');

map.has('dog'); //false

4m

But let's say we do want to match all the case variations of funFunfun including FunFunFun, funfunfun etc...

Add the letter i to the end like so: /funFunfun/i

The letter i is one type of 'flag' that modifies regex search

4m

Implemented an intricate anti-spam measure.

window.setTimeout(function(){
    var sf = 'sf_' + Math.random().toString(36).replace('0.', ''); 	    var sf = $('#sf');
    $('.donation-form').append($("<input type='hidden' name='sf'/>").val(sf));	
     if(sf.val())
      sf.val(sf.val() + '!');
    else
      sf.val(Math.random().toString(36).replace('0.', '') + $('#donation_form_id').val());
  }, 7000);	  }, 7000);
});	});

5m