Skip to content

Instantly share code, notes, and snippets.

const saveImgTemp = function (req, res, next) {
const writeStream = fs.createWriteStream(
path.join(__dirname, "../store/test.png")
);
req.pipe(writeStream);
// After all the data is saved, respond with a simple html form so they can post more data
req.on('end', function () {
res.send({msg: "Works"})
});
@EarthenLynx
EarthenLynx / Detail.controller.js
Created August 4, 2020 13:24
UI5 Drag and drop example with Gridlist
handleDropToList(oEvent) {
// Define if item is dropped on, before or after elements in new drop-list
// let sDropPosition = oEvent.getParameter("dropPosition");
// Define the list which is dragged from, and the handled Item
let oDraggedControl = oEvent.getParameter("draggedControl");
let oDraggedItems = oDraggedControl.mBindingInfos.items;
let oDraggedPath;
/**
* Helper function to encrypt a JSON or Javascript Object
*
*/
const crypto = require("crypto");
const jEncrypt = (pubKey, obj, callback) => {
const algorithm = "aes-192-cbc";
/*
* The node process
* It's a global object that, itself as well as its methods
* and nested objects, can be accessed from anywhere anytime.
* Within the process, global variables can be defined. A prominent
* example is the node.env.NODE_ENV variable. It is a convention to,
* for instance, set the process.env.NODE_ENV to production.
*/
console.log(process);
console.log(process.memoryUsage());
@EarthenLynx
EarthenLynx / javascript.jsonc
Last active June 26, 2020 07:53
ui5 JavascriptCcode Snippets
{
// Place your snippets for javascript here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
@EarthenLynx
EarthenLynx / LongTextInput.vue
Last active May 7, 2020 09:32
Minimalistic Vue Inputs with Spectre.css classes
<template>
<div class="form-group mb-4">
<label class="text-bold">{{label}}</label>
<textarea @keyup="emitValue" v-model="text" class="form-input" :id="id" :placeholder="placeholder" :name="name" rows="2" />
<small style="float: right;" v-if="wordcount && textValue.words > 1">Count: {{textValue.words}} words</small>
</div>
</template>
<script>
/*
@EarthenLynx
EarthenLynx / MixinsAndFilters.vue
Created April 15, 2020 14:21
Filter snippet for vue.js
<template>
<div class="container" id="app">
<div class="row">
<div class="col">
<h1>Filters & Mixins</h1>
<!-- Local filter which reverses the text that is applied -->
<input type="text" class="form-control" v-model="text"/>
<p>{{text|reverseText}}</p>
<!-- Build a global filter that counts the length of a word + appends it -->
@EarthenLynx
EarthenLynx / deleteRecipe.js
Created April 13, 2020 20:00
CRUD Operations from MongoDB - Recipe database as well as matching images
const Recipe = require("../models/recipe");
const path = require("path");
const fs = require("fs");
const galleryPath = require("../config/paths").galleryPath;
const date = new Date();
// Find the recipe by the given ID and delete it from the database.
const deleteRecipe = function (req, res) {
Recipe.findByIdAndDelete(req.body.recipe_id, (err, data) => {
@EarthenLynx
EarthenLynx / DMan.js
Last active April 13, 2020 20:01
Simple collection of classes to create DOM elements with javascript
class D {
// Initialize the constructor. An object is passed that specifies the DOM element to be created
constructor(
props = {
el: "" /* Type of the DOM element */,
cl: [] /* Class list */,
id: "",
src: "" /* This is also considered as the href for css elements */,
href: "", /* Adds a ref for anchor elements or buttons [not to be confused with src] */
name: "" /* Adds a name to the element */,
@EarthenLynx
EarthenLynx / checkColorBrightness.js
Last active April 13, 2020 19:47
Some useful color methods to be used as modular functions. Credit where credit's due: If not my own, the source is given in comments.
// Check for color darkness. Returns false of dark'ish, true if bright
function checkForBrightness(arr) {
let sortedArr = arr.sort;
return (sortedArr[0] < 150 && sortedArr[1] < 80 && sortedArr[2] < 80) ?
false : true
}