Skip to content

Instantly share code, notes, and snippets.

View noxd3v's full-sized avatar
🏠
Working from home

noxd3v noxd3v

🏠
Working from home
View GitHub Profile
@noxd3v
noxd3v / context menu.reg
Last active October 7, 2021 11:02
VSCode commands
Windows Registry Editor Version 5.00
; This will handle right clicking on a file
[HKEY_CLASSES_ROOT\*\shell\Open with VS Code]
@="Edit with VS Code"
"Icon"="%LOCALAPPDATA%\\Programs\\Microsoft VS Code\\Code.exe,0"
[HKEY_CLASSES_ROOT\*\shell\Open with VS Code\command]
@="\"%LOCALAPPDATA%\\Programs\\Microsoft VS Code\\Code.exe\" \"%1\""
@noxd3v
noxd3v / convert to pdf.js
Last active March 2, 2021 18:55
Sending email with SES (with attachment)
const pdf = require("html-pdf");
const convertToPdf = (html, cb) => {
pdf.create(html).toBuffer(function (err, buffer) {
if (err) {
console.error("Cannot write PDF", err);
throw Error("Internal Server Error");
}
console.log("Stream created...");
cb(buffer);
@noxd3v
noxd3v / git commands.MD
Last active December 20, 2022 16:37
Git commands

Clear local changes, revert to latest local commit

git checkout .

Ignore changes

git update-index --assume-unchanged config/database.yml

Reference

@noxd3v
noxd3v / Vercel.MD
Last active February 27, 2021 14:49
Deployment notes

##Override build commands to ignore warnings such as unused variables

CI='' npm run build

@noxd3v
noxd3v / merging cache.js
Last active January 17, 2022 12:20
Apollo Client
/* since apollo cache depends on unique identifiers, if it occurs that the fields are without id field we need to merge existing with incoming cache, or just accept the incoming one */
const cache = new InMemoryCache({
typePolicies: {
/* query */
getSinglePosition: {
fields: {
/* related field */
Files: {
merge(existing, incoming) {
@noxd3v
noxd3v / rearrangable-list-react-beautiful-dnd.js
Created December 3, 2020 12:52
Simple rearrangable sidebar list using react-beautiful-dnd
import React, { useState, useContext, useCallback } from "react";
import styled from "styled-components";
import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd";
import { SidebarItem } from "../SidebarNavigation/SidebarNavigation.component";
import { FaPlus } from "react-icons/fa";
import { HiOutlineDotsVertical } from "react-icons/hi";
import { ModalContext } from "../../structure/Modal/modalContext";
import AddPositionForm from "./AddPositionForm";
const Wrapper = styled.div`
@noxd3v
noxd3v / Arrays.js
Last active September 25, 2021 08:15
Array snippets
/* Change position of the item in array */
const list = [1, 2, 3, 4, 5, 6];
const changePosition = (arr, destinationIndex, sourceIndex) => {
// destructable, copy array before using splice
arr.splice(destinationIndex, 0, list.splice(sourceIndex, 1)[0]);
return arr;
};
@noxd3v
noxd3v / Aggregate with filtering.js
Last active February 15, 2022 11:30
MongoDB snippets
Position.aggregate([
{
$project: {
_id: 1,
positions: {
$filter: {
input: "$newPositionsArray",
as: "position",
cond: {
/* multiple conditions */
@noxd3v
noxd3v / compose.js
Last active October 7, 2020 14:03
compose function
/* compose function for combining HOC in react */
export const compose = (...rest) => (x) => rest.reduceRight((y, f) => f(y), x);
/*
It's called functional composition and it has mathematical background (that causes y and x variables naming and reversed execution of functions). It decreases complexity of the way how you call written functions by eliminating variables extra definition and deep level of function wrapage.
*/
@noxd3v
noxd3v / Computed property names and methods.MD
Last active October 4, 2020 11:43
Computed property names and methods

Computed property names and methods ECMAScript 2015 adds a nice feature: computed property names in object literals and classes. The computed properties use a slight different syntax [methodName]() {...}, so the method definition looks this way:

const addMethod = 'add',
  getMethod = 'get';
const collection = {
  items: [],
  [addMethod](...items) {