8,037 Matching Annotations
  1. Jul 2023
    1. ```js import { ThreadsAPI } from 'threads-api';

      // or in Deno 🦖: // import { ThreadsAPI } from "npm:threads-api";

      const main = async () => { const threadsAPI = new ThreadsAPI();

      const username = '_junhoyeo'; const id = await threadsAPI.getUserIDfromUsername(username); console.log(id);

      if (!id) { return; }

      const user = await threadsAPI.getUserProfile(username, id); console.log(JSON.stringify(user));

      const posts = await threadsAPI.getUserProfileThreads(username, id); console.log(JSON.stringify(posts));

      const replies await threadsAPI.getUserProfileReplies(username, id); console.log(JSON.stringify(replies)); }; main(); ```

    1. js function getFlagEmoji(countryCode) { const codePoints = countryCode .toUpperCase() .split('') .map(char => 127397 + char.charCodeAt()); return String.fromCodePoint(...codePoints); }

      js getFlagEmoji('US') = 🇺🇸 getFlagEmoji('NL') = 🇳🇱 getFlagEmoji('CH') = 🇨🇭

    1. WebSocket support in Pub/Sub works by encapsulating MQTT packets (Pub/Sub’s underlying native protocol) within WebSocket framesExternal link icon

      ```js // Ensure MQTT.js is installed first // > npm install mqtt import * as mqtt from "mqtt"

      // Where 'url' is "mqtts://BROKER.NAMESPACE.cloudflarepubsub.com:8884" function example(url) { let client = mqtt.connect(url, { protocolVersion: 5, reconnectPeriod: 0, username: 'anything', password: jwt, // pass this from a form field in your app clientId: '', })

      client.on('connect', function () { client.subscribe(topic, function (err) { if (err) { client.end(); } else { console.log(subscribed to ${topic}) } })

      client.on('message', function (topic, message) { let line = (new Date()).toLocaleString('en-US') + ": " + message.toString() + "\n"; console.log(line) }) } ```

    1. ```js exports.handler = async (event) => { if (event.headers != undefined) { const headers = toLowerCaseProperties(event.headers);

          if (headers['sec-websocket-protocol'] != undefined) {
              const subprotocolHeader = headers['sec-websocket-protocol'];
              const subprotocols = subprotocolHeader.split(',');
      
              if (subprotocols.indexOf('myprotocol') >= 0) {
                  const response = {
                      statusCode: 200,
                      headers: {
                          "Sec-WebSocket-Protocol" : "myprotocol"
                      }
                  };
                  return response;
              }
          }
      }
      
      const response = {
          statusCode: 400
      };
      
      return response;
      

      };function toLowerCaseProperties(obj) { var wrapper = {}; for (var key in obj) { wrapper[key.toLowerCase()] = obj[key]; } return wrapper; } ```

    1. ```js async function main() { const blob = new Blob([new Uint8Array(10 * 1024 * 1024)]); // any Blob, including a File const uploadProgress = document.getElementById("upload-progress"); const downloadProgress = document.getElementById("download-progress");

      const totalBytes = blob.size; let bytesUploaded = 0;

      // Use a custom TransformStream to track upload progress const progressTrackingStream = new TransformStream({ transform(chunk, controller) { controller.enqueue(chunk); bytesUploaded += chunk.byteLength; console.log("upload progress:", bytesUploaded / totalBytes); uploadProgress.value = bytesUploaded / totalBytes; }, flush(controller) { console.log("completed stream"); }, }); const response = await fetch("https://httpbin.org/put", { method: "PUT", headers: { "Content-Type": "application/octet-stream" }, body: blob.stream().pipeThrough(progressTrackingStream), duplex: "half", });

      // After the initial response headers have been received, display download progress for the response body let success = true; const totalDownloadBytes = response.headers.get("content-length"); let bytesDownloaded = 0; const reader = response.body.getReader(); while (true) { try { const { value, done } = await reader.read(); if (done) { break; } bytesDownloaded += value.length; if (totalDownloadBytes != undefined) { console.log("download progress:", bytesDownloaded / totalDownloadBytes); downloadProgress.value = bytesDownloaded / totalDownloadBytes; } else { console.log("download progress:", bytesDownloaded, ", unknown total"); } } catch (error) { console.error("error:", error); success = false; break; } }

      console.log("success:", success); } main().catch(console.error); ```

    1. On any Web page run the following code

      js await startLocalServer(); let abortable = new AbortController; let {signal} = abortable; (await fetch('https://localhost:8443', { method: 'post', body: 'cat local_server_export.js', // Code executed in server, piped to browser duplex: 'half', headers: { 'Access-Control-Request-Private-Network': true }, signal })).body.pipeThrough(new TextDecoderStream()).pipeTo(new WritableStream({ write(v) { console.log(v); }, close() { console.log('close'); }, abort(reason) { console.log(reason); } })).catch(console.warn); await resetLocalServer();

    1. The Hibernation API allows a Durable Object that is not currently running an event handler, such as handling a WebSocket message, HTTP request, or alarm, to be removed from memory while keeping its WebSockets connected (“hibernation”).
  2. Jun 2023
    1. ```sparql PREFIX pm20: http://purl.org/pressemappe20/folder/ PREFIX p: http://www.wikidata.org/prop/ PREFIX pq: http://www.wikidata.org/prop/qualifier/ PREFIX skos: http://www.w3.org/2004/02/skos/core# PREFIX wdt: http://www.wikidata.org/prop/direct/ PREFIX wd: http://www.wikidata.org/entity/

      SELECT ?wd ?skosRelation ?pm20

      construct {

      ?wd ?skosRelation ?pm20 .

      }

      where { service https://query.wikidata.org/sparql { # wd items with PM20 ID ?wd wdt:P4293 ?pm20Id . filter(isLiteral(?pm20Id)) # # mapping relation optional { ?wd p:P4293/pq:P4390 ?relation . # URL of the equivalent skos property ?relation wdt:P2699 ?skosRelation1 . } } # bind as URIs bind(uri(concat('http://purl.org/pressemappe20/folder/', ?pm20Id)) as ?pm20) bind(if(bound(?skosRelation1), ?skosRelation1, uri('http://www.w3.org/2004/02/skos/core#exactMatch')) as ?skosRelation) } ```

    1. There are many different types of controlled vocabularies, the most common among them are: Thesaurus - a type of controlled vocabulary used in information systems that organizes concepts in hierarchical and/or associative relationships and provides their semantic definitions Classification schema - a system that based primarily on classifying things or concepts into groups or classes with a detailed explanation of those classification methods Subject heading list - a list of terms describing subjects in information system Taxonomy - a system that organizes things and concepts in groups based on their common characteristics and/or differences Terminology - a list of terms used to describe concepts in a certain domain Glossary - an alphabetical list of terms with their explanation used in a specific context