Skip to content

Instantly share code, notes, and snippets.

@wtshek
wtshek / answer1.js
Last active July 16, 2020 18:23
Answer for Oursky test
const isSubset = (arr1, arr2) => {
for (let i = 0; i < arr2.length; i++) {
if (!arr1.find(ele => ele === arr2[i])) {
// console.log(item);
return false;
}
}
return true;
};
@wtshek
wtshek / _grid.scss
Created March 14, 2020 15:13
#starter Grid_starter_template_sample
.site{
display:grid;
grid-template-columns:2fr 1fr;
grid-template-areas:"header header"
"title sidebar"
"main sidebar"
"footer footer";
}
.site > *{padding:30px; color:#fff; font-size:20px;}
.mastheader{ grid-area:header; }
@wtshek
wtshek / index.js
Created January 9, 2020 08:52
#ErrorHandling
// Error Object
const Error = new Error(‘please improve your code’)
Error.message //please improve your code
Error.stack
//Error: please improve your code
// at Object.<anonymous> (/Users/gisderdube/Documents/_projects/hacking.nosync/error-handling/src/general.js:1:79)
// at Module._compile (internal/modules/cjs/loader.js:689:30)
// at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
// at Module.load (internal/modules/cjs/loader.js:599:32)
@wtshek
wtshek / index.js
Last active December 30, 2019 06:09
#express initial setup
# require express
# optional mongoDB and body-parser
const express = require('express');
const mongoose = require("mongoose");
const bodyParesr = require("body-parser");
require("") //schema for mongodb
const app = express();
@wtshek
wtshek / snippet.scss
Last active March 14, 2020 15:13
#CSS-Tricks Inner border radius
inner border radius = border radius - border width (border radius > border width)
.app{
border-radius: 10px;
border-width: 8px
}
@wtshek
wtshek / snippet.js
Created October 12, 2019 06:07
#Pattern RORO (receive an object, return an object)
// can make a parameter optional
// make the return value much richer
const human = ({name, contact, age}={}) => {
return {name, contact, age}
}
const Paul = human({name="Paul", age="32"})
@wtshek
wtshek / inheritance.js
Last active October 12, 2019 06:10
#Pattern #OOP Icey Factory
// how to do inheritance
// passing in the prototype function
// Object.freeze make only shallow copies
function makeProductList({ productDb }) {
return Object.freeze({
addProduct,
empty,
getProducts,
removeProduct,
@wtshek
wtshek / snippet.js
Last active October 12, 2019 05:56
#Pattern #OOP Factory Function
const dog = () => {
const sound = "woof!"
return {
bark: ()=>{console.log(sound)}
}
}
const sniffles = dog();
sniffles.talk() //output: "woof!"
@wtshek
wtshek / snippet.js
Created October 9, 2019 14:35
#JSON #nodejs write and read
import fs from 'fs';
// read file
function jsonReader(filePath, cb) {
fs.readFile(filePath, (err, fileData) => {
if (err) {
return cb && cb(err)
}
try {
const object = JSON.parse(fileData)
@wtshek
wtshek / index.js
Last active October 8, 2019 14:51
#react event.persist()
// setState within syntheitc event
// setState is async, by the time the action finished,
// event.target.value is no longer the same
// so need event.persist() to maintain the value
// if you want to access currentTarget in async way, you need to cache it in a variable as you did in your answer.
const Searchbar = ({getNutrition}) => {
const [searchState, setSearchState] = useState("ingredient")
const selValue = (ev) => {