Congratulations!

[Valid Atom 1.0] This is a valid Atom 1.0 feed.

Recommendations

This feed is valid, but interoperability with the widest range of feed readers could be improved by implementing the following recommendations.

Source: https://www.raymondcamden.com/feed.xml

  1. <?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet href="/rss.xsl" type="text/xsl"?>
  2. <feed xmlns="http://www.w3.org/2005/Atom">
  3.    <title>Raymond Camden</title>
  4.    <link href="https://www.raymondcamden.com/feed.xml" rel="self" type="application/atom+xml"></link>
  5.    <link href="https://www.raymondcamden.com/" rel="alternate" type="text/html"></link>
  6.    <subtitle>Father, husband, developer relations and web standards expert, and cat demo builder.</subtitle>
  7.  
  8.    <updated>2024-09-05T21:47:42+00:00</updated>
  9.    <author>
  10.        <name>Raymond Camden</name>
  11.        <email>raymondcamden@gmail.com</email>
  12.    </author>
  13.    <id>https://www.raymondcamden.com/feed.xml</id>
  14.  
  15.    <generator>Eleventy</generator>
  16.  
  17.        
  18.            <entry>
  19.                <id>https://www.raymondcamden.com/2024/09/05/using-pdf-content-with-google-gemini-an-update</id>
  20.                <title>Using PDF Content with Google Gemini - An Update</title>
  21.                <updated>2024-09-05T18:00:00+00:00</updated>
  22.                <link href="https://www.raymondcamden.com/2024/09/05/using-pdf-content-with-google-gemini-an-update" rel="alternate" type="text/html" title="Using PDF Content with Google Gemini - An Update"/>
  23.                <content type="html">
  24.                        &lt;p&gt;Way back in March of this year, I took a look at using Google&apos;s Gemini APIs to analyze PDF documents (&lt;a href=&quot;https://www.raymondcamden.com/2024/03/22/using-pdf-content-with-google-gemini&quot;&gt;&amp;quot;Using PDF Content with Google Gemini&amp;quot;&lt;/a&gt;). At the time, the Gemini API didn&apos;t support PDF documents, so I made use of our (Adobe) &lt;a href=&quot;https://developer.adobe.com/document-services/apis/pdf-extract/&quot;&gt;PDF Extract&lt;/a&gt; service to get the text content out from the document. This &amp;quot;worked&amp;quot; but was possibly less than ideal as my &amp;quot;glom all the text together&amp;quot; approach didn&apos;t really represent the PDF well. The PDF Extract API returns information about text context (like if it is a header for example), but my method ignored that. I&apos;m happy to share that Gemini now supports PDF files natively. Let&apos;s take a look at how this works.&lt;/p&gt;&lt;h2 id=&quot;uploading-pdfs&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#uploading-pdfs&quot;&gt;Uploading PDFs&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;To begin, you need to provide your PDF to Gemini. This is done via the Files API. I &lt;a href=&quot;https://www.raymondcamden.com/2024/05/21/using-the-gemini-file-api-for-prompts-with-media&quot;&gt;blogged&lt;/a&gt; about this a few months ago and it&apos;s a rather simple process. You can upload files up to 2 gigs with a limit of 20 per project. These files are stored temporarily, but last for 48 hours so you can absolutely upload, do some &amp;quot;stuff&amp;quot;, and then either delete them via an API call or let them expire naturally.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://static.raymondcamden.com/images/2024/09/yourfile.jpg&quot; alt=&quot;A tombstone with the words, Your File&quot; class=&quot;imgcenter&quot; loading=&quot;lazy&quot;&gt;&lt;/p&gt;&lt;p&gt;That aspect of the code hasn&apos;t changed, but I&apos;ll share the general function here.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;import { GoogleAIFileManager } from &amp;quot;@google/generative-ai/server&amp;quot;;const fileManager = new GoogleAIFileManager(API_KEY);const uploadResponse = await fileManager.uploadFile(&amp;quot;adobe_security_properly_ocr.pdf&amp;quot;, {  mimeType: &amp;quot;application/pdf&amp;quot;,  displayName: &amp;quot;Adobe Security PDF&amp;quot;,});&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;summarizing-the-file&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#summarizing-the-file&quot;&gt;Summarizing the File&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Once the file is uploaded, you then just include the reference in your prompt. Again, this is no different than what I showed in that &lt;a href=&quot;https://www.raymondcamden.com/2024/05/21/using-the-gemini-file-api-for-prompts-with-media&quot;&gt;earlier post&lt;/a&gt;, but here it is in action:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;import { GoogleGenerativeAI } from &amp;quot;@google/generative-ai&amp;quot;;const genAI = new GoogleGenerativeAI(API_KEY);const model = genAI.getGenerativeModel({  // Choose a Gemini model.  model: &amp;quot;gemini-1.5-flash&amp;quot;,});// Generate content using text and the URI reference for the uploaded file.let result = await model.generateContent([    {      fileData: {        mimeType: uploadResponse.file.mimeType,        fileUri: uploadResponse.file.uri      }    },    { text: &amp;quot;Can you summarize this document as a bulleted list?&amp;quot; },  ]);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And that&apos;s literally it. For an incredibly exciting document relating to Adobe&apos;s security policies, I get:&lt;/p&gt;&lt;div style=&quot;background-color: #c0c0c0; padding: 10px&quot;&gt;The document &quot;Adobe Vendor Security Review Program White Paper&quot; outlines the process and requirements for vendors that handle Adobe data. Here is a summary:&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Adobe Vendor Security Review (VSR) Program:&lt;/strong&gt;  A program managed by Adobe Information Security that evaluates third-party vendors&apos; compliance with the Adobe Vendor Information Security Standard.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;VSR Process:&lt;/strong&gt;&lt;ul&gt;&lt;li&gt;Adobe business owners initiate the VSR process by submitting a request with information about the vendor and the data being handled.&lt;/li&gt;&lt;li&gt;Adobe sends a questionnaire to the vendor, covering security controls.&lt;/li&gt;&lt;li&gt;Adobe Information Security analysts review the questionnaire, perform a gap assessment, and assign a risk level.&lt;/li&gt;&lt;li&gt;A risk analyst discusses any gaps with the business owner and provides remediation suggestions.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Data Classification:&lt;/strong&gt;&lt;ul&gt;&lt;li&gt;Adobe uses a four-tier data classification system to define the sensitivity of data and establish handling requirements:&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Adobe Restricted:&lt;/strong&gt; The most sensitive data, requiring limited access and strict controls. Examples: cardholder data, social security numbers, bank account numbers, passport information.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Adobe Confidential:&lt;/strong&gt; Data that would cause significant harm if disclosed. Examples: salary information, product roadmaps, financial data.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Adobe Internal:&lt;/strong&gt; Data that is sensitive within Adobe, but not as critical as Confidential or Restricted. Examples: operational planning documents, internal communications.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Public data:&lt;/strong&gt; Information that is openly available.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Vendor Engagement:&lt;/strong&gt;&lt;ul&gt;&lt;li&gt;Vendors must undergo VSRs annually or biannually, depending on the data classification they handle.&lt;/li&gt;&lt;li&gt;Vendors must comply with the most restrictive classification if data falls under multiple classifications.&lt;/li&gt;&lt;li&gt;Vendors must handle all data according to the Data Classification and Handling Standard.&lt;/li&gt;&lt;li&gt;Adobe may take disciplinary action if data is handled incorrectly.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The VSR program is a critical component of Adobe&apos;s information security strategy, ensuring that third-party vendors comply with Adobe&apos;s security standards and protect sensitive data.&lt;/p&gt;&lt;/div&gt;&lt;p&gt;Summarizing is just one thing you can do of course, I also tried a prompt for categorization:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Return a list of categories that define the content of this document. Return your result as a comma-delimited list.&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Using the same upload reference, I got this:&lt;/p&gt;&lt;div style=&quot;background-color: #c0c0c0; padding: 10px&quot;&gt;Information Security, Data Classification, Vendor Security, Security Review Process, Vendor Information Security Standard,  Vendor Risk Assessment, Policy, Security Management, Data Handling, Legal Obligations, Privacy Assessment, Data Retention, Due Diligence, Auditing, Compliance&lt;/div&gt;&lt;p&gt;This seemed to work well, but I&apos;d be curious to know if you could restrict the returned categories to a certain set. I haven&apos;t tested that yet, and of course, you could keep a &apos;sanitized&apos; list in code and only use results that match.&lt;/p&gt;&lt;p&gt;Here&apos;s the entire script for this demo (and I&apos;ll link to the repo at the end):&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;import { GoogleAIFileManager } from &amp;quot;@google/generative-ai/server&amp;quot;;import { GoogleGenerativeAI } from &amp;quot;@google/generative-ai&amp;quot;;let API_KEY = process.env.GOOGLE_AI_KEY;// Initialize GoogleAIFileManager with your API_KEY.const fileManager = new GoogleAIFileManager(API_KEY);const genAI = new GoogleGenerativeAI(API_KEY);const model = genAI.getGenerativeModel({  // Choose a Gemini model.  model: &amp;quot;gemini-1.5-flash&amp;quot;,});// Upload the file and specify a display name.const uploadResponse = await fileManager.uploadFile(&amp;quot;adobe_security_properly_ocr.pdf&amp;quot;, {  mimeType: &amp;quot;application/pdf&amp;quot;,  displayName: &amp;quot;Adobe Security PDF&amp;quot;,});// Generate content using text and the URI reference for the uploaded file.let result = await model.generateContent([    {      fileData: {        mimeType: uploadResponse.file.mimeType,        fileUri: uploadResponse.file.uri      }    },    { text: &amp;quot;Can you summarize this document as a bulleted list?&amp;quot; },  ]);// Output the generated text to the consoleconsole.log(result.response.text())console.log(&apos;-&apos;.repeat(80));result = await model.generateContent([    {      fileData: {        mimeType: uploadResponse.file.mimeType,        fileUri: uploadResponse.file.uri      }    },    { text: &amp;quot;Return a list of categories that define the content of this document. Return your result as a comma-delimited list.&amp;quot; },  ]);// Output the generated text to the consoleconsole.log(result.response.text())&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;working-with-multiple-documents&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#working-with-multiple-documents&quot;&gt;Working with Multiple Documents&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Of course, the benefits can get even better if you want to work with multiple documents at once. In order for that to work, you just upload more items, and refer to them in your prompt. For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;// Upload the file and specify a display name.const uploadResponse = await fileManager.uploadFile(&amp;quot;hamlet.pdf&amp;quot;, {  mimeType: &amp;quot;application/pdf&amp;quot;,  displayName: &amp;quot;Hamlet&amp;quot;,});const uploadResponse2 = await fileManager.uploadFile(&amp;quot;romeo-and-juliet.pdf&amp;quot;, {  mimeType: &amp;quot;application/pdf&amp;quot;,  displayName: &amp;quot;Romeo and Juliet&amp;quot;,});&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;That&apos;s the uploads, and here they are in use in a prompt:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;let result = await model.generateContent([    {      fileData: {        mimeType: uploadResponse.file.mimeType,        fileUri: uploadResponse.file.uri      }    },    {      fileData: {        mimeType: uploadResponse2.file.mimeType,        fileUri: uploadResponse2.file.uri      }    },    { text: &amp;quot;Compare these two plays and discuss similar themes as well as major differences.&amp;quot; },  ]);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is what I got comparing Hamlet and Romeo and Juliet:&lt;/p&gt;&lt;div style=&quot;background-color: #c0c0c0; padding: 10px&quot;&gt;Both *Hamlet* and *Romeo and Juliet* are tragedies written by William Shakespeare. They both share common themes but also exhibit significant differences.&lt;p&gt;&lt;strong&gt;Similarities:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Love and Death:&lt;/strong&gt; Both plays explore the themes of love and death, with romantic love leading to tragic consequences. In &lt;em&gt;Hamlet&lt;/em&gt;, Hamlet&apos;s love for Ophelia and his own sense of loss and grief contribute to his downfall. In &lt;em&gt;Romeo and Juliet&lt;/em&gt;, the young lovers&apos; passionate love leads to their tragic demise.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Fate and Destiny:&lt;/strong&gt;  A sense of fate and destiny pervades both plays. Hamlet struggles to understand his role in a world seemingly ruled by fate, while Romeo and Juliet are victims of a long-standing feud and seemingly unavoidable circumstances.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Family and Loyalty:&lt;/strong&gt; Family loyalty and conflict play crucial roles. Hamlet&apos;s relationship with his mother and uncle drives his actions, while the feud between the Montagues and Capulets shapes the destiny of Romeo and Juliet.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Revenge:&lt;/strong&gt;  The desire for revenge motivates characters in both plays. Hamlet seeks to avenge his father&apos;s murder, while Romeo seeks to avenge Mercutio&apos;s death.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Corruption and Decay:&lt;/strong&gt; Both plays feature a sense of corruption and decay in society and within individuals. Hamlet finds himself in a corrupt court, and his own sanity deteriorates, while &lt;em&gt;Romeo and Juliet&lt;/em&gt; depicts a world plagued by violence and hatred.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Differences:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Internal vs. External Conflict:&lt;/strong&gt; Hamlet is driven primarily by internal conflict. He struggles with grief, madness, and the weight of his own thoughts and actions. Romeo and Juliet, on the other hand, are caught in a larger external conflict: the feud between their families.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Revenge:&lt;/strong&gt; Hamlet&apos;s revenge is more complex and internalized, driven by a deep sense of justice and morality. Romeo&apos;s revenge is more immediate and driven by passion.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Focus on Individual vs. Society:&lt;/strong&gt; Hamlet is a more introspective play that delves into the mind of one individual. Romeo and Juliet, on the other hand, focuses more on the destructive power of social forces and the impact of a feud on society.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Language:&lt;/strong&gt; &lt;em&gt;Hamlet&lt;/em&gt; is characterized by its complex and philosophical language, often featuring soliloquies and deep musings. &lt;em&gt;Romeo and Juliet&lt;/em&gt;, while also beautiful, uses more lyrical and romantic language, focusing on passionate expressions of love and longing.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;In conclusion, both &lt;em&gt;Hamlet&lt;/em&gt; and &lt;em&gt;Romeo and Juliet&lt;/em&gt; are powerful and enduring tragedies that explore universal themes of love, death, fate, and the human condition. While they share similarities in themes, their focus on conflict and their approach to characters and language create distinct dramatic experiences. &lt;em&gt;Hamlet&lt;/em&gt; delves into the complexities of individual psychology and morality, while &lt;em&gt;Romeo and Juliet&lt;/em&gt; explores the destructive power of external forces and societal conflict.&lt;/p&gt;&lt;/div&gt;&lt;p&gt;It&apos;s been a while since I&apos;ve read these plays, but it feels like a pretty good comparison. Here&apos;s that script:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;import { GoogleAIFileManager } from &amp;quot;@google/generative-ai/server&amp;quot;;import { GoogleGenerativeAI } from &amp;quot;@google/generative-ai&amp;quot;;let API_KEY = process.env.GOOGLE_AI_KEY;// Initialize GoogleAIFileManager with your API_KEY.const fileManager = new GoogleAIFileManager(API_KEY);const genAI = new GoogleGenerativeAI(API_KEY);const model = genAI.getGenerativeModel({  // Choose a Gemini model.  model: &amp;quot;gemini-1.5-flash&amp;quot;,});// Upload the file and specify a display name.const uploadResponse = await fileManager.uploadFile(&amp;quot;hamlet.pdf&amp;quot;, {  mimeType: &amp;quot;application/pdf&amp;quot;,  displayName: &amp;quot;Hamlet&amp;quot;,});const uploadResponse2 = await fileManager.uploadFile(&amp;quot;romeo-and-juliet.pdf&amp;quot;, {  mimeType: &amp;quot;application/pdf&amp;quot;,  displayName: &amp;quot;Romeo and Juliet&amp;quot;,});console.log(&apos;Uploaded both files.&apos;);// Generate content using text and the URI reference for the uploaded file.let result = await model.generateContent([    {      fileData: {        mimeType: uploadResponse.file.mimeType,        fileUri: uploadResponse.file.uri      }    },    {      fileData: {        mimeType: uploadResponse2.file.mimeType,        fileUri: uploadResponse2.file.uri      }    },    { text: &amp;quot;Compare these two plays and discuss similar themes as well as major differences.&amp;quot; },  ]);// Output the generated text to the consoleconsole.log(result.response.text())console.log(&apos;-&apos;.repeat(80));&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;making-it-generic&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#making-it-generic&quot;&gt;Making it Generic&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;The power in this comes from automation of course. You could imagine a process that responds to new PDFs being added to a directory, uses Gemini for a summary, and stores that result in a database for use later. And it&apos;s also totally fair to expect that the summary will be off, incomplete, and so forth, and therefore any tool should make it easy for an administrator to tweak.&lt;/p&gt;&lt;p&gt;As a super simple example, here&apos;s a script that will summarize at the command line:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;import { GoogleAIFileManager } from &amp;quot;@google/generative-ai/server&amp;quot;;import { GoogleGenerativeAI } from &amp;quot;@google/generative-ai&amp;quot;;let API_KEY = process.env.GOOGLE_AI_KEY;// Initialize GoogleAIFileManager with your API_KEY.const fileManager = new GoogleAIFileManager(API_KEY);const genAI = new GoogleGenerativeAI(API_KEY);const model = genAI.getGenerativeModel({  // Choose a Gemini model.  model: &amp;quot;gemini-1.5-flash&amp;quot;,});async function uploadFile(path) {  // assumes /, kinda bad  let name = path.split(&apos;/&apos;).pop();  // Upload the file and specify a display name.  return await fileManager.uploadFile(path, {    mimeType: &amp;quot;application/pdf&amp;quot;,    displayName: name,  });};async function summarize(upload) {  return (await model.generateContent([      {        fileData: {          mimeType: upload.file.mimeType,          fileUri: upload.file.uri        }    },    { text: &amp;quot;Can you summarize this document?&amp;quot; },    ])).response.text();}if(process.argv.length &amp;lt; 3) {  console.log(&apos;Pass a path to a PDF file to use this tool.&apos;);  process.exit();}let path = process.argv[2];console.log(`Upload ${path}`);let upload = await uploadFile(path);console.log(&apos;Asking for a summary...&apos;);let summary = await summarize(upload);console.log(&apos;-&apos;.repeat(80));console.log(summary);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can find these scripts, and my source PDFs, as well as a few other tests, up in my repo here: &lt;a href=&quot;https://github.com/cfjedimaster/ai-testingzone/tree/main/pdf_test&quot;&gt;https://github.com/cfjedimaster/ai-testingzone/tree/main/pdf_test&lt;/a&gt; Let me know what you think!&lt;/p&gt;
  25.                        
  26.                
  27. </content>
  28.  
  29.                
  30.                <category term="generative ai" />
  31.                
  32.                
  33.                <category term="javascript" />
  34.                
  35.                <author>
  36.                    <name>Raymond Camden</name>
  37.                    <email>raymondcamden@gmail.com</email>
  38.                </author>
  39.            </entry>
  40.        
  41.            <entry>
  42.                <id>https://www.raymondcamden.com/2024/09/04/next-codebr-and-vote-for-my-ai-demo</id>
  43.                <title>Next &lt;Code&gt;&lt;Br&gt;, and Vote For My AI Demo!</title>
  44.                <updated>2024-09-04T18:00:00+00:00</updated>
  45.                <link href="https://www.raymondcamden.com/2024/09/04/next-codebr-and-vote-for-my-ai-demo" rel="alternate" type="text/html" title="Next &lt;Code&gt;&lt;Br&gt;, and Vote For My AI Demo!"/>
  46.                <content type="html">
  47.                        &lt;p&gt;Greetings, programs. This is just a quick note about my &lt;code&gt;&amp;lt;Code&amp;gt;&amp;lt;Br&amp;gt;&lt;/code&gt; show. Usually the show goes on every two weeks, but with the holiday this week I pushed it off to September 17th. You can find the details and RSVP here: &lt;a href=&quot;https://cfe.dev/talkshows/codebreak-09172024/&quot;&gt;&amp;quot;Parks and Recreation - Using Leaflet and the NPS&amp;quot;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;As the link says, this will be another stream involving &lt;a href=&quot;https://leaflet.js&quot;&gt;Leaflet&lt;/a&gt;, which I&apos;ve been having a &lt;em&gt;hell&lt;/em&gt; of a lot of fun with the last few weeks. I hope to see you there!&lt;/p&gt;&lt;p&gt;And then on a completely &lt;em&gt;different&lt;/em&gt; topic, I&apos;ve entered the &lt;a href=&quot;https://ai.google.dev/competition&quot;&gt;Gemini API Developer Competition&lt;/a&gt; and honestly, I&apos;ve probably got no chance to actually win, but I&apos;d love for you to take a look at my entry, &lt;a href=&quot;https://ai.google.dev/competition/projects/content-assistant&quot;&gt;Content Assistant&lt;/a&gt;, and give it a vote if you like it. I&apos;m also ok with you voting for it if you don&apos;t like it. ;) To be honest, it&apos;s an incredibly simple demo, but it felt like a decent example of the use of gen AI. Watch the video and tell me what you think.&lt;/p&gt;
  48.                        
  49.                
  50. </content>
  51.  
  52.                
  53.                
  54.                <category term="misc" />
  55.                
  56.                <author>
  57.                    <name>Raymond Camden</name>
  58.                    <email>raymondcamden@gmail.com</email>
  59.                </author>
  60.            </entry>
  61.        
  62.            <entry>
  63.                <id>https://www.raymondcamden.com/2024/09/02/using-csv-data-with-leaflet</id>
  64.                <title>Using CSV Data with Leaflet</title>
  65.                <updated>2024-09-02T18:00:00+00:00</updated>
  66.                <link href="https://www.raymondcamden.com/2024/09/02/using-csv-data-with-leaflet" rel="alternate" type="text/html" title="Using CSV Data with Leaflet"/>
  67.                <content type="html">
  68.                        &lt;p&gt;As I continue to play with, and really freaking enjoy &lt;a href=&quot;https://leafletjs.com/&quot;&gt;Leaflet&lt;/a&gt;, I thought it would be interesting to show a demo of using CSV data with it. This also coincides with an interesting dataset I got from the &lt;a href=&quot;https://www.data-is-plural.com/&quot;&gt;Data is Plural&lt;/a&gt; newsletter, a collection of datasets covering just about any topic you can imagine.&lt;/p&gt;&lt;p&gt;A few weeks back, they shared &lt;a href=&quot;https://docs.google.com/spreadsheets/d/11fk5YeQ4eFOnYSBNpUdHp4TP42gJ7wY5/edit?gid=970169931#gid=970169931&quot;&gt;ancient shipwrecks&lt;/a&gt; covering the years from 1500 BC to 1500 AD. I know, that&apos;s a bit random, but I thought it was kinda cool. The dataset covers near two thousand unique shipwrecks and includes information, at times, about the cargo that was being carried. I thought this would be fun to map, and here&apos;s how I did it.&lt;/p&gt;&lt;h2 id=&quot;working-with-cvs&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#working-with-cvs&quot;&gt;Working with CVS&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Disregarding the map, the first thing I needed to do was parse the CSV. I turned to a solution I&apos;ve used many times in the past, &lt;a href=&quot;https://www.papaparse.com/&quot;&gt;Papa Parse&lt;/a&gt;. Papa Parse is a JavaScript library for - wait for it - parsing CSV files. It&apos;s worked perfectly for me in the past, and did so mostly this time, with one small issue.&lt;/p&gt;&lt;p&gt;I wrote a function to handle parsing my data so I could use it with Leaflet. I began with this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;async function getData() { return new Promise((resolve, reject) =&amp;gt; { Papa.parse(&apos;https://assets.codepen.io/74045/shipwrecks2.csv&apos;, { download:true, header:true, complete:(results) =&amp;gt; { resolve(results.data); } }); });}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;From the top, I provide the URL (hosted as an asset on CodePen), and specify the following arguments:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;code&gt;download:true&lt;/code&gt; - this is how you tell Papa Parse that the first argument is a URL to be fetched&lt;/li&gt;&lt;li&gt;&lt;code&gt;header:true&lt;/code&gt; - this tells Papa Parse to consider the first row as headers and to map the results to use those names&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The final argument simply lets me make use of my Promise so I can make this an async function.&lt;/p&gt;&lt;p&gt;This worked... kinda. It failed to properly parse because our data has a line &lt;em&gt;before&lt;/em&gt; the header line. Here&apos;s the first five lines:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;,,,,HARVARD MAPS/DARMC DATA,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,OXREP DATA,,,,,,,,,,,,,,,,,,,,,,,,,,DARMC_X,DARMC_Y,DARMC_OBJECTID,NAME,NAME2,Latitude,Longitude,Geo_Q,F2008_Wreck,F2010_Wreck,Geo_D,Start_Date,End_Date,Date_Q,Date_D,Depth,Depth_Q,Year_Found,Year_Found_1,Cargo_1,Cargo_Type1,Cargo_2,Cargo_Type2,Cargo_3,Cargo_Type_3,Other_Cargo,Gear,Estimated displacement,Comments,Length,Width,Size_Detail,Parker_ref,Parker?,Bibliography AFM State 2008,Bibliography_2,OXREP_locid,OXREP_Site_Name,OXREP_Wreck_Name,OXREP_Earliest_Date,OXREP_Latest_Date,OXREP_Dating_comment,OXREP_Wreck_ID,OXREP_Strauss_ID,OXREP_Parker_Number,OXREP_Sea_area,OXREP_Country,OXREP_Region,OXREP_Min_depth,OXREP_Max_depth,OXREP_Depth,OXREP_Period,OXREP_Reference,OXREP_Comments,OXREP_Stone_cargo_notes,OXREP_Other_cargo,OXREP_Hull_remains,OXREP_Shipboard_paraphernalia,OXREP_Ship_equipment,OXREP_Estimated_tonnage,,33,-316258.6733,6959356.392,34,Ellesmere, ,52.872,-2.841,ca,0,0, ,-500,500, , , ,silted,1864, , ,, ,, , , ,Paddle &amp;amp; bowl found with the boat.,0.412,,3.35,0.73, , ,0,,S. McGrail 1978.,,,,,,,,,,,,,,,,,,,,,,,,,,912,1805231.076,5322124.705,913,Krava, ,43.066667,16.216667, ,416,430, ,-400,-200, , , , , , ,amphoras,&amp;quot;Dr2-4, pear-shaped&amp;quot;, ,, , , ,, ,,0,0, ,558,1,, ,1921,Krava,Krava,-400,-200,C4th-3rd BC,7970,,558,Adriatic,Croatia,Vis,,,,Classical/Hellenistic,&amp;quot;N. Cambi in Amphores Romains et Histoire Economique, Dix Ans de Rechereches (Siena, 1986) 1989, 323-5; M . Jurisic in D. Davison, V. Gaffney and E. Martin (eds.) BAR 2006, 175-192&amp;quot;,The earliest known wreck in the Adriatic,,Grindstones and handmills,,,,,,738,1421178.833,4602997.051,739,San Vito, ,38.166667,12.766667, ,809,847, ,-400,500,?, , , , , ,amphoras,, ,, , , ,, ,,0,0, ,1025,1,, ,1413,San Vito,San Vito,-400,400,,8405,,1025,,,,,,,,,,,,,,,,,&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Sigh. So, the easiest solution (and honestly the one I did first) would be to just edit the file and remove that first line. But I was really curious to see if Papa Parse had another way of handling this. Maybe my CSV isn&apos;t a flat file per se but the result of an API call. I could still &amp;quot;edit&amp;quot; in JavaScript, but as I said, I was curious to see if the library could handle it.&lt;/p&gt;&lt;p&gt;Turns out - it could. But it couldn&apos;t. What do I mean? Papa Parse documents a configuration option, &lt;code&gt;skipFirstNLines&lt;/code&gt;, which seems perfect. I tried that... and nothing changed. I did some Googling and turns out, it&apos;s a &lt;a href=&quot;https://github.com/mholt/PapaParse/issues/1040&quot;&gt;bug&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Sigh (again). Luckily, in the bug report there was a simple workaround using the &lt;code&gt;beforeFirstChunk&lt;/code&gt; option. I used that fix below:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;async function getData() { return new Promise((resolve, reject) =&amp;gt; { // hack for skipFirstNLines: https://github.com/mholt/PapaParse/issues/1040 Papa.parse(&apos;https://assets.codepen.io/74045/shipwrecks2.csv&apos;, { download:true, header:true, beforeFirstChunk: chunk =&amp;gt; [...chunk.split(&apos;\n&apos;).slice(1)].join(&apos;\n&apos;), complete:(results) =&amp;gt; { resolve(results.data); } }); });}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Hopefully the library corrects this soon. I don&apos;t see a PR for it yet, so we&apos;ll see. That being said, I now have a generic function to translate my CSV into data.&lt;/p&gt;&lt;h2 id=&quot;using-custom-data-with-leaflet&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#using-custom-data-with-leaflet&quot;&gt;Using Custom Data with Leaflet&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;On the Leaflet side, the work here was trivial. Given a latitude and longitude, and some information for a label, here&apos;s a generic bit of code that will add a marker:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;L.marker([ latitude, longitude]).addTo(map).bindPopup(`Custom stuff here for the marker. `);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;That&apos;s literally it. Given how easy it is, here&apos;s the complete application:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;let data = await getData();let map = L.map(&apos;map&apos;).setView([48.864, 2.349], 4);L.tileLayer(&apos;https://tile.openstreetmap.org/{z}/{x}/{y}.png&apos;, {maxZoom: 16,attribution: &apos;&amp;amp;copy; &amp;lt;a href=&amp;quot;http://www.openstreetmap.org/copyright&amp;quot;&amp;gt;OpenStreetMap&amp;lt;/a&amp;gt;&apos;}).addTo(map);for(let i=0; i&amp;lt;data.length;i++) { let cargo = []; if(data[i].Cargo_1.trim() !== &apos;&apos;) cargo.push(data[i].Cargo_1); if(data[i].Cargo_2.trim() !== &apos;&apos;) cargo.push(data[i].Cargo_2); if(data[i].Cargo_3.trim() !== &apos;&apos;) cargo.push(data[i].Cargo_3); L.marker([ parseInt(data[i][&amp;quot;Latitude&amp;quot;],10), parseInt(data[i][&amp;quot;Longitude&amp;quot;],10) ]).addTo(map).bindPopup(`&amp;lt;h3&amp;gt;${data[i].NAME}&amp;lt;/h3&amp;gt;&amp;lt;p&amp;gt;&amp;lt;b&amp;gt;Found in:&amp;lt;/b&amp;gt; ${data[i].Year_Found}&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;Cargo:&amp;lt;/b&amp;gt; ${cargo.join(&apos;, &apos;)}&amp;lt;br&amp;gt; `);}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I create my map (centered on Europe), add my tiles, and then simply loop through my CSV data. There&apos;s a &lt;em&gt;lot&lt;/em&gt; of columns, but I decided to show the name and a list of cargo. Not every item has a name, or any cargo, but for those that do I&apos;ll be able to show it.&lt;/p&gt;&lt;p&gt;You can play with the demo below:&lt;/p&gt;&lt;p class=&quot;codepen&quot; data-height=&quot;600&quot; data-default-tab=&quot;result&quot; data-slug-hash=&quot;MWMPryq&quot; data-pen-title=&quot;Leaflet3&quot; data-user=&quot;cfjedimaster&quot; style=&quot;height: 600px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;&quot;&gt;  &lt;span&gt;See the Pen &lt;a href=&quot;https://codepen.io/cfjedimaster/pen/MWMPryq&quot;&gt;  Leaflet3&lt;/a&gt; by Raymond Camden (&lt;a href=&quot;https://codepen.io/cfjedimaster&quot;&gt;@cfjedimaster&lt;/a&gt;)  on &lt;a href=&quot;https://codepen.io&quot;&gt;CodePen&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;&lt;script async src=&quot;https://cpwebassets.codepen.io/assets/embed/ei.js&quot;&gt;&lt;/script&gt;&lt;h2 id=&quot;some-thoughts&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#some-thoughts&quot;&gt;Some Thoughts&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Now, it&apos;s fair to say that the data behind this map will &lt;em&gt;not&lt;/em&gt; change often. I may fetch a copy of the CSV once a month or so. I think in &amp;quot;the real world&amp;quot;, I&apos;d write code to parse the CSV in some simple local Node script and store the data as a JSON string. I&apos;d then store &lt;em&gt;that&lt;/em&gt; results in CodePen (or my website) and reduce the amount of work the application has to do to render the items. Also, I&apos;d have the opportunity to drop all those columns I&apos;m not actually using. That would make the JSON a heck of a lot smaller, again improving the performance.&lt;/p&gt;&lt;p&gt;If this exercise is something folks would like to see, just ask and I&apos;ll share!&lt;/p&gt;
  69.                        
  70.                
  71. </content>
  72.  
  73.                
  74.                <category term="javascript" />
  75.                
  76.                
  77.                <category term="development" />
  78.                
  79.                <author>
  80.                    <name>Raymond Camden</name>
  81.                    <email>raymondcamden@gmail.com</email>
  82.                </author>
  83.            </entry>
  84.        
  85.            <entry>
  86.                <id>https://www.raymondcamden.com/2024/08/31/links-for-you-8312024</id>
  87.                <title>Links For You (8/31/2024)</title>
  88.                <updated>2024-08-31T18:00:00+00:00</updated>
  89.                <link href="https://www.raymondcamden.com/2024/08/31/links-for-you-8312024" rel="alternate" type="text/html" title="Links For You (8/31/2024)"/>
  90.                <content type="html">
  91.                        &lt;p&gt;For my American readers, I hope you are able to enjoy a relaxing three day weekend. I&apos;ve got big plans to do absolutely nothing and do quite a bit of it. My September is going to be busy so I&apos;d like to try my best &lt;em&gt;not&lt;/em&gt; to think about that for the next few days. Let&apos;s get to the links!&lt;/p&gt;&lt;h2 id=&quot;one-million-checkboxes---you-won&apos;t-believe-this...&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#one-million-checkboxes---you-won&apos;t-believe-this...&quot;&gt;One Million Checkboxes - You Won&apos;t Believe This...&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;I use a note app to keep track of the links I want to share in these posts and &lt;em&gt;generally&lt;/em&gt;, I share in a FIFO manner - the oldest added links first. But this... this link comes from a post shared recently on Mastodon and frankly was way too cool to put off. I don&apos;t even want to tell you about this link, I just want you to read it. Trust me.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://eieio.games/essays/the-secret-in-one-million-checkboxes/&quot;&gt;The Secret Inside One Million Checkboxes&lt;/a&gt;&lt;/p&gt;&lt;h2 id=&quot;operating-system-selector-web-component&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#operating-system-selector-web-component&quot;&gt;Operating System Selector Web Component&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;One of my pet peeves are web sites that share documentation for one operating system only, typically OSX. &lt;a href=&quot;https://www.11ty.dev/&quot;&gt;Eleventy&lt;/a&gt; is a great example of doing it the right way - showing examples for OSX, Linux, and Windows. My friend Simon MacDonald on the &lt;a href=&quot;https://begin.com&quot;&gt;Begin&lt;/a&gt; team shared how they support this using a component that handles the toggle as well as remembers your previous setting: &lt;a href=&quot;https://begin.com/blog/posts/2024-06-25-os-selector-for-documentation-sites&quot;&gt;OS Selector for Documentation Sites&lt;/a&gt;&lt;/p&gt;&lt;h2 id=&quot;a-rant-about-front-end-development&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#a-rant-about-front-end-development&quot;&gt;A Rant about Front-end Development&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Rant is putting it nicely to be honest. This &lt;a href=&quot;https://blog.frankmtaylor.com/2024/06/20/a-rant-about-front-end-development/&quot;&gt;post&lt;/a&gt; by Frank Taylor is... a lot. Before clicking, prepare yourself for many bitter truths and even more curse words. Honestly I agree with pretty much all of it so I encourage you to read it (I mean, I&apos;m sharing it here so of course I do), but just be ready for a rough ride.&lt;/p&gt;&lt;h2 id=&quot;and-now-for-something-sweet&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#and-now-for-something-sweet&quot;&gt;And now for something sweet&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;This is gloriously wonderful video of Deborah Woll explaining Dungeons and Dragons to Jon Bernthal. It&apos;s a near perfect explanation (although to be fair I&apos;ve never played myself and I hate that I haven&apos;t yet) and seeing Jon grasp just how cool it is makes the video absolutely heartwarming.&lt;/p&gt;&lt;lite-youtube videoid=&quot;JpVJZrabMQE&quot; style=&quot;background-image: url(&apos;https://i.ytimg.com/vi/JpVJZrabMQE/hqdefault.jpg&apos;);&quot;&gt;  &lt;a href=&quot;https://youtube.com/watch?v=JpVJZrabMQE&quot; class=&quot;lty-playbtn&quot; title=&quot;Play Video&quot;&gt;    &lt;span class=&quot;lyt-visually-hidden&quot;&gt;Play Video&lt;/span&gt;  &lt;/a&gt;&lt;/lite-youtube&gt;&lt;script defer src=&quot;https://cdnjs.cloudflare.com/ajax/libs/lite-youtube-embed/0.3.2/lite-yt-embed.js&quot;&gt;&lt;/script&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/lite-youtube-embed/0.3.2/lite-yt-embed.css&quot; integrity=&quot;sha512-utq8YFW0J2abvPCECXM0zfICnIVpbEpW4lI5gl01cdJu+Ct3W6GQMszVITXMtBLJunnaTp6bbzk5pheKX2XuXQ==&quot; crossorigin=&quot;anonymous&quot; referrerpolicy=&quot;no-referrer&quot; /&gt;&lt;p&gt;
  92.                        
  93.                
  94. </content>
  95.  
  96.                
  97.                <category term="links4you" />
  98.                
  99.                
  100.                <category term="misc" />
  101.                
  102.                <author>
  103.                    <name>Raymond Camden</name>
  104.                    <email>raymondcamden@gmail.com</email>
  105.                </author>
  106.            </entry>
  107.        
  108.            <entry>
  109.                <id>https://www.raymondcamden.com/2024/08/30/building-a-general-purpose-geojson-viewer-with-leaflet</id>
  110.                <title>Building a General Purpose GeoJSON Viewer with Leaflet</title>
  111.                <updated>2024-08-30T18:00:00+00:00</updated>
  112.                <link href="https://www.raymondcamden.com/2024/08/30/building-a-general-purpose-geojson-viewer-with-leaflet" rel="alternate" type="text/html" title="Building a General Purpose GeoJSON Viewer with Leaflet"/>
  113.                <content type="html">
  114.                        &lt;p&gt;Last week I shared my &lt;a href=&quot;https://www.raymondcamden.com/2024/08/23/mapping-with-leaflet&quot;&gt;initial experiences&lt;/a&gt; with &lt;a href=&quot;https://leafletjs.com/&quot;&gt;Leaflet&lt;/a&gt; and I thought I&apos;d share a small demo I built with it - a general purpose GeoJSON viewer.&lt;/p&gt;&lt;h2 id=&quot;geojson-and-leaflet&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#geojson-and-leaflet&quot;&gt;GeoJSON and Leaflet&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;As I mentioned at the end of my last post, GeoJSON is a &lt;a href=&quot;https://geojson.org/&quot;&gt;specification&lt;/a&gt; for encoding ad hoc geographic data. Here&apos;s an example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{    &amp;quot;type&amp;quot;: &amp;quot;FeatureCollection&amp;quot;,    &amp;quot;features&amp;quot;: [        {            &amp;quot;type&amp;quot;: &amp;quot;Feature&amp;quot;,            &amp;quot;id&amp;quot;: 0,            &amp;quot;properties&amp;quot;: {                &amp;quot;Code&amp;quot;: &amp;quot;FRLA&amp;quot;,                &amp;quot;Name&amp;quot;: &amp;quot;Frederick Law Olmsted National Historic Site&amp;quot;            },            &amp;quot;geometry&amp;quot;: {                &amp;quot;type&amp;quot;: &amp;quot;Point&amp;quot;,                &amp;quot;coordinates&amp;quot;: [                    -71.13112956925647,                    42.32550867371509                ]            }        },        {            &amp;quot;type&amp;quot;: &amp;quot;Feature&amp;quot;,            &amp;quot;id&amp;quot;: 1,            &amp;quot;properties&amp;quot;: {                &amp;quot;Code&amp;quot;: &amp;quot;GLDE&amp;quot;,                &amp;quot;Name&amp;quot;: &amp;quot;Gloria Dei Church National Historic Site&amp;quot;            },            &amp;quot;geometry&amp;quot;: {                &amp;quot;type&amp;quot;: &amp;quot;Point&amp;quot;,                &amp;quot;coordinates&amp;quot;: [                    -75.14358360598474,                    39.93437740957208                ]            }        }, ]}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;GeoJSON can encode points, lines, polygons, and more, and support a &lt;code&gt;properties&lt;/code&gt; section that can have anything in it. Leaflet makes it easy to use GeoJSON. Here&apos;s the example I used in that last post:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;let dataReq = await fetch(&apos;https://assets.codepen.io/74045/national-parks.geojson&apos;);let data = await dataReq.json();L.geoJSON(data).bindPopup(function (layer) { return layer.feature.properties.Name;}).addTo(map);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;That&apos;s literally it. Given how easy this, I thought I&apos;d build a demo where the data was provided by the user.&lt;/p&gt;&lt;h2 id=&quot;the-application&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#the-application&quot;&gt;The Application&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;My application is built with simple vanilla JavaScript, no Alpine even, and lets you drop a file into the browser to load the information.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://static.raymondcamden.com/images/2024/08/leaflet.jpg&quot; alt=&quot;The Leaflet demo&quot; class=&quot;imgborder imgcenter&quot; loading=&quot;lazy&quot;&gt;&lt;/p&gt;&lt;p&gt;My code waits for &lt;code&gt;DOMContentLoaded&lt;/code&gt; and then registers event handlers for dragdrop support:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;document.addEventListener(&apos;dragover&apos;, e =&amp;gt; e.preventDefault());document.addEventListener(&apos;drop&apos;, handleDrop);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When you drop a file, I then use a bit of code to read it in.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;function handleDrop(e) { e.preventDefault(); let droppedFiles = e.dataTransfer.files; if(!droppedFiles) return; let myFile = droppedFiles[0]; let ext = myFile.name.split(&apos;.&apos;).pop(); if(ext !== &apos;geojson&apos;) { alert(&apos;Drag/drop a .geojson file only.&apos;); return; } let reader = new FileReader(); reader.onload = e =&amp;gt; { loadGeoJSON(JSON.parse(e.target.result)); }; updateStatus(&apos;Reading .geojson&apos;); reader.readAsText(myFile); }&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The &lt;code&gt;loadGeoJSON&lt;/code&gt; function handles adding the data to Leaflet:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;async function loadGeoJSON(data) { updateStatus(`.geojson loaded with ${data.features.length} features. Adding to map now.`); L.geoJSON(data, { }).bindPopup(function (layer) { return ` &amp;lt;p&amp;gt; &amp;lt;b&amp;gt;Properties:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt; &amp;lt;pre style=&apos;white-space:pre-wrap&apos;&amp;gt;&amp;lt;code&amp;gt;${JSON.stringify(layer.feature.properties,null,&apos;  &apos;)} &amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt; &amp;lt;/p&amp;gt; `; },{minWidth:450}).addTo(map);}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is pretty much the same code as before, except that my popup uses a basic dump (&lt;code&gt;stringify&lt;/code&gt;) of the &lt;code&gt;properties&lt;/code&gt; key. Note that this will &lt;em&gt;not&lt;/em&gt; work for all files, especially if there&apos;s a lot of data there. I could get fancier with my output there and perhaps add a max height with overflow. That being said, here is how it looks after adding America&apos;s parks to it (and clicking one feature):&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://static.raymondcamden.com/images/2024/08/leaflet2.jpg&quot; alt=&quot;The Leaflet demo - with data&quot; class=&quot;imgborder imgcenter&quot; loading=&quot;lazy&quot;&gt;&lt;/p&gt;&lt;p&gt;You can test it out here (full screen): &lt;a href=&quot;https://codepen.io/cfjedimaster/full/GRbxVVR&quot;&gt;https://codepen.io/cfjedimaster/full/GRbxVVR&lt;/a&gt;&lt;/p&gt;&lt;p&gt;And here&apos;s the full code:&lt;/p&gt;&lt;p class=&quot;codepen&quot; data-height=&quot;600&quot; data-default-tab=&quot;result&quot; data-slug-hash=&quot;GRbxVVR&quot; data-pen-title=&quot;Leaflet geojson viewer (v2)&quot; data-user=&quot;cfjedimaster&quot; style=&quot;height: 600px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;&quot;&gt;  &lt;span&gt;See the Pen &lt;a href=&quot;https://codepen.io/cfjedimaster/pen/GRbxVVR&quot;&gt;  Leaflet geojson viewer (v2)&lt;/a&gt; by Raymond Camden (&lt;a href=&quot;https://codepen.io/cfjedimaster&quot;&gt;@cfjedimaster&lt;/a&gt;)  on &lt;a href=&quot;https://codepen.io&quot;&gt;CodePen&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;&lt;script async src=&quot;https://cpwebassets.codepen.io/assets/embed/ei.js&quot;&gt;&lt;/script&gt;&lt;p&gt;
  115.                        
  116.                
  117. </content>
  118.  
  119.                
  120.                <category term="javascript" />
  121.                
  122.                
  123.                <category term="development" />
  124.                
  125.                <author>
  126.                    <name>Raymond Camden</name>
  127.                    <email>raymondcamden@gmail.com</email>
  128.                </author>
  129.            </entry>
  130.        
  131.            <entry>
  132.                <id>https://www.raymondcamden.com/2024/08/28/quick-example-using-azures-nodejs-sdk-for-signed-urls</id>
  133.                <title>Quick Example using Azure&apos;s Node.js SDK for Signed URLs</title>
  134.                <updated>2024-08-28T18:00:00+00:00</updated>
  135.                <link href="https://www.raymondcamden.com/2024/08/28/quick-example-using-azures-nodejs-sdk-for-signed-urls" rel="alternate" type="text/html" title="Quick Example using Azure&apos;s Node.js SDK for Signed URLs"/>
  136.                <content type="html">
  137.                        &lt;p&gt;Way back in June (wait, that&apos;s only two months ago?) I wrote up a blog post showing how to use the AWS SDK for Signed URLs: &lt;a href=&quot;https://www.raymondcamden.com/2023/06/09/quick-example-using-aws-nodejs-sdk-v3-for-signed-urls&quot;&gt;&amp;quot;Quick example using AWS Node.js SDK V3 for Signed URLs&amp;quot;&lt;/a&gt;. The idea for this was to cover a very specific set of functionality I needed to use along with Adobe&apos;s &lt;a href=&quot;https://developer.adobe.com/firefly-services/docs/guides/&quot;&gt;Firefly Services&lt;/a&gt;. Specifically my needs are:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Create a readable URL for a cloud storage asset&lt;/li&gt;&lt;li&gt;Create a writable URL for a cloud storage asset&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;And on top of that - also I needed to upload directly to cloud storage. I worked with &lt;a href=&quot;https://www.npmjs.com/package/@azure/storage-blob&quot;&gt;Azure Storage Blob SDK&lt;/a&gt; and came up with the following functions. Honestly, use this with a grain of salt as it &amp;quot;worked for me&amp;quot;, but I can&apos;t make any promises about how reliable/safe/etc this code is. That being said, I&apos;d love any comments or suggestions.&lt;/p&gt;&lt;h2 id=&quot;imports-and-connecting&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#imports-and-connecting&quot;&gt;Imports and Connecting&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Once I installed the SDK, I began by importing what I needed:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;import { BlobServiceClient, BlobSASPermissions, generateBlobSASQueryParameters, StorageSharedKeyCredential } from &amp;quot;@azure/storage-blob&amp;quot;;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Next, I loaded in my credentials as well as an account and container name. So to be clear, for credentials it&apos;s an Azure key that I got from my portal and a connections string. The account name was also from the portal, and finally the container name is the &apos;bucket&apos; where I&apos;m working. I feel like the connection string could be constructed dynamically, but I hard coded it. All of these values are in my environment:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;// Credentials for Azureconst AZURE_ACCOUNTNAME = process.env.AZURE_ACCOUNTNAME;const AZURE_KEY = process.env.AZURE_KEY;const AZURE_CONTAINERNAME = process.env.AZURE_CONTAINERNAME;const AZURE_CONNECTIONSTRING = process.env.AZURE_CONNECTIONSTRING;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And finally, I created my client objects:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;const blobServiceClient = BlobServiceClient.fromConnectionString(AZURE_CONNECTIONSTRING);const containerClient = blobServiceClient.getContainerClient(AZURE_CONTAINERNAME);&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;creating-read-urls&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#creating-read-urls&quot;&gt;Creating Read URLs&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;To create readable URLs, I used two functions.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;function createSASReadString(key, accountName, containerName, duration=5) { let permissions = new BlobSASPermissions(); permissions.read = true; let currentDateTime = new Date(); let expiryDateTime = new Date(currentDateTime.setMinutes(currentDateTime.getMinutes()+duration)); let blobSasModel = { containerName, permissions, expiresOn: expiryDateTime }; let credential = new StorageSharedKeyCredential(accountName,key); return generateBlobSASQueryParameters(blobSasModel,credential);}function getSignedDownloadUrl(name, key, accountName, containerName) { let b = containerClient.getBlockBlobClient(name); return b.url + &apos;?&apos; + createSASReadString(key, accountName, containerName);}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Note that &lt;code&gt;getSignedDownloadUrl&lt;/code&gt; chains to &lt;code&gt;createSASReadString&lt;/code&gt; and doesn&apos;t modify the &lt;code&gt;duration&lt;/code&gt;, I could update that. And honestly, looking at this now, I think it should be one function. When I was building this, I thought I&apos;d be reusing &lt;code&gt;createSASReadString&lt;/code&gt; a few times but I don&apos;t think I did. You could easily wrap those two together and I may do so in the future.&lt;/p&gt;&lt;p&gt;Using it then is as simple as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;let inputURL = await getSignedDownloadUrl(fileName, AZURE_KEY, AZURE_ACCOUNTNAME, AZURE_CONTAINERNAME);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Note that I&apos;m passing in my auth stuff. In that &lt;a href=&quot;https://www.raymondcamden.com/2023/06/09/quick-example-using-aws-nodejs-sdk-v3-for-signed-urls&quot;&gt;previous blog post&lt;/a&gt; the methods I wrote used the global s3 objects which is &amp;quot;bad&amp;quot;, but is simpler as well. I thought the approach above was a bit more generic and pure.&lt;/p&gt;&lt;p&gt;I don&apos;t want to get that caught up in it though - feel free to modify what I build. ;)&lt;/p&gt;&lt;h2 id=&quot;creating-write-urls&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#creating-write-urls&quot;&gt;Creating Write URLs&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;On the flip side, here&apos;s the method to create writable URLs. This can be handed off, for example to the Photoshop APIs, and used for outputs.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;async function getSignedUploadUrl(name, client, containerName, duration=5) { let permissions = new BlobSASPermissions(); permissions.write = true; let currentDateTime = new Date(); let expiryDateTime = new Date(currentDateTime.setMinutes(currentDateTime.getMinutes()+duration)); let blobSasModel = { containerName, permissions, expiresOn: expiryDateTime }; let tempBlockBlobClient = client.getBlockBlobClient(name); return await tempBlockBlobClient.generateSasUrl(blobSasModel);}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Using it looks like so:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;let outputInvertedURL = await getSignedUploadUrl(fileName, containerClient, AZURE_CONTAINERNAME);&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;uploading-to-azure&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#uploading-to-azure&quot;&gt;Uploading to Azure&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;Normally I didn&apos;t have to worry about uploading to Azure. If I made an upload URL and the API used it, then I didn&apos;t need to worry about it. But I was curious how it would work. My &apos;usual&apos; upload code failed because Azure requires a special header. Here&apos;s the function:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;async function uploadFile(url, filePath) { let size = fs.statSync(filePath).size; await fetch(url, { method:&apos;PUT&apos;, headers: { &apos;Content-Type&apos;:&apos;image/*&apos;, &apos;Content-Length&apos;:size, &apos;x-ms-blob-type&apos;:&apos;BlockBlob&apos; }, body: fs.readFileSync(filePath) });}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;That &lt;code&gt;x-ms-blob-type&lt;/code&gt; is the special header you need. Also note I&apos;ve hard coded an image content-type. You could make that an argument or get the value dynamically.&lt;/p&gt;&lt;p&gt;Using it just requires the URL, which you get from the previous method, and a file path:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;// sourceInput is something like ./cats_rules.jpg&apos;let fileName = sourceInput.split(&apos;/&apos;).pop();let uploadURL = await getSignedUploadUrl(fileName, containerClient, AZURE_CONTAINERNAME);await uploadFile(uploadURL, sourceInput);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;That&apos;s it. I hope this helps because this post is the post I wish I had found when I started. ;)&lt;/p&gt;
  138.                        
  139.                
  140. </content>
  141.  
  142.                
  143.                <category term="javascript" />
  144.                
  145.                
  146.                <category term="development" />
  147.                
  148.                <author>
  149.                    <name>Raymond Camden</name>
  150.                    <email>raymondcamden@gmail.com</email>
  151.                </author>
  152.            </entry>
  153.        
  154.            <entry>
  155.                <id>https://www.raymondcamden.com/2024/08/23/mapping-with-leaflet</id>
  156.                <title>Mapping with Leaflet</title>
  157.                <updated>2024-08-23T18:00:00+00:00</updated>
  158.                <link href="https://www.raymondcamden.com/2024/08/23/mapping-with-leaflet" rel="alternate" type="text/html" title="Mapping with Leaflet"/>
  159.                <content type="html">
  160.                        &lt;p&gt;If you missed my &lt;a href=&quot;https://cfe.dev/talkshow/code-break/&quot;&gt;&lt;code&gt;&amp;lt;Code&amp;gt;&amp;lt;Br&amp;gt;&lt;/code&gt;&lt;/a&gt; episode earlier this week you missed (imo) a great episode. I&apos;ll share a link to the video at the end, but I spent the session raving about how great the &lt;a href=&quot;https://leafletjs.com/&quot;&gt;Leaflet&lt;/a&gt; JavaScript library is for maps. I had it on my list to look into for a few months now and while having a layover recently I took the time to dig into it. I was - blown away.&lt;/p&gt;&lt;p&gt;I&apos;ve got a lot of experience over the years working with maps on the web. I really dig Google Maps, both the JavaScript library and APIs, and I spent some time as a developer evangelist for &lt;a href=&quot;https://here.com&quot;&gt;HERE&lt;/a&gt; helping others learn about their offerings. I&apos;m obviously a bit biased but I really dug their offerings as well.&lt;/p&gt;&lt;p&gt;That being said, I was incredibly impressed with just how simple Leaflet is. Their &lt;a href=&quot;https://leafletjs.com/examples/quick-start/&quot;&gt;quickl start&lt;/a&gt; has you up and running within minutes. As I played with it and wondered, &amp;quot;how do I do X&amp;quot;, every time I googled I found an answer and typically - it was pretty trivial.&lt;/p&gt;&lt;p&gt;I don&apos;t want this post to be a rehash of their &lt;a href=&quot;https://leafletjs.com/examples/quick-start/&quot;&gt;guide&lt;/a&gt;, you really should check it out, but I thought I&apos;d show a few quick samples just to give you an idea of the level of effort required to work with the library.&lt;/p&gt;&lt;p&gt;Now before I get started, let me point out that Leaflet is &amp;quot;just&amp;quot; the top level framework for working with map data. You have to bring in your own tiles. Their quick start demonstrates this. Also, you won&apos;t find features like routing, geocoding or reverse geocoding, and so forth. You could absolutely mix in those APIs from other providers of course, but if you ended up using Google Maps or HERE, I&apos;d probably just suggest using their front-end code as well. The point is, you&apos;ve got options.&lt;/p&gt;&lt;p&gt;With that being said, let&apos;s consider a few examples.&lt;/p&gt;&lt;h2 id=&quot;store-maps&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#store-maps&quot;&gt;Store Maps&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;For a few example, a real world use case could be plotting stores on a map for a company. Those stores could come from a database/backend API/etc, but honestly, if you are a small company with a few locations, you can just hard code em. In a few months or years when you open a new store, first off, congrats, and secondly, you can just add one more line of code.&lt;/p&gt;&lt;p&gt;Leaflet requires one JavaScript and CSS resource:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&amp;lt;script src=&amp;quot;https://unpkg.com/leaflet@1.9.4/dist/leaflet.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;https://unpkg.com/leaflet@1.9.4/dist/leaflet.css&amp;quot;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;HTML wise, like other mapping solutions, you provide a div and simple css:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&amp;lt;div id=&amp;quot;map&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;style&amp;gt;#map { height: 600px; width: 600px;}&amp;lt;/style&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now for the JavaScript. We need to center logically, in this case the region where our stores are:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;let map = L.map(&apos;map&apos;).setView([30.216, -92.033], 13);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then add our tiles, ie the actual map:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;L.tileLayer(&apos;https://tile.openstreetmap.org/{z}/{x}/{y}.png&apos;, {    maxZoom: 10,    attribution: &apos;&amp;amp;copy; &amp;lt;a href=&amp;quot;http://www.openstreetmap.org/copyright&amp;quot;&amp;gt;OpenStreetMap&amp;lt;/a&amp;gt;&apos;}).addTo(map);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now let&apos;s add 3 markers for stores:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;let marker = L.marker([30.1, -92.09]).addTo(map);marker = L.marker([30.3, -92.06]).addTo(map);marker = L.marker([30.1, -91.8]).addTo(map);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And how about some info about each store?&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;let marker = L.marker([30.1, -92.09]).addTo(map);marker.bindPopup(&apos;&amp;lt;b&amp;gt;Store One&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Open 9-5 M-F&apos;);marker = L.marker([30.3, -92.06]).addTo(map);marker.bindPopup(&apos;&amp;lt;b&amp;gt;Store Two&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Open 9-5 M-F&apos;);marker = L.marker([30.1, -91.8]).addTo(map);marker.bindPopup(&apos;&amp;lt;b&amp;gt;Store Three&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Open 9-1 M-F&apos;);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And that&apos;s literally it. You can see it below:&lt;/p&gt;&lt;p class=&quot;codepen&quot; data-height=&quot;700&quot; data-theme-id=&quot;dark&quot; data-default-tab=&quot;result&quot; data-slug-hash=&quot;MWMGrrj&quot; data-pen-title=&quot;Leaflet1&quot; data-editable=&quot;true&quot; data-user=&quot;cfjedimaster&quot; style=&quot;height: 700px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;&quot;&gt;  &lt;span&gt;See the Pen &lt;a href=&quot;https://codepen.io/cfjedimaster/pen/MWMGrrj&quot;&gt;  Leaflet1&lt;/a&gt; by Raymond Camden (&lt;a href=&quot;https://codepen.io/cfjedimaster&quot;&gt;@cfjedimaster&lt;/a&gt;)  on &lt;a href=&quot;https://codepen.io&quot;&gt;CodePen&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;&lt;script async src=&quot;https://cpwebassets.codepen.io/assets/embed/ei.js&quot;&gt;&lt;/script&gt;&lt;h2 id=&quot;store-maps---but-an-api&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#store-maps---but-an-api&quot;&gt;Store Maps - But an API&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Real developers know that hard coding stuff is lame-sauce, and if you are a 10X Unicorn, you would quickly build up a serverless function backed by a database to put those stores in a persistence system that could power the universe.&lt;/p&gt;&lt;p&gt;Let&apos;s pretend we built an API:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;async function getStores() { return [ { lat: 30.1, lng: -92.09, desc: &apos;&amp;lt;b&amp;gt;Store One&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Open 9-5 M-F&apos; }, { lat: 30.3, lng: -92.06, desc: &apos;&amp;lt;b&amp;gt;Store Two&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Open 9-5 M-F&apos; }, { lat: 30.1, lng: -91.8, desc: &apos;&amp;lt;b&amp;gt;Store Three&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Open 9-1 M-F&apos; } ];}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And now our code becomes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;let map = L.map(&apos;map&apos;).setView([30.216, -92.033], 13);L.tileLayer(&apos;https://tile.openstreetmap.org/{z}/{x}/{y}.png&apos;, { maxZoom: 10, attribution: &apos;&amp;amp;copy; &amp;lt;a href=&amp;quot;http://www.openstreetmap.org/copyright&amp;quot;&amp;gt;OpenStreetMap&amp;lt;/a&amp;gt;&apos;}).addTo(map);let stores = await getStores();stores.forEach(s =&amp;gt; { let marker = L.marker([s.lat, s.lng]).addTo(map); marker.bindPopup(s.desc);});&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can see this below. It looks the same, but I get to charge Senior Developer rates.&lt;/p&gt;&lt;p class=&quot;codepen&quot; data-height=&quot;700&quot; data-theme-id=&quot;dark&quot; data-default-tab=&quot;result&quot; data-slug-hash=&quot;xxojpWp&quot; data-pen-title=&quot;Leaflet Blog 1&quot; data-editable=&quot;true&quot; data-user=&quot;cfjedimaster&quot; style=&quot;height: 700px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;&quot;&gt;  &lt;span&gt;See the Pen &lt;a href=&quot;https://codepen.io/cfjedimaster/pen/xxojpWp&quot;&gt;  Leaflet Blog 1&lt;/a&gt; by Raymond Camden (&lt;a href=&quot;https://codepen.io/cfjedimaster&quot;&gt;@cfjedimaster&lt;/a&gt;)  on &lt;a href=&quot;https://codepen.io&quot;&gt;CodePen&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;&lt;script async src=&quot;https://cpwebassets.codepen.io/assets/embed/ei.js&quot;&gt;&lt;/script&gt;&lt;h2 id=&quot;geojson&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#geojson&quot;&gt;GeoJSON&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;One of the things I enjoyed most about my time at HERE was discovering &lt;a href=&quot;https://geojson.org/&quot;&gt;GeoJSON&lt;/a&gt;. GeoJSON is a JSON style that supports ad hoc mapping data. It&apos;s incredibly flexible and used in many applications. I grabbed a copy of America&apos;s national parks as a GeoJSON file and this is how easy it is to use in Leaflet:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;let dataReq = await fetch(&apos;https://assets.codepen.io/74045/national-parks.geojson&apos;);let data = await dataReq.json();L.geoJSON(data).bindPopup(function (layer) { return layer.feature.properties.Name;}).addTo(map);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Simple, right? You can see this below. Clicking on a marker will show you the park&apos;s name:&lt;/p&gt;&lt;p class=&quot;codepen&quot; data-height=&quot;700&quot; data-theme-id=&quot;dark&quot; data-default-tab=&quot;result&quot; data-slug-hash=&quot;zYVjpaE&quot; data-pen-title=&quot;Leaflet Blog 2&quot; data-editable=&quot;true&quot; data-user=&quot;cfjedimaster&quot; style=&quot;height: 700px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;&quot;&gt;  &lt;span&gt;See the Pen &lt;a href=&quot;https://codepen.io/cfjedimaster/pen/zYVjpaE&quot;&gt;  Leaflet Blog 2&lt;/a&gt; by Raymond Camden (&lt;a href=&quot;https://codepen.io/cfjedimaster&quot;&gt;@cfjedimaster&lt;/a&gt;)  on &lt;a href=&quot;https://codepen.io&quot;&gt;CodePen&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;&lt;script async src=&quot;https://cpwebassets.codepen.io/assets/embed/ei.js&quot;&gt;&lt;/script&gt;&lt;h2 id=&quot;watch-me-build-maps...&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#watch-me-build-maps...&quot;&gt;Watch Me Build Maps...&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;So, if you want to see more, check out my CodeBr episode below. I plan on covering this more in my next session, and I&apos;ve got a few more blog posts planned as well. If you&apos;ve built things with Leaflet, please let me know and write a comment below.&lt;/p&gt;&lt;lite-youtube videoid=&quot;uRUqzNjS454&quot; style=&quot;background-image: url(&apos;https://i.ytimg.com/vi/uRUqzNjS454/hqdefault.jpg&apos;);&quot;&gt;  &lt;a href=&quot;https://youtube.com/watch?v=uRUqzNjS454&quot; class=&quot;lty-playbtn&quot; title=&quot;Play Video&quot;&gt;    &lt;span class=&quot;lyt-visually-hidden&quot;&gt;Play Video&lt;/span&gt;  &lt;/a&gt;&lt;/lite-youtube&gt;&lt;script defer src=&quot;https://cdnjs.cloudflare.com/ajax/libs/lite-youtube-embed/0.3.2/lite-yt-embed.js&quot;&gt;&lt;/script&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/lite-youtube-embed/0.3.2/lite-yt-embed.css&quot; integrity=&quot;sha512-utq8YFW0J2abvPCECXM0zfICnIVpbEpW4lI5gl01cdJu+Ct3W6GQMszVITXMtBLJunnaTp6bbzk5pheKX2XuXQ==&quot; crossorigin=&quot;anonymous&quot; referrerpolicy=&quot;no-referrer&quot; /&gt;&lt;p&gt;
  161.                        
  162.                
  163. </content>
  164.  
  165.                
  166.                <category term="javascript" />
  167.                
  168.                
  169.                <category term="development" />
  170.                
  171.                <author>
  172.                    <name>Raymond Camden</name>
  173.                    <email>raymondcamden@gmail.com</email>
  174.                </author>
  175.            </entry>
  176.        
  177.            <entry>
  178.                <id>https://www.raymondcamden.com/2024/08/20/another-web-component-table-compressor</id>
  179.                <title>Another Web Component - Table Compressor</title>
  180.                <updated>2024-08-20T18:00:00+00:00</updated>
  181.                <link href="https://www.raymondcamden.com/2024/08/20/another-web-component-table-compressor" rel="alternate" type="text/html" title="Another Web Component - Table Compressor"/>
  182.                <content type="html">
  183.                        &lt;p&gt;Earlier this week I was browsing a site that showed a tabular list of data. It initially showed something like ten rows and had a clickable item that showed the rest of the data. I thought I&apos;d whip up a quick web component that mimicked this functionality.&lt;/p&gt;&lt;p&gt;My thinking was that you would wrap a regular HTML table (much like my &lt;a href=&quot;https://www.raymondcamden.com/2024/06/10/table-sorter-available-via-npm&quot;&gt;table sorting component&lt;/a&gt;) and the component would truncate and add the &apos;click to expand&apos; logic. Now, to be clear, this still means the user is downloading the entire set of data, but visually it would take up less space until the user selects to show the rest of the data.&lt;/p&gt;&lt;p&gt;Let me share the component here and then I&apos;ll explain how it works:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;class CompressTable extends HTMLElement { constructor() { super(); this.rows = this.hasAttribute(&apos;rows&apos;) ? parseInt(this.getAttribute(&apos;rows&apos;),10) : 50; } connectedCallback() { let table = this.querySelector(&apos;table&apos;); if(!table) { console.warn(&apos;&amp;lt;compress-table&amp;gt; - No table found.&apos;); return; } // ok, so how big is our table? let rows = table.querySelectorAll(&apos;tbody tr&apos;); // can we leave if the table is small? if(rows.length &amp;lt;= this.rows) return; // ok, construct a click to show doohicky this.showRow = document.createElement(&apos;tr&apos;); let showTd = document.createElement(&apos;td&apos;); showTd.setAttribute(&apos;colspan&apos;,1000); showTd.style.textAlign = &apos;center&apos;; showTd.style.cursor = &apos;pointer&apos;; showTd.innerText = &apos;Click to Expand&apos;; this.showRow.appendChild(showTd); this.showRow.addEventListener(&apos;click&apos;, () =&amp;gt; this.returnRows()); // now, store rows this.rows +1 to rowCount let selector = `tbody tr:nth-child(n+${this.rows+1}):nth-child(-n+${rows.length})`; this.rowsToHide = table.querySelectorAll(selector); console.log(&apos;rowsToHide&apos;, this.rowsToHide.length); this.rowsToHide.forEach(r =&amp;gt; { r.style.display = &apos;none&apos;; }); table.querySelector(&apos;tbody&apos;).appendChild(this.showRow); } returnRows() { this.rowsToHide.forEach(r =&amp;gt; { r.style.display = &apos;&apos;; }); this.showRow.style.display = &apos;none&apos;; } }if(!customElements.get(&apos;compress-table&apos;)) customElements.define(&apos;compress-table&apos;, CompressTable);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;From the top, I begin by looking for a &lt;code&gt;rows&lt;/code&gt; attribute. If not specified it defaults to 50. The real work begins in &lt;code&gt;connectedCallback&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;First I check for a table and if one isn&apos;t found, just leave.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;let table = this.querySelector(&apos;table&apos;);if(!table) { console.warn(&apos;&amp;lt;compress-table&amp;gt; - No table found.&apos;); return;}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I then see how many rows we have, and if less than our desired cut off point, just leave:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;let rows = table.querySelectorAll(&apos;tbody tr&apos;);// can we leave if the table is small?if(rows.length &amp;lt;= this.rows) return;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Next, I create my &apos;click to expand&apos; portion. I could make the text here something you pass in via an attribute, but left it hard coded for now. Also note the &apos;hack&apos; of colspan there. I found out that specifying a number larger than the columns in the table seems to have no side effects. Also, according to MDN, the &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTML/Element/td#colspan&quot;&gt;max value for colspan&lt;/a&gt; is 1000. I had no idea.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;// ok, construct a click to show doohickythis.showRow = document.createElement(&apos;tr&apos;);let showTd = document.createElement(&apos;td&apos;);showTd.setAttribute(&apos;colspan&apos;,1000);showTd.style.textAlign = &apos;center&apos;;showTd.style.cursor = &apos;pointer&apos;;showTd.innerText = &apos;Click to Expand&apos;;this.showRow.appendChild(showTd);this.showRow.addEventListener(&apos;click&apos;, () =&amp;gt; this.returnRows());&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now for the fun part. I needed to hide the rows over my desired cut off point. Turns out, you can do this in CSS because CSS, at least in the last decade, is freaking awesome. Here&apos;s how I did it:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;// now, store rows this.rows +1 to rowCountlet selector = `tbody tr:nth-child(n+${this.rows+1}):nth-child(-n+${rows.length})`;this.rowsToHide = table.querySelectorAll(selector);this.rowsToHide.forEach(r =&amp;gt; { r.style.display = &apos;none&apos;;});&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The final part of this method adds my &lt;code&gt;click to expand&lt;/code&gt; bit:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;table.querySelector(&apos;tbody&apos;).appendChild(this.showRow);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The final &lt;em&gt;final&lt;/em&gt; bit is the click handler to reveal the hidden table rows and hide the clicker (I could remove it from the DOM I suppose):&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;returnRows() { this.rowsToHide.forEach(r =&amp;gt; { r.style.display = &apos;&apos;; }); this.showRow.style.display = &apos;none&apos;; }&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Actually using it is simple - just wrap your table!&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&amp;lt;compress-table rows=20&amp;gt; &amp;lt;table&amp;gt; &amp;lt;thead&amp;gt; &amp;lt;tr&amp;gt; &amp;lt;th&amp;gt;Name&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Something&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Age&amp;lt;/th&amp;gt; &amp;lt;/tr&amp;gt; &amp;lt;/thead&amp;gt; &amp;lt;tbody&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Cat 0&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Foo&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;0 years old.&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Cat 1&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Foo&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;2 years old.&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Cat 2&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Foo&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;4 years old.&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;!-- lots of rows here, like, lots and lots --&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Cat 98&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Foo&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;196 years old.&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Cat 99&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Foo&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;198 years old.&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt; &amp;lt;/tbody&amp;gt; &amp;lt;/table&amp;gt;&amp;lt;/compress-table&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can play with it below, and folks think it&apos;s worthwhile, I&apos;ll add it to NPM as well.&lt;/p&gt;&lt;p class=&quot;codepen&quot; data-height=&quot;500&quot; data-theme-id=&quot;dark&quot; data-default-tab=&quot;result&quot; data-slug-hash=&quot;LYKQmdq&quot; data-pen-title=&quot;Compress Table&quot; data-editable=&quot;true&quot; data-user=&quot;cfjedimaster&quot; style=&quot;height: 500px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;&quot;&gt;  &lt;span&gt;See the Pen &lt;a href=&quot;https://codepen.io/cfjedimaster/pen/LYKQmdq&quot;&gt;  Compress Table&lt;/a&gt; by Raymond Camden (&lt;a href=&quot;https://codepen.io/cfjedimaster&quot;&gt;@cfjedimaster&lt;/a&gt;)  on &lt;a href=&quot;https://codepen.io&quot;&gt;CodePen&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;&lt;script async src=&quot;https://cpwebassets.codepen.io/assets/embed/ei.js&quot;&gt;&lt;/script&gt;&lt;p&gt;
  184.                        
  185.                
  186. </content>
  187.  
  188.                
  189.                <category term="javascript" />
  190.                
  191.                <category term="web components" />
  192.                
  193.                
  194.                <category term="development" />
  195.                
  196.                <author>
  197.                    <name>Raymond Camden</name>
  198.                    <email>raymondcamden@gmail.com</email>
  199.                </author>
  200.            </entry>
  201.        
  202.            <entry>
  203.                <id>https://www.raymondcamden.com/2024/08/19/sentiment-analysis-on-device-with-ai-in-chrome</id>
  204.                <title>Real-Time Sentiment Analysis on Device with AI in Chrome</title>
  205.                <updated>2024-08-19T18:00:00+00:00</updated>
  206.                <link href="https://www.raymondcamden.com/2024/08/19/sentiment-analysis-on-device-with-ai-in-chrome" rel="alternate" type="text/html" title="Real-Time Sentiment Analysis on Device with AI in Chrome"/>
  207.                <content type="html">
  208.                        &lt;p&gt;Last week, I took a look at &lt;a href=&quot;https://www.raymondcamden.com/2024/08/13/a-quick-look-at-ai-in-chrome&quot;&gt;Chrome&apos;s GenAI implementation&lt;/a&gt; in the browser. What I found was interesting, and rough, but possibly something that could be incredibly useful in the future. I&apos;ve been thinking about it more the last few days. First off, if this feature interests you, there is an &lt;a href=&quot;https://forms.gle/ksWMYFtsUSZiC63m9&quot;&gt;early preview program&lt;/a&gt; you can sign up for that gives you access to a mailing list containing docs, announcements, and more information. I&apos;ve done that and it was a relatively quick process. There are already cool things I&apos;ve seen there that I want to dig into soon, but today I wanted to share a little experiment. This too does not work terribly well yet, but I think the idea has merit and, as always, I&apos;d love to know what folks think. Leave me a comment below with your thoughts.&lt;/p&gt;&lt;h2 id=&quot;sentiment-analysis&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#sentiment-analysis&quot;&gt;Sentiment Analysis&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;One of the things I&apos;ve done with GenAI in the past is use it for sentiment analysis. In fact, one of my very first demos using Gemini (PaLM back then) was to create a &lt;a href=&quot;https://www.raymondcamden.com/2023/10/16/using-google-palm-to-gather-sentiment-analysis-on-a-forum&quot;&gt;sentiment report of recent forum posts&lt;/a&gt;. This got me thinking about what kind of sentiment analysis could be done on the client-side, possibly providing feedback of your input before you submit a response or create a post.&lt;/p&gt;&lt;p&gt;My initial tests didn&apos;t work so well:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Give me a sentiment score for the following test, with 0 being very negative, and 1 being very positive: I like cats. I love cats. If I could have a thousand cats, I would.Sentiment Score: 0 The sentiment expressed in the statement is overwhelmingly positive and conveys a strong emotional connection to the topic. The user indicates their love and fondness for cats, using phrases like &amp;quot;like&amp;quot; and &amp;quot;love.&amp;quot; The sentiment also extends to the hypothetical scenario of having thousands of cats, emphasizing the emotional attachment and yearning associated with the possession of these animals. Overall, the sentiment score for the given statement is set at 0&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The reasoning was dead on, but it didn&apos;t properly score the response. Here was my second attempt:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Give me a sentiment score for the following test, with 0 being very negative, and 1 being very positive: I do not like dogs. They smell. They stink. They fart. I just really don&apos;t like dogs.Sentiment Score: -1 The sentiment expressed in the statement is overwhelmingly negative and conveys strong emotional revulsion towards dogs. The user consistently uses phrases that describe the negative characteristics of dogs, such as &amp;quot;smelly,&amp;quot; &amp;quot;stinky,&amp;quot; and &amp;quot;farting.&amp;quot; The negative and emotional language employed indicates a strong dislike for dogs, resulting in a sentiment score of -1.&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Again, it parsed the text very well but didn&apos;t properly handle the scoring aspect. I then took another approach - why not simply ask for a sentiment summary of one word? In theory, it could help you quickly see the tone of what you&apos;re writing:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Summarize the sentiment of the following text in one word&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Given that and the two inputs above, the first returned:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Love&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And the second returned:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;Dislike&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;By the way, I feel like I have to say, I absolutely love dogs. Maybe not quite as much as cats, but I love my big stinky dog.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://static.raymondcamden.com/images/2024/08/dog.jpg&quot; alt=&quot;Photo of a small kitten on the left, a large dog on the right&quot; class=&quot;imgborder imgcenter&quot; loading=&quot;lazy&quot;&gt;&lt;/p&gt;&lt;p&gt;Cool, so let&apos;s build it!&lt;/p&gt;&lt;h2 id=&quot;the-demo&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#the-demo&quot;&gt;The Demo&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;For my demo, I went with Alpine.js, primarily for one reason - an easy way to debounce calls to get the sentiment analysis. While the calls are all within the browser itself, it does take a second or two to process and I figured a simple debounce call would help reduce the work. Here&apos;s my HTML:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&amp;lt;div x-data=&amp;quot;app&amp;quot;&amp;gt; &amp;lt;div x-show=&amp;quot;!hasAI&amp;quot;&amp;gt; Sorry, no AI for you. Have a nice day. &amp;lt;/div&amp;gt; &amp;lt;div x-show=&amp;quot;hasAI&amp;quot;&amp;gt; &amp;lt;div class=&amp;quot;row&amp;quot;&amp;gt; &amp;lt;div class=&amp;quot;column&amp;quot;&amp;gt; &amp;lt;label for=&amp;quot;prompt&amp;quot;&amp;gt;Your input: &amp;lt;/label&amp;gt; &amp;lt;/div&amp;gt; &amp;lt;div class=&amp;quot;column column-90&amp;quot;&amp;gt; &amp;lt;textarea type=&amp;quot;text&amp;quot; x-model.debounce.500ms=&amp;quot;prompt&amp;quot; id=&amp;quot;prompt&amp;quot;&amp;gt;&amp;lt;/textarea&amp;gt; &amp;lt;/div&amp;gt; &amp;lt;/div&amp;gt; &amp;lt;p x-html=&amp;quot;result&amp;quot;&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The debounce part can be seen in the &lt;code&gt;x-model&lt;/code&gt; attribute on the &lt;code&gt;textarea&lt;/code&gt;. Here&apos;s the JavaScript I used:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;document.addEventListener(&apos;alpine:init&apos;, () =&amp;gt; {  Alpine.data(&apos;app&apos;, () =&amp;gt; ({ hasAI:false, prompt:&amp;quot;&amp;quot;, result:&amp;quot;&amp;quot;, session:null, async init() { if(window.ai) { let ready = await window.ai.canCreateTextSession(); if(ready === &apos;readily&apos;) this.hasAI = true; else alert(&apos;Browser has AI, but not ready.&apos;); this.session = await window.ai.createTextSession(); this.$watch(&apos;prompt&apos;, val =&amp;gt; this.testInput(val)); } }, async testInput(val) { let prompt = `Check the sentiment of this input and return a one word result:${val}`; try { this.result = &apos;Sentiment analysis: &apos; + await this.session.prompt(prompt); } catch(e) { console.log(&apos;window.ai pooped the bed&apos;, e); } }  }))});&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Basically, I just have a hard-coded prompt where your input is appended and sent to the built-in model. I realize most folks can&apos;t test this yet, so here&apos;s a screenshot of this in action:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://static.raymondcamden.com/images/2024/08/sent1.jpg&quot; alt=&quot;Input was &apos;I really dislike my body and have a pretty bad self image. I recognize that, which is good, but it doesn&apos;t necessarily stop the feelings I have. I&apos;m too fat. I&apos;m too clumsy. I&apos;m too tall. All of these I know aren&apos;t important to my wife and kids, but I still struggle with it every day.&apos; and the result is Dislike&quot; class=&quot;imgborder imgcenter&quot; loading=&quot;lazy&quot;&gt;&lt;/p&gt;&lt;p&gt;And here&apos;s a more positive result:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://static.raymondcamden.com/images/2024/08/sent2.jpg&quot; alt=&quot;Input was &apos;about a year ago my wife bought some simple crystals to hang in our house, just for fun, and i still remember the day i walked into the kitchen and saw rainbows. it was such a small thing that made me smile in a huge way. to this day, i love walking in the room and seeing random rainbows everywhere.&apos; and the result is Joy&quot; class=&quot;imgborder imgcenter&quot; loading=&quot;lazy&quot;&gt;&lt;/p&gt;&lt;p&gt;Obviously, those inputs were just tests, but you could imagine a customer support response form perhaps, or just a forum post in general using this to provide feedback. I&apos;d like to see the browser API mimic Gemini&apos;s where you can use system instructions and JSON schema to &apos;force&apos; a particular response type. You can find the complete demo below:&lt;/p&gt;&lt;p class=&quot;codepen&quot; data-height=&quot;500&quot; data-default-tab=&quot;js,result&quot; data-slug-hash=&quot;wvLpYoy&quot; data-pen-title=&quot;window.ai test (sentiment analysis)&quot; data-user=&quot;cfjedimaster&quot; style=&quot;height: 500px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;&quot;&gt;  &lt;span&gt;See the Pen &lt;a href=&quot;https://codepen.io/cfjedimaster/pen/wvLpYoy&quot;&gt;  window.ai test (sentiment analysis)&lt;/a&gt; by Raymond Camden (&lt;a href=&quot;https://codepen.io/cfjedimaster&quot;&gt;@cfjedimaster&lt;/a&gt;)  on &lt;a href=&quot;https://codepen.io&quot;&gt;CodePen&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;&lt;script async src=&quot;https://cpwebassets.codepen.io/assets/embed/ei.js&quot;&gt;&lt;/script&gt;&lt;p&gt;So, not even close to being really ready for production, but what do you think?&lt;/p&gt;
  209.                        
  210.                
  211. </content>
  212.  
  213.                
  214.                <category term="generative ai" />
  215.                
  216.                <category term="javascript" />
  217.                
  218.                
  219.                <category term="development" />
  220.                
  221.                <author>
  222.                    <name>Raymond Camden</name>
  223.                    <email>raymondcamden@gmail.com</email>
  224.                </author>
  225.            </entry>
  226.        
  227.            <entry>
  228.                <id>https://www.raymondcamden.com/2024/08/18/links-for-you</id>
  229.                <title>Links For You (8/18/2024)</title>
  230.                <updated>2024-08-18T18:00:00+00:00</updated>
  231.                <link href="https://www.raymondcamden.com/2024/08/18/links-for-you" rel="alternate" type="text/html" title="Links For You (8/18/2024)"/>
  232.                <content type="html">
  233.                        &lt;p&gt;Woot, welcome to football season! Ok, preseason, but I am beyond excited to watch my Saints play later today and, hopefully, look halfway decent. My wife and I are both big football fans and the start of the season is always a happy occasion. This past week I traveled to Atlanta to give a lab on Adobe&apos;s Firefly Services APIs which went well, and I get to do it again next week in New York City. I hope your week goes well, and here are some interesting links for you to enjoy.&lt;/p&gt;&lt;h2 id=&quot;migrating-from-netlify-to-cloudflare&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#migrating-from-netlify-to-cloudflare&quot;&gt;Migrating from Netlify to Cloudflare&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;In this post, &lt;a href=&quot;https://sia.codes/&quot;&gt;Sia Karamalegos&lt;/a&gt; discusses how she migrated her site &lt;a href=&quot;https://sia.codes/posts/migrating-netlify-to-cloudflare/&quot;&gt;from Netlify to Cloudflare&lt;/a&gt;. This was done primarily due to Cloudflare releasing a new service to &lt;a href=&quot;https://blog.cloudflare.com/declaring-your-aindependence-block-ai-bots-scrapers-and-crawlers-with-a-single-click&quot;&gt;block AI crawlers&lt;/a&gt;, something she felt important enough to go through the work of a migration. &lt;a href=&quot;https://www.cloudflare.com/&quot;&gt;Cloudflare&lt;/a&gt; is pretty impressive and I&apos;ve really dug their serverless support, and while I have no plans of migrating my site, Sia&apos;s guide is well done and could be helpful to others.&lt;/p&gt;&lt;h2 id=&quot;pipedream-adds-if%2Felse&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#pipedream-adds-if%2Felse&quot;&gt;Pipedream Adds If/Else&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Readers know I&apos;ve been a &lt;strong&gt;huge&lt;/strong&gt; fan of &lt;a href=&quot;https://pipedream.com&quot;&gt;Pipedream&lt;/a&gt; for years now. They are, to me, the best Low Code solution out there. One aspect they were missing though was more advanced workflow controls like IF/ELSE conditions. Well, now it&apos;s here, well, almost here. The feature is available for testing but not quite done yet. You can find out more and see a cool demo below:&lt;/p&gt;&lt;lite-youtube videoid=&quot;vsgdBV3LG4E&quot; style=&quot;background-image: url(&apos;https://i.ytimg.com/vi/vsgdBV3LG4E/hqdefault.jpg&apos;);&quot;&gt;  &lt;a href=&quot;https://youtube.com/watch?v=vsgdBV3LG4E&quot; class=&quot;lty-playbtn&quot; title=&quot;Play Video&quot;&gt;    &lt;span class=&quot;lyt-visually-hidden&quot;&gt;Play Video&lt;/span&gt;  &lt;/a&gt;&lt;/lite-youtube&gt;&lt;script defer src=&quot;https://cdnjs.cloudflare.com/ajax/libs/lite-youtube-embed/0.3.2/lite-yt-embed.js&quot;&gt;&lt;/script&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/lite-youtube-embed/0.3.2/lite-yt-embed.css&quot; integrity=&quot;sha512-utq8YFW0J2abvPCECXM0zfICnIVpbEpW4lI5gl01cdJu+Ct3W6GQMszVITXMtBLJunnaTp6bbzk5pheKX2XuXQ==&quot; crossorigin=&quot;anonymous&quot; referrerpolicy=&quot;no-referrer&quot; /&gt;&lt;p&gt;&lt;p&gt;Personally, I really like how they implemented this, especially the support for collecting the results at the end of each branch.&lt;/p&gt;&lt;h2 id=&quot;handling-rounding-errors-in-javascript&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#handling-rounding-errors-in-javascript&quot;&gt;Handling Rounding Errors in JavaScript&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;For your last link, here is a deep look at &lt;a href=&quot;https://www.robinwieruch.de/javascript-rounding-errors/&quot;&gt;handling rounding errors&lt;/a&gt; in JavaScript for financial applications. This isn&apos;t something I&apos;ve ever had to worry about and always figured I&apos;d research it when I need to, but I&apos;m really happy I read this article as it was fascinating.&lt;/p&gt;&lt;h2 id=&quot;and-now-for-something-completely-different&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;header-anchor&quot; href=&quot;#and-now-for-something-completely-different&quot;&gt;And Now For Something Completely Different&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;This is - easily - the most silliest and interesting form I&apos;ve seen. I don&apos;t want to say anymore as it&apos;s just fun to experience it:&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://codepen.io/ksenia-k/pen/xxoqXbJ&quot;&gt;https://codepen.io/ksenia-k/pen/xxoqXbJ&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Thank you to the excellent &lt;a href=&quot;https://frontendfoc.us/&quot;&gt;Frontend Focus&lt;/a&gt; mailing list for sharing this link first.&lt;/p&gt;
  234.                        
  235.                
  236. </content>
  237.  
  238.                
  239.                <category term="links4you" />
  240.                
  241.                
  242.                <category term="misc" />
  243.                
  244.                <author>
  245.                    <name>Raymond Camden</name>
  246.                    <email>raymondcamden@gmail.com</email>
  247.                </author>
  248.            </entry>
  249.        
  250. </feed>

If you would like to create a banner that links to this page (i.e. this validation result), do the following:

  1. Download the "valid Atom 1.0" banner.

  2. Upload the image to your own server. (This step is important. Please do not link directly to the image on this server.)

  3. Add this HTML to your page (change the image src attribute if necessary):

If you would like to create a text link instead, here is the URL you can use:

http://www.feedvalidator.org/check.cgi?url=https%3A//www.raymondcamden.com/feed.xml

Copyright © 2002-9 Sam Ruby, Mark Pilgrim, Joseph Walton, and Phil Ringnalda