Skip to content

Instantly share code, notes, and snippets.

View tudorilisoi's full-sized avatar

Tudor Ilisoi tudorilisoi

View GitHub Profile
@tudorilisoi
tudorilisoi / react-context.js
Created December 18, 2019 18:45
React context with hooks
export const AppContextProvider = ({ initialData, children }) => {
const mergedInitialData = { ...defaults, ...initialData }
const [data, setData] = useState(mergedInitialData)
useEffect(() => {
//I/O
console.log(`ctx Update:`, data)
}, [data])
import React from 'react';
import pt from 'prop-types';
import logo from './logo.svg';
import './App.css';
import { op } from './config'
// op()
function isObject(value) {

In these drills, you'll practice executing basic CRUD (create, read, update, delete) operations in the psql shell.

Before you get started, download this SQL data dump. Create and populate a new database using the data dump (make sure to update the path with the location where you saved the file):

psql -U dunder_mifflin_admin -d restaurants-app -f ~/Downloads/nyc-restaurants-data-backup.sql

Take a moment to get familiar with this new database. You can use \dt+ to see a list of public tables and \d <TABLENAME> to see a description of those tables.

const express = require("express");
const app = express()
// NOTE the router should go into its own file and do
// module.exports = usersRouter;
const usersRouter = express.Router();
usersRouter.route('/id/:id')
.get((req, res, next) => {
res.status(200).json({ message: 'Hello' })
})
@tudorilisoi
tudorilisoi / http.md
Last active March 10, 2020 20:02
HTTP protocol 101
const persons =[{
id: 'aBcDeFgH',
firstName: 'Juan',
lastName: 'Doe',
age: 32
},
{
id: 'zYxWvUt',
firstName: 'Alex',
lastName: 'Smith',
// https://www.npmjs.com/package/faker
const faker = require('faker')
faker.seed(123);
const { parse, stringify } = require('flatted/cjs');
function unique(fn, arr, objKey) {
const value = fn()
const exists = arr.find(item => item[objKey] === value)
if (exists !== undefined) {
function getUrbanAreas() {
console.log(urbanAreaNames);
let userInputUA = Object.keys(urbanAreaNames);
for (let i = 0; i < userInputUA.length; i++) {
let urbanAreaDropdownlist = `<option value="${urbanAreaNames[userInputUA[i]]}">${userInputUA[i]}</option>`
$('#urbanAreas-Dropdown').append(urbanAreaDropdownlist);
}
$('#urbanAreas-Dropdown').chosen();
}
function setupDropdownSubmit() {
// npm i animated-scroll-to --save
// import animateScrollTo from 'animated-scroll-to';
<li className="nav-item"><Link onClick={ev => {
console.log('clicked!')
// document.getElementsByClassName('flex-bottom')[0].scrollTop=0
if (window.location.pathname === '/players') {
ev.preventDefault()
animateScrollTo(0, {
element: document.querySelector('.flex-bottom'),
});
class ControlledInput extends React.Component {
constructor(props) {
super(props)
this.state = { value: props.initialValue || '' }
}
componentDidUpdate(prevProps, prevState) {
console.log(prevProps.initialValue, this.props.initialValue)
if (prevProps.initialValue !== this.props.initialValue) {
this.setState({ value: this.props.initialValue || '' })