Skip to content

Instantly share code, notes, and snippets.

View ScriptBytes's full-sized avatar

Jeff ScriptBytes

View GitHub Profile
@ScriptBytes
ScriptBytes / page.tsx
Created November 16, 2023 22:36
A working, but ugly, way to show JSON in a web page
'use client';
import React, { useEffect, useState } from 'react';
function JsonTester() {
const [json, setJson] = useState('');
useEffect(() => {
const getJson = async () => {
var response = await fetch('https://swapi.dev/api/people/1');
if (response.ok) {
setJson(JSON.stringify(await response.json()));
@ScriptBytes
ScriptBytes / docker-compose.yml
Last active May 29, 2024 22:58
Docker compose file and example docker run command for my youtube video: https://youtu.be/gFjpv-nZO0U
version: '3.8'
services:
mongo:
image: mongo:7.0
environment:
MONGO_INITDB_ROOT_USERNAME: mongadmin
MONGO_INITDB_ROOT_PASSWORD: LikeAndSubscribe
ports:
- 27017:27017
volumes:
@ScriptBytes
ScriptBytes / TodoContext.cs
Created August 21, 2022 19:30
A very simple database context file for a Todo API.
public class TodoContext : DbContext
{
private readonly IConfiguration config;
public TodoContext(DbContextOptions options, IConfiguration config) : base(options)
{
this.config = config;
}
public DbSet<Todo> Todos { get; set; }
@ScriptBytes
ScriptBytes / SimpleDatabaseBuilder.sql
Created August 18, 2022 03:09
A simple example of a script that creates a database, a Person table, populates the table, and selects all the contents.
-- Create a new database called 'SBDemo'
-- Connect to the 'master' database to run this snippet
USE master
GO
-- Create the new database if it does not exist already
IF NOT EXISTS (
SELECT [name]
FROM sys.databases
WHERE [name] = N'SBDemo'
)
@ScriptBytes
ScriptBytes / concurrentTasksDemo.c
Created March 30, 2022 03:31
Quick and ugly example of the benefits of using Task.WhenAll for running many concurrent Tasks
using System.Diagnostics;
var numTasks = 10;
var taskTimeMs = 1000;
Console.WriteLine($"Running {numTasks} tasks at {taskTimeMs} ms each.");
Stopwatch stopWatch = new Stopwatch();
await DoSlow();
await DoFast();
@ScriptBytes
ScriptBytes / dockerfile
Created March 14, 2022 01:05
A simple dockerfile for a .net core 6 API
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build-env
# Copy csproj and restore as distinct layers
COPY ./TodoAPI/TodoAPI.csproj ./TodoAPI/TodoAPI.csproj
COPY *.sln .
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o build --no-restore
FROM node:16.14.0 as build
WORKDIR /source
# Copy the package lock file into the container
COPY package*.json ./
# Run ci only for the production dependencies
RUN npm ci
# Copy the rest of the files into the container and build
steps:
- name: gcr.io/cloud-builders/docker
args:
- build
- '-t'
- '$_GCR_HOSTNAME/$PROJECT_ID/$_SERVICE_NAME:$COMMIT_SHA'
- .
- name: gcr.io/cloud-builders/docker
args:
- push
import { Component, OnInit } from '@angular/core';
import { Person } from './person.model';
import { PersonService } from './person.service';
@Component({
selector: 'app-person',
template: `
<div>Selected Person: <span *ngIf="selected$ | async as person">{{person.name}}</span></div>
<div *ngFor="let per of people$ | async" (click)="select(per)">
<div>Name: {{per.name}}</div>
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Person } from './person.model';
import { environment } from 'environments/environment';
import { StoreService } from 'app/core/services/store.service';
@Injectable({
providedIn: 'root'
})
export class PersonService extends StoreService<Person> {