Transform php code into a widget?

how can I create a widget out of a php code? It’s just a disqus code that I would like to place in the sidebar. I could just paste the code in the widget section (my tag), but then I would not be able to change it’s order with the other wigets. This is why I want to convert this code into a widget.

How to mix partial and full page refresh in the same section of the customizer?

This is really a two stage question, for not very relevant context you can look at this question – How to customize a shortcode using the customizer. In brief I got a widget and a shortcode that implement the same functionality and that is customized in the customizer by adapting the form generated for the widget into a customizer section.