Skip to content

Instantly share code, notes, and snippets.

@ChristianOConnor
ChristianOConnor / index.js
Last active February 6, 2023 22:50
Trying to call a Lit Action through an express server
const express = require("express");
const cors = require("cors");
const litJsSdk = require("lit-js-sdk");
const app = express();
var corsOptions = {
origin: "*"
};
app.use(cors(corsOptions));
@ChristianOConnor
ChristianOConnor / docker-log-020123_3.txt
Created February 1, 2023 22:43
error from mongodb docker image for dwgebler/node-express-example after change with node 16
Mongo started
MongoError: Authentication failed.
at MessageStream.messageHandler (/var/app/node_modules/mongodb/lib/cmap/connection.js:272:20)
at MessageStream.emit (node:events:513:28)
at processIncomingData (/var/app/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
at MessageStream._write (/var/app/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
at writeOrBuffer (node:internal/streams/writable:391:12)
at _write (node:internal/streams/writable:332:10)
at MessageStream.Writable.write (node:internal/streams/writable:336:10)
at Socket.ondata (node:internal/streams/readable:754:22)
@ChristianOConnor
ChristianOConnor / docker-log-020123_2.txt
Created February 1, 2023 22:38
error from mongodb docker image for dwgebler/node-express-example after change command to entrypoint
Mongo started
MongoError: Authentication failed.
at MessageStream.messageHandler (/var/app/node_modules/mongodb/lib/cmap/connection.js:272:20)
at MessageStream.emit (events.js:400:28)
at processIncomingData (/var/app/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
at MessageStream._write (/var/app/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
at writeOrBuffer (internal/streams/writable.js:358:12)
at MessageStream.Writable.write (internal/streams/writable.js:303:10)
at Socket.ondata (internal/streams/readable.js:731:22)
import React, { Dispatch, SetStateAction } from "react";
import "./ToggleSwitch.css";
function ToggleSwitch({ toggledVal, setToggled } : { toggledVal: boolean, setToggled: Dispatch<SetStateAction<boolean>> }) {
const onToggle = () => setToggled(!toggledVal);
return (
<label className="toggle-switch">
<input type="checkbox" checked={toggledVal} onChange={onToggle} />
<span className="switch" />
</label>
import logo from "./logo.svg";
import "./App.css";
import React, { useState } from "react";
import ToggleSwitch from "./ToggleSwitch";
function App() {
const [resp, setResp] = useState("");
const [isToggled, setIsToggled] = useState(false);
async function callApi() {
var express = require("express");
var app = express();
require("dotenv").config();
const GoogleAuth = require("google-auth-library").GoogleAuth;
const cors = require("cors");
app.use(
cors({ origin: process.env.ORIGIN, credentials: process.env.CREDENTIALS })
);
@ChristianOConnor
ChristianOConnor / index.js
Created January 13, 2023 10:31
GCP IAMCredentialsClient Example 1
// Imports the Google Cloud client library
const {IAMCredentialsClient} = require('@google-cloud/iam-credentials');
// TODO(developer): replace with your prefered project values.
// The service account must be granted the roles/iam.serviceAccountTokenCreator role
const serviceAccount = '<SERVICE ACCOUNT NAME HERE>@<PROJECT NAME HERE>.iam.gserviceaccount.com'
const scopes = 'https://www.googleapis.com/auth/cloud-platform'
// Creates a client
@ChristianOConnor
ChristianOConnor / page.tsx
Created November 21, 2022 20:13
cookies() won't work on Next.js 13 with turbopack 112122
import { cookies } from 'next/headers';
async function GetSpecCookies() {
console.log('GetLitCookies is running');
const cookiesList = cookies();
const hasCookie = cookiesList.has('lit-auth')
return hasCookie
}
export default async function Page() {
@ChristianOConnor
ChristianOConnor / Creator.tsx
Last active September 20, 2022 00:10
Trying to make a warning that disappears in 3 seconds
// import { useState } from "preact/hooks";
import { useState, useEffect, useRef } from "preact/hooks";
import { Handlers, PageProps } from "$fresh/server.ts";
import UserDb from "../database.ts";
interface CreatorProps {
email: string,
key: string
}
@ChristianOConnor
ChristianOConnor / routes-api-createUser.tsx
Created September 17, 2022 00:14
fresh app Creator Island 092622
import { Handlers, PageProps } from "$fresh/server.ts";
import UserDb from "../../database.ts";
export const handler = {
POST: async (request, ctx) => {
console.log(await request.json());
if (!request.hasBody) {
ctx.status = 400;
ctx.body = { msg: "Invalid user data" };
return ;