Skip to content

Instantly share code, notes, and snippets.

@lucasreta
lucasreta / graphql-clients-benchmark.md
Created May 26, 2021 04:57 — forked from oddlyfunctional/graphql-clients-benchmark.md
Comparison between GraphQL clients

Client-side GraphQL

graphql_ppx

Let's first analyze how to write the queries. I experimented the graphql_ppx with a few different features (nullable and non-nullable variables, fragments, convert response into record automatically). The type safety is very neat, both the input variables and the response have specific types (no Js.Json.t!), and the queries/mutations are validated against the schema! This makes it really easy to write queries, although I worry about integrating new versions of the schema since the repos are separated (we should probably re-fetch the schema as part of the CI).

As for the drawbacks, there are not many:

  • The ppx really messes up my language server sometimes.
  • I haven't tried a lot but I couldn't find easily a way to use refmt to format the queries.
  • I couldn't find anything about custom directives, the lack of which would prevents us from using some features from the GraphQL clients (for example, managing local state using Apollo's @client directive).
  • I haven't
* {
font-family: sans-serif;
}
body {
background-color: #eee;
}
header, main {
background-color: #fff;
border: 1px solid #ababab;
box-shadow: 1px 1px 0 rgba(0,0,0,.2);
const useHash = true;
const apiUrl = 'https://lucasreta.com/stack-overflow/spa-vanilla-js/api';
const routes = ['section-1', 'section-2'];
const content_box = document.getElementById("content_box");
function get(page) {
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
data = JSON.parse(xhr.responseText);
@lucasreta
lucasreta / vanilla-spa-index.html
Last active December 30, 2020 14:23
vanilla-spa
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Welcome | App Manual</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<header>
@lucasreta
lucasreta / jwtRS256.sh
Created December 29, 2020 21:33 — forked from ygotthilf/jwtRS256.sh
How to generate JWT RS256 key
ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
# Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
cat jwtRS256.key
cat jwtRS256.key.pub
@lucasreta
lucasreta / gifeegol.sh
Last active December 4, 2020 02:29
embeddable version of gifeegol.sh for medium article
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd $DIR
./cligol/cligol
weekday=`date +"%w"`
today=`date +%Y-%m-%d`
@lucasreta
lucasreta / cligol.c
Created December 3, 2020 09:30
reduced version of cligol's main.c file for medium article
#include "headers/config.h"
#include "headers/custom_string.h"
void compute (int neighbors[BOARD_HEIGHT][BOARD_WIDTH], int board[BOARD_HEIGHT][BOARD_WIDTH]);
void randomize (int board[BOARD_HEIGHT][BOARD_WIDTH]);
void clear () { printf ("\033[H\033[J"); }
void show (int board[BOARD_HEIGHT][BOARD_WIDTH]);
@lucasreta
lucasreta / README.md
Last active October 16, 2020 23:31
php-login

Small gist for a Stack Overflow question about simple PHP login flow.

  • Download all files into a directory
  • Create a database named logintest
  • Create a table as the one described in users.sql
  • Replace login credentials in mysqli() for your own (both in signup.php and login.php)
  • Start a local server in the directory where the files exist: php -S 0.0.0.0:8888
  • Go to http://localhost:8888/signup.php and create a user
  • Go to http://localhost:8888/login.php and log in with email and password of created user
@lucasreta
lucasreta / README.md
Created October 16, 2020 21:36
react-hello-world

Small gist to try and help answer a question in Stack Overflow.

Download the contents of the gist into a folder, open the terminal and navigate to said folder. Once inside the directory, run:

npx serve

This should start a local server in which the small Hello World application can be viewed.

@lucasreta
lucasreta / index.html
Created September 22, 2020 16:01
working with Chart.JS
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.css" rel="stylesheet" />
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.css" rel="stylesheet" type="text/css">
<title>Portfolio Review Overview</title>