Skip to content

Instantly share code, notes, and snippets.

View kyliepace's full-sized avatar

Kylie kyliepace

View GitHub Profile
@kyliepace
kyliepace / schema.prisma
Created March 4, 2022 22:58
prisma mongodb embedded document
model Book {
id String @id @default(auto()) @map("_id") @db.ObjectId
authors EmbeddedAuthor[]
translators EmbeddedAuthor[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
ISBN String? @unique
}
@kyliepace
kyliepace / schema.prisma
Created March 4, 2022 22:56
many-many prisma relation
model Character {
id String @id @default(auto()) @map("_id") @db.ObjectId
books Book[] @relation(fields: [bookIds], references: [id])
bookIds String[] @db.ObjectId
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Book {
id String @id @default(auto()) @map("_id") @db.ObjectId
@kyliepace
kyliepace / book.resolver.ts
Created March 4, 2022 22:49
nestjs graphql prisma resolver
import {
Resolver,
Query,
Mutation,
Args,
} from '@nestjs/graphql'
import { Inject } from '@nestjs/common';
import { Book } from '@prisma/client'
import { NewBookInput } from './dto/new-book.input'
import { BookStock } from './dto/book-stock.input'
@kyliepace
kyliepace / gist:a1ff779de53815e3803174d1067d4c75
Created January 20, 2022 20:44
use regex to truncate a float to a number of decimal places without rounding
function truncateNumber(number: Float, decimalPlaces: Int): Float {
const reg = new RegExp("^-?\\d+(?:\\.\\d{0," + decimalPlaces + "})?", "g")
const stringedNumber = number.toString().match(reg)[0]
const dotIndex = stringedNumber.indexOf(".")
const remainingDecimals = decimalPlaces - (stringedNumber.length - dotIndex) + 1
---
eleventyExcludeFromCollections: true
permalink: /robots.txt
---
User-agent: *
Allow: /
Sitemap: {{ site.url }}/sitemap.xml
@kyliepace
kyliepace / sitemap.njk
Created January 20, 2022 01:10
nunjucks sitemap
---
permalink: /sitemap.xml
eleventyExcludeFromCollections: true
---
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% for item in collections.all %}
<url>
<loc>{{ site.url }}{{ item.url }}</loc>
<lastmod>{{ item.date | htmlDateString }}</lastmod>
from pyspark.sql import SparkSession
from pyspark.sql.functions import from_json, to_json, col, unbase64, base64, split, expr
from pyspark.sql.types import StructField, StructType, StringType, BooleanType, ArrayType, DateType
# TO-DO: create a StructType for the Kafka redis-server topic which has all changes made to Redis - before Spark 3.0.0, schema inference is not automatic
redisSchema = StructType(
[
StructField("key", StringType()),
StructField("existType", StringType()),
StructField("Ch", BooleanType()),
from pyspark.sql import SparkSession
from pyspark.sql.functions import from_json, to_json, col, unbase64, base64, split, expr
from pyspark.sql.types import StructField, StructType, StringType, FloatType, BooleanType, ArrayType, DateType
# create deposit a kafka message schema StructType including the following JSON elements:
# {"accountNumber":"703934969","amount":415.94,"dateAndTime":"Sep 29, 2020, 10:06:23 AM"}
# Cast the amount as a FloatType
depositMessageSchema = StructType(
[
map.on('load', async () => {
map.addSource('greenspace_tiles', {
type: 'vector',
url: `mapbox://${mapboxUsername}.${mapID}`
});
map.addLayer({
id: 'greenspaces',
type: 'fill',
source: 'greenspace_tiles',
// node.js express.js server
const express = require('express');
const bodyParser = require('body-parser');
const routes = require('./routes.js');
const port = process.env.PORT || 3000;
const app = express();
const http = require('http').Server(app);
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))