Skip to content

Instantly share code, notes, and snippets.

@nduckwiler
nduckwiler / status.ts
Created August 18, 2023 23:32
api/status.ts for mocking openai responses
import { NextApiRequest, NextApiResponse } from 'next';
const handler = (_req: NextApiRequest, res: NextApiResponse) => {
/* SUCCESS */
// const body = {
// "id": "chatcmpl-123",
// "object": "chat.completion",
// "created": 1677652288,
// "model": "gpt-3.5-turbo-0613",
/*
* More query methods: https://callstack.github.io/react-native-testing-library/docs/api-queries
* ReactTestInstance, returned by query methods: https://reactjs.org/docs/test-renderer.html#testinstance
* Jest expect methods: https://jestjs.io/docs/expect
*/
import React from 'react';
import { View } from 'react-native';
import { render, cleanup } from '@testing-library/react-native/pure';
@nduckwiler
nduckwiler / wagon.js
Last active December 9, 2020 19:15
Project solution code for Redux Core Concepts module
const initialWagon = {
supplies: 100,
distance: 0,
days: 0
};
const reducer = (wagon = initialWagon, action) => {
switch (action.type) {
case 'travel': {
const days = action.payload || 1;
@nduckwiler
nduckwiler / App.js
Created November 12, 2020 22:18
All components use react-redux hooks
import React from "react";
import "./App.css";
import AllThings from "../features/allThings/AllThings";
import MyThings from "../features/myThings/MyThings";
import Search from "../features/search/Search";
function App() {
return (
@nduckwiler
nduckwiler / App.js
Created November 12, 2020 22:17
Only "smart" component uses react-redux hooks
import React, { useEffect } from "react";
import "./App.css";
import { useDispatch, useSelector } from "react-redux";
import {
loadThings,
selectFilteredAllThings,
} from "../features/allThings/allThingsSlice";
import AllThings from "../features/allThings/AllThings";
import {
addThing,
@nduckwiler
nduckwiler / altogether.css
Last active June 7, 2020 18:39
errno32 broken pipe
main {
position: relative;
}
div#flex-container {
display: flex;
justify-content: center;
}
div.position-relative {
@nduckwiler
nduckwiler / fancy-regex-test.js
Created April 23, 2020 23:21
A fancy form of the Component test that uses capture groups
// Save code file as a string
var code = Components.CodeEditor.readFileContent('Startup.cs');
// Match a regex pattern and capture a value from learner code
var codeMatches = code.match(/Configure\s*\(.*\)\s*\{\s*([\s\S]*)app\.UseHttpsRedirection/);
if (!codeMatches) {
return {
pass: false,
errors: {
@nduckwiler
nduckwiler / sketch.js
Created April 22, 2020 18:14
p5 tracing video
// Add a janky form of Intellisense for P5.js
/// <reference path="./libraries/p5.d/p5.global-mode.d.ts" />
var imageWidth = 640;
var imageHeight = 480;
var canvasWidth = imageWidth * 2;
var canvasHeight = imageHeight;
var sourceImage;
var captureVideo;
var prevFrame;
@nduckwiler
nduckwiler / index.js
Created April 18, 2020 02:45
express-zoo
const express = require('express');
const app = express();
const port = 3000;
const zoo = [
'zebra',
'gecko',
'elephant',
'dog',
'parrot'
@nduckwiler
nduckwiler / Index.cshtml
Created March 10, 2020 23:49
DictionaryBinding
<form method="post">
<div class="form-group row">
<label class="col-6" for="fruits">How many servings of fruits did you have today?</label>
<div class="col-2">
<!-- how do I use asp-for here? -->
<select class="form-control" id="fruits" name="fruits">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>