Skip to content

Instantly share code, notes, and snippets.

View cguedes's full-sized avatar
🇵🇹
Remotely working from Portugal

Carlos Guedes cguedes

🇵🇹
Remotely working from Portugal
View GitHub Profile
@cguedes
cguedes / fetch-teacher-lectures.js
Created September 20, 2018 11:24
Thoth API Utilities
async function fetchLectures(teacher) {
const allClasses = (await fetch("https://adeetc.thothapp.com/api/v1/classes").then(res => res.json())).classes
const teacherClasses = allClasses.filter(c => c.mainTeacherShortName === teacher)
const teacherClassesDetails = await Promise.all( teacherClasses.map(c => fetch(c._links.self).then(r => r.json())) )
const teacherClassesLectures = await Promise.all( teacherClassesDetails.map(klass => fetch(klass._links.lectures).then(r => r.json()).then(lectures => ({ klass, lectures }))) )
const detailedInfo = await Promise.all(teacherClassesLectures.map(klassInfo => Promise.all(klassInfo.lectures.classLectures.map(l => fetch(l._links.self).then(r => r.json()))).then(lectures => ({ klass: klassInfo.klass, lectures }))))
return detailedInfo
}
const teacher = "Carlos Guedes"
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"title": "TokenStatusResult",
"description": "Status about a given token",
"properties": {
"active": {
"type": "boolean",
"title": "Active",
"description": "True if the token is active and therefore, usabale to reset the password"
@cguedes
cguedes / A List of Links.md
Last active November 14, 2022 04:37
List of Links
@cguedes
cguedes / a-tour-on-react-ecosystem.md
Last active December 5, 2015 21:07
A Tour on React Ecosystem

Demos for A tour on react ecosystem

  1. Basic React Sample (click component - state)
  • show reconciliation
  • DOM mutation breakpoint
  • update basic example to use list of items
  1. Counter example and stateless functions
@cguedes
cguedes / index.html
Created June 2, 2015 15:56
Huge Canvas Image Download
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Huge Canvas Image Donwload</title>
</head>
<body>
<div id="content">
<h2>Huge Canvas
@cguedes
cguedes / XMLHttpRequest
Created December 7, 2013 12:17
XMLHttpRequest interfaces
[NoInterfaceObject]
interface XMLHttpRequestEventTarget : EventTarget {
// event handlers
[TreatNonCallableAsNull] attribute Function? onloadstart;
[TreatNonCallableAsNull] attribute Function? onprogress;
[TreatNonCallableAsNull] attribute Function? onabort;
[TreatNonCallableAsNull] attribute Function? onerror;
[TreatNonCallableAsNull] attribute Function? onload;
[TreatNonCallableAsNull] attribute Function? ontimeout;
[TreatNonCallableAsNull] attribute Function? onloadend;
@cguedes
cguedes / sampleAJAX.js
Created December 7, 2013 11:54
Sample AJAX request
function handler() {
show("readyState: " + this.readyState);
if(this.readyState == this.DONE) {
if(this.status == 200)
show(this.responseText);
}
}
var client = new XMLHttpRequest();
client.onreadystatechange = handler;
@cguedes
cguedes / findSubmissions.js
Created June 6, 2013 23:17
How easy is to write code in NodeJS to asynchronously find files with a given set of patterns :-). Note: If glob could accept regex (i.e. `**/*.(zip|rar)`) in search pattern this code could be simpler!
function findSubmissions(extractedDir, done) {
var glob = require("glob");
var fileSearchPatterns = ["**/*.zip", "**/*.rar"];
log.info("Finding code to evaluate in " + extractedDir + " with patterns " + fileSearchPatterns);
async.map(fileSearchPatterns, findFilesWithPattern, function(err, filesArray) {
if (err) return log.errorAndDone("Error finding code to evaluate", err, done);
var allFiles = Array.prototype.concat.apply([], filesArray);
log.dir("Search found " + allFiles.length + " files: ", allFiles);