Skip to content

Instantly share code, notes, and snippets.

View Voles's full-sized avatar

Niels Dequeker Voles

  • Belgium
  • 16:50 (UTC +02:00)
View GitHub Profile
@Voles
Voles / bump-patch.sh
Last active August 20, 2020 10:10
Bump patch file and push to origin
#!/usr/bin/env bash
bp () {
git fetch
latestTag=$(git tag | tail -n1)
versionParts=($(echo "$latestTag" | tr '.' '\n'))
newTag="${versionParts[1]}.${versionParts[2]}.$(($versionParts[3] + 1))"
echo "new patch version is: $newTag"
@Voles
Voles / main.go
Created October 28, 2019 12:51
BizzBuzz attempt
package code_kata
import "testing"
import "strconv"
//func TestLineCount(t *testing.T) {
// buffer := fizbuzz()
//
// if len(buffer) != 100 {
// t.Fail("expected 100 lines")

Keybase proof

I hereby claim:

  • I am voles on github.
  • I am voles (https://keybase.io/voles) on keybase.
  • I have a public key ASAOjePk0T8yqrP3FMKPX0gakD5aAM6ySU5I1IMPGrMqRQo

To claim this, I am signing this object:

@Voles
Voles / main.go
Created March 4, 2019 20:37
Go channel experiment
// Directory maps every file from a directory into an API model
func Directory(directory string) ([]models.API, error) {
files, err := ioutil.ReadDir(directory)
workerQueue := make(chan string)
APImodelsChan := make(chan result)
output := []models.API{}
if err != nil {
@Voles
Voles / index.js
Created May 22, 2018 20:59
Recursive Promise
function fetchResultsWithPagination(options, page, resultList) {
resultList = resultList || [];
page = page || 1;
return new Promise((resolve, reject) => {
makeHttpRequestPromise(Object.assign({}, options, { page: page }))
.then(payload => {
const newResultList = resultList.concat(payload);
if (payload.length >= options.per_page) {
@Voles
Voles / README.md
Created January 22, 2018 10:04
MySQL with phpMyAdmin setup using Docker Compose
@Voles
Voles / App.elm
Created November 10, 2017 16:29
My First Elm App
-- Read more about this program in the official Elm guide:
-- https://guide.elm-lang.org/architecture/user_input/buttons.html
import Html exposing (beginnerProgram, div, button, text, input)
import Html.Attributes exposing (class)
import Html.Events exposing (onClick, onInput)
import String exposing (toInt)
{-
import Result exposing (..)
-}
@Voles
Voles / the-bind-problem.jsx
Last active March 23, 2017 14:09 — forked from Restuta/the-bind-problem.jsx
React, removeEventListener and bind(this) gotcha
/* Sometimes it's pretty easy to run ito troubles with React ES6 components.
Consider the following code: */
class EventStub extends Component {
componentDidMount() {
window.addEventListener('resize', this.onResize.bind(this)); //notice .bind
}
componentWillUnmount() {
window.removeEventListener('resize', this.onResize.bind(this));
@Voles
Voles / .gitlab-ci.yml
Created February 2, 2017 20:20
GitLab configuration for Protractor
image: kkarczmarczyk/node-yarn:6.9
cache:
paths:
- webapp/node_modules/
- vendor/apt
e2e_tests:
before_script:
# install chrome

Using pg.connect is the way to go in a web environment.

PostgreSQL server can only handle 1 query at a time per connection. That means if you have 1 global new pg.Client() connected to your backend your entire app is bottleknecked based on how fast postgres can respond to queries. It literally will line everything up, queuing each query. Yeah, it's async and so that's alright...but wouldn't you rather multiply your throughput by 10x? Use pg.connect set the pg.defaults.poolSize to something sane (we do 25-100, not sure the right number yet).

new pg.Client is for when you know what you're doing. When you need a single long lived client for some reason or need to very carefully control the life-cycle. A good example of this is when using LISTEN/NOTIFY. The listening client needs to be around and connected and not shared so it can properly handle NOTIFY messages. Other example would be when opening up a 1-off client to kill some hung stuff or in command line scripts.