Skip to content

Instantly share code, notes, and snippets.

@lejonmanen
lejonmanen / dynamodb-node.ts
Created September 14, 2025 15:22
Använda DynamoDB från Node
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient, GetCommand, PutCommand, ScanCommand } from "@aws-sdk/lib-dynamodb";
/*
GetCommand används för att hämta en specifik Item i en Table. (AWS rekommenderar att man har allt i samma tabell.)
ScanCommand kan hämta hela innehållet i en tabell. Opraktiskt om man har mycket data.
PutCommand lägger till en ny Item.
UpdateItemCommand ändrar en Item.
DeleteCommand
*/
@lejonmanen
lejonmanen / ask.ts
Created August 14, 2025 10:02
Node async readline
/* Exempel på användning:
import { ask } from './ask.ts'
let x: string = await ask('Vilken är din favoritfärg? ')
console.log('Du svarade: ' + x)
*/
import readline from 'node:readline'
async function ask(query: string): Promise<string> {
const rl = readline.createInterface({ input: process.stdin, output: process.stdout, tabSize: 4 });
@lejonmanen
lejonmanen / search.feature
Last active April 5, 2025 19:29
Exempel på Page Object för söksida för en musiktjänst
Feature: Musiksökning
Som en användare av musiktjänsten
Vill jag kunna söka efter musik
För att hitta musik jag gillar
Background:
Given att jag är inloggad på musiktjänsten
And att jag är på söksidan
Scenario: Söka efter musik med giltigt sökord
@lejonmanen
lejonmanen / ask.js
Created October 24, 2024 15:35
Read input from user in terminal, Node.js
/*
Use this file in your project.
But first, create a Node project:
npm init -y
Then add a line to package.json:
"type": "module",
Usage:
@lejonmanen
lejonmanen / .env
Last active September 26, 2024 15:04
Fullstack MERN with TypeScript
# Add your secrets here
CONNECTION_STRING=yes-here
@lejonmanen
lejonmanen / mongoose-node.ts
Last active September 13, 2024 12:59
Mongoose example with TypeScript
import { Schema, model, connect, Mongoose } from 'mongoose'
// Animal is an interface describing animal objects
import { Animal } from './animal.js';
const animalSchema = new Schema<WithId<Animal>>({
_id: ObjectId, // from WithId
species: String, // from Animal
factoid: String, // from Animal
score: Number // from Animal
@lejonmanen
lejonmanen / example.js
Created May 13, 2024 19:57
Example Cypress config for Vite+React
// This example produced 2024-05-13
// vite.config.js
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
server: {
@lejonmanen
lejonmanen / fire.js
Last active April 15, 2024 18:41
Firestore CRUD from static frontend 2024
// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getFirestore, collection, addDoc, getDocs, getDoc, doc, updateDoc, deleteDoc } from 'firebase/firestore/lite'
// Get this from Firebase Console
import { firebaseConfig } from "./firebaseConfig.js";
// Initialize Firebase and get database
const app = initializeApp(firebaseConfig);
const db = getFirestore(app)
@lejonmanen
lejonmanen / App.jsx
Last active February 29, 2024 16:57
Conditional rendering exercise
/*
The Budget component uses "conditional rendering" to do
different things based on its props. What will each line
in the App component render?
*/
const App = () => (
<main>
<Budget value={5500} />
<Budget value={240} />
@lejonmanen
lejonmanen / Aaa.jsx
Last active February 29, 2024 16:37
React components
// A component is a function that returns JSX
const Aaa = () => (
<div>
You can do any JSX in here
</div>
)
// Remember to export the component
// Most people have one component per file and use export default
export default Aaa