Skip to content

Instantly share code, notes, and snippets.

View mosheKerbel's full-sized avatar

Moshe Kerbel mosheKerbel

  • Wix
View GitHub Profile
@mosheKerbel
mosheKerbel / question.txt
Last active November 12, 2020 15:26
nopp.js
Pseudo-Palindromic Paths in a Binary Tree:
Given a binary tree where node values are digits from 1 to 9.
A path in the binary tree is said to be pseudo-palindromic if
at least one permutation of the node values in the path is a palindrome.
Return the number of pseudo-palindromic paths going from the root node to leaf nodes.
Examples 1:
3
/ \
@mosheKerbel
mosheKerbel / index.module.css
Created October 22, 2020 13:05
index.module.css
.previewIframe { width: 100vw; height: 100vh; border: 0;}
@mosheKerbel
mosheKerbel / final-[id].js
Created October 22, 2020 07:59
final-[id].js
import { connect, ObjectId } from "../../../utils/database";
// import { connect, ObjectId } from "../../../utils/fakeDatabase";
export default async (req, res) => {
const {
query: { id },
method,
} = req;
const collectionName = "pens";
switch (method) {
@mosheKerbel
mosheKerbel / apis-post.js
Created October 22, 2020 07:58
apis-post.js
case "POST":
try {
const { html, css, js, id } = req.body;
const { db } = await connect();
await db
.collection(collectionName)
.updateOne(
{ _id: ObjectId(id) },
{ $set: { html: html, css: css, js: js } }
@mosheKerbel
mosheKerbel / apis-put.js
Created October 22, 2020 07:57
apis-put.js
case "PUT":
try {
const { html, css, js } = req.body;
const { db } = await connect();
const result = await db.collection(collectionName).insertOne({
html,
css,
js,
});
@mosheKerbel
mosheKerbel / apis-get.js
Created October 22, 2020 07:55
apis-get.js
case "GET":
try {
const { db } = await connect();
const data = await db
.collection(collectionName)
.findOne({ _id: ObjectId(id) });
if (!data) {
res.status(404).json({ success: false });
}
res.status(200).json({ data });
@mosheKerbel
mosheKerbel / apis-import.js
Created October 22, 2020 07:44
apis-import.js
import { connect, ObjectId } from "../../../utils/database";
# OR fake db
import { connect, ObjectId } from "../../../utils/fakeDatabase";
@mosheKerbel
mosheKerbel / fake-database.js
Created October 22, 2020 07:09
fake-database.js
import { MongoClient, ObjectId } from "mongo-mock";
async function connect() {
const db = await MongoClient.connect("mongodb://someserver/mock_database");
const collection = await db.createCollection("pens");
return {db , collection};
}
export { connect, ObjectId };
@mosheKerbel
mosheKerbel / database.js
Created October 22, 2020 07:07
database.js
import { MongoClient, ObjectId } from "mongodb";
const dbName = "db-name";
const url = `mongodb+srv://your-username:your-password@cluster0.ldrfm.mongodb.net/your-db?retryWrites=true&w=majority`;
const client = new MongoClient(url, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
@mosheKerbel
mosheKerbel / index.module.css
Created October 22, 2020 06:26
updated-index.js
.previewIframe {
width: 100vw;
height: 100vh;
border: 0;
pointer-events: none;
}
.loading {
width: 100vw;
height: 100vh;