Skip to content

Instantly share code, notes, and snippets.

View BananaAcid's full-sized avatar

Nabil Redmann BananaAcid

View GitHub Profile
@BananaAcid
BananaAcid / super-async-load.js
Created August 18, 2022 12:56
Load css & script with promises and wait till loaded
let add = (tag, url) => new Promise( (resolve) => {
let el = document.createElement(tag);
if (tag === 'link') {
el.rel = 'stylesheet';
el.href = url;
}
else if (tag === 'script') {
el.src = url;
}
@BananaAcid
BananaAcid / inview.client.js
Last active August 11, 2022 20:47
inView Directive for Vue + Vue3
// Licence ISC
// global
let inited = !!(window as any).inview_scroll_targets;
let targets:[{el:HTMLElement, value:any}] = (window as any).inview_scroll_targets = (window as any).inview_scroll_targets || [];
function isElementOutViewport(el) {
let rect = el.getBoundingClientRect();
@BananaAcid
BananaAcid / directMethods.mjs
Last active July 22, 2022 19:30
couchDB - putSecurity() and getSecurity() using fetch #PouchDB
/**
Access CouchDB to get and update a security object using fetch
(does it directly, no pouchdb or alike needed. PouchDB CAN get a _security object but not set it).
Usage:
let con = 'http://admin:adminpw@localhost:5984/user-numberone';
let secDoc = await getSecurity(con);
secDoc.members = ['user_to_add'];
@BananaAcid
BananaAcid / init typescript project.sh
Last active July 16, 2022 12:48
npm: init typescript project
mkdir app
cd app
npm init -y
npm i -D typescript
npm i ts-node
node_modules/.bin/tsc --init
touch index.ts
# package.json ->
# "start": "node_modules/.bin/ts-node index.ts",
@BananaAcid
BananaAcid / downloadBlob.vue3.js
Last active July 15, 2022 09:12
VUE 3 plugin to download a string
// Copyright Nabil Redmann, ISC License
// USE: import downloadBlob from 'downloadBlob.vue3.js'; app.use(downloadBlob);
export function downloadString(text:any, filename:string = 'unnamed.txt', mimeType:string = 'text/plain') {
var element = document.createElement('a');
element.setAttribute('href', 'data:' + mimeType + ';charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
@BananaAcid
BananaAcid / vs-code-settings-and-exts.code-workspace
Created June 30, 2022 10:52
onboarding vscode with all required plugins
{
"folders": [],
"settings": {
"extensions.ignoreRecommendations": false,
"prettier.arrowParens": "avoid",
"prettier.useTabs": true,
"prettier.requireConfig": true,
"html.format.indentInnerHtml": true,
"editor.formatOnSave": true,
"editor.formatOnType": true,
@BananaAcid
BananaAcid / crypto-stream.js
Created April 24, 2022 22:55 — forked from chris-rock/crypto-stream.js
Encrypt and decrypt streams
// Part of https://github.com/chris-rock/node-crypto-examples
// Nodejs encryption of buffers
var crypto = require('crypto'),
algorithm = 'aes-256-ctr',
password = 'd6F3Efeq';
var fs = require('fs');
var zlib = require('zlib');
@BananaAcid
BananaAcid / formidable.mjs
Created April 22, 2022 21:11
formidable in koa and ES6
import formidable from 'formidable';
router.post('/', async (ctx, next) => {
const form = formidable({ multiples: true, maxFileSize: 200 * 1024 * 1024 });
let fields, files;
@BananaAcid
BananaAcid / set-timestamp.ps
Last active March 25, 2022 10:21
Reset timestamp (creation + modification)
# has to be run in the folder where all files and sub-files should be changed (Win Powershell):
Get-ChildItem -force .\ * | ForEach-Object{$_.CreationTime = ("31 April 2022 16:01:43")}
Get-ChildItem -force .\ * | ForEach-Object{$_.LastWriteTime = ("31 April 2022 16:01:43")}
Get-ChildItem -force .\ * | ForEach-Object{$_.LastAccessTime = ("31 April 2022 16:01:43")}
@BananaAcid
BananaAcid / summernote-auto.js
Last active June 30, 2022 11:07
Includes summernote WYSIWYG editor with just one <script src="thisfile">
document.write(
'<!-- include libraries(jQuery, bootstrap) -->' +
'<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">' +
'<script src="https://code.jquery.com/jquery-3.5.1.min.js"></scr'+'ipt>' +
'<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></scr'+'ipt>' +
'<!-- include summernote css/js -->' +
'<link href="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote.min.css" rel="stylesheet">' +
'<script src="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote.min.js"></scr'+'ipt>' +
'<script>$(function(){$("[data-summernote]").summernote();});</scr'+'ipt>'
);