Skip to content

Instantly share code, notes, and snippets.

View ZaninAndrea's full-sized avatar
👨‍💻

Zanin Andrea ZaninAndrea

👨‍💻
View GitHub Profile
@ZaninAndrea
ZaninAndrea / README.md
Last active April 10, 2022 08:36
Permanently remapping of a key in MacOS
@ZaninAndrea
ZaninAndrea / main.cpp
Created April 4, 2022 14:55
Step 3 - Igloo with C++ tutorial
if (parsedResponse["errors"] != nullptr){
std::cerr << parsedResponse["errors"][0]["message"] << std::endl;
throw "GraphQL Error";
}
@ZaninAndrea
ZaninAndrea / main.cpp
Created April 4, 2022 14:52
Step 2 - Igloo with C++ tutorial
#include <nlohmann/json.hpp>
// omitted
nlohmann::json parsedResponse = nlohmann::json::parse(r.text);
std::string email = parsedResponse["data"]["user"]["email"].get<std::string>();
std::cout << email << std::endl;
@ZaninAndrea
ZaninAndrea / main.cpp
Created April 4, 2022 14:45
Step 1 - Igloo with C++ tutorial
#include <iostream>
#include <cpr/cpr.h>
int main(int argc, char** argv) {
std::string query = "{ user { email } }";
std::string token = "replace-your-access-token-here";
cpr::Response r = cpr::Post(cpr::Url{"https://v1.igloo.ooo/graphql"},
cpr::Body{"{\"query\": \"" + query + "\"}"},
cpr::Header{
@ZaninAndrea
ZaninAndrea / main.cpp
Created April 4, 2022 14:32
Connecting to Igloo using c++
#include <iostream>
#include <cpr/cpr.h>
#include <nlohmann/json.hpp>
nlohmann::json sendRequest(std::string query, std::string token){
// Send the HTTP request
cpr::Response r = cpr::Post(cpr::Url{"https://v1.igloo.ooo/graphql"},
cpr::Body{"{\"query\": \"" + query + "\"}"},
cpr::Header{
{"Content-Type", "application/json"},
@ZaninAndrea
ZaninAndrea / main.py
Last active April 4, 2022 14:27
Utility to send requests to Igloo
import requests
import json
class GraphQLException(Exception):
pass
def send_request(query, token=None):
payload=json.dumps({"query": query})
headers= {"Content-Type": "application/json"}
@ZaninAndrea
ZaninAndrea / main.py
Created April 4, 2022 08:57
Parsing Igloo errors
parsed_response = json.loads(response.text)
if "errors" in parsed_response.keys():
# Raise an error using the first error message in the response
raise Error(parsed_response["errors"][0]["message"]
@ZaninAndrea
ZaninAndrea / main.py
Created April 4, 2022 08:55
Parse an Igloo response
parsed_response = json.loads(response.text)
email = parsed_response["data"]["user"]["email"]
print(email)
@ZaninAndrea
ZaninAndrea / main.py
Created April 4, 2022 08:37
Sending a request to Igloo
import requests
import json
# Converts a python dictionary into a JSON string
payload = json.dumps({"query": """{
user{
email
}
}"""})
@ZaninAndrea
ZaninAndrea / hello_express.js
Created August 5, 2020 09:04
Minimal express.js example
const express = require('express')
const cors = require("cors")
const app = express()
app.use(cors())
const port = process.env.PORT || 3000
app.get('/', (req, res) => {
res.send('Hello World!')
})