Skip to content

Instantly share code, notes, and snippets.

View tudorilisoi's full-sized avatar

Tudor Ilisoi tudorilisoi

View GitHub Profile
@tudorilisoi
tudorilisoi / route.ts
Created April 15, 2024 08:15
@conform with zod and zenstack
// schema
import { z } from 'zod'
// structure for a blog post
export const postCreateSchema = z.object({
title: z
.string({ required_error: 'Title is required' })
.min(10, 'Title is too short'),
body: z
.string({ required_error: 'Body is required' })
@tudorilisoi
tudorilisoi / index.js
Last active February 10, 2023 06:52
faker generate persons
import { faker } from '@faker-js/faker';
const MAX = 100
const users = []
const departaments = 'bridge engine'.split(' ')
for (let i = 0; i < MAX; i++) {
let firstName = faker.name.firstName();
let lastName = faker.name.lastName();
const user = {
name: firstName + ' ' + lastName,
let num = 0 //declare a variable whose initial value is zero
//function declaration
function increaseNum(){
num++ //increase the value of num by 1 using the increment operator
//get the reference to the body element
let bodyElement = document.getElementsByTagName('body')[0]
//... and set its text value to the value of num
@tudorilisoi
tudorilisoi / js-object-creation.js
Last active October 13, 2020 16:23
JS constructor, factory, class
//*** Object creation
// 1) class syntax , usage: p = new Person('Rex')
class Person {
constructor(name) {
this.name = name
}
sayHello() {
@tudorilisoi
tudorilisoi / fibo.js
Created October 2, 2020 18:49
Fibonacci
let i = 1 //step
//this implementation computes the sequence as an array
function fib(n) {
if (n === 1) {
return [1, 1]
}
const prev = fib(n - 1)
const rl = prev.length
@tudorilisoi
tudorilisoi / splitter.js
Created October 2, 2020 18:23
Rescursive string splitting
/*
Write a recursive function that splits a string based on a separator (similar to String.prototype.split).
Don't use JS array's split function to solve this problem.
Input: 02/20/2020
Output: ["02", "20", "2020"]
https://courses.thinkful.com/dsa-v1/checkpoint/2
@tudorilisoi
tudorilisoi / knex_join_vs_procedural.js
Created September 4, 2020 19:10
Knex procedural sequence vs join
try {
// queries sequence
const topicIDs = await knex('topics_users').select('topic_id').where('user_id', userID)
const topics = await knex('topics').select('*').where('id', topicIDs)
//single query
const topicsInOneGo = await knex('topics').select('*')
.innerJoin('topics_users', 'topics_users.id', 'topics.id')
.where('topics_users.user_id', topicIDs)
@tudorilisoi
tudorilisoi / react_layout_hoc.jsx
Created September 4, 2020 18:37
React layout wrapper HOC
export default function Layout(props) {
const classes = useStyles()
const gc = useGlobalStyles()
const { data: { user, loading } } = useContext(AppContext)
console.log(`LOADING ${loading}`)
const menuProps = { user }
return (
// Toast/Snack
import { NoSsr, Snackbar } from "@material-ui/core";
import { Alert } from "@material-ui/lab";
import React, { useEffect, useState } from "react";
export default function Snack(props) {
const { message, severity = "success" } = props
const [open, setOpen] = React.useState(null);
useEffect(() => {
import React from 'react'
//define your context
const APIContext = React.createContext(null)
// export default APIContext;
class NotesList extends Component {
//make the context accessible within this component