Skip to content

Instantly share code, notes, and snippets.

💡

Victor victornpb

💡
Block or report user

Report or block victornpb

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@victornpb
victornpb / parseQueryString.js
Created Oct 16, 2019
Simple query string parser
View parseQueryString.js
/*
Example:
parseQueryString('?foo=hi&bar=World%20Hello')
{
foo: "hi",
bar: "Hello World"
}
*/
/**
@victornpb
victornpb / ajax.js
Created Oct 16, 2019
Minimal ajax library
View ajax.js
/**
* Minimal Ajax library
* @param {object} options Options
* @param {string} options.url Url
* @param {string} [options.method='GET'] Method GET|POST|PUT|DELTE
* @param {string} [options.data] Body of the request
* @param {string} [options.contentType='application/x-www-form-urlencoded'] Set the content type of the body
* @param {number} [options.timeout] Timout in milliseconds
* @param {boolean} [options.withCredentials=false] withCredentials
* @return {Promise} Returns a promise
@victornpb
victornpb / param.js
Created Oct 16, 2019
Simple location.hash parser
View param.js
/**
* url hash manager
* @author Victor N <victornunes@lett.digital>
*/
const param = (function HashParams() {
function parse(string) {
var params = {};
string.replace(/^[#?]/, '').split('&').forEach(text => {
var p = text.split('=');
View domReady.js
/**
* domReady for IE6+
* @param {Function} callback Callback
*
* @author http://beeker.io/jquery-document-ready-equivalent-vanilla-javascript
* @date 2016-10-04
*/
function domReady(callback) {
var ready = false;
var detach = function() {
View shuffle.js
function shuffle(arr) {
const a = arr.slice();
for (let i = a.length; i; i--) {
let j = Math.floor(Math.random() * i);
[a[i - 1], a[j]] = [a[j], a[i - 1]];
}
return a;
}
View sortBy.js
function sortBy(arr, fields) {
function compareFn(a, b) {
return fields
.map(field => {
let dir = 1;
if (field[0] === "-") {
dir = -1;
field = field.substring(1);
}
return a[field] > b[field] ? dir : a[field] < b[field] ? -dir : 0;
@victornpb
victornpb / bookmarklet
Created Jun 1, 2019
Import/Export Beanstalk Enviroment Variables
View bookmarklet
javascript:(function () { var html = ` <div style="position: fixed; top: 50px; left: 50px; background-color:black; color: white; padding: 5px;"> <div> <button class="getBtn">GET</button> <button class="setBtn">SET</button> <button class="closeBtn">X</button> </div><br> <textarea placeholder="Click GET or type a JSON" style="font-family:monospace; width: 500px; height: 300px;"></textarea> </div> `; var d = document.createElement('div'); d.innerHTML = html; var textarea = d.querySelector('textarea'); var setBtn = d.querySelector('.setBtn'); var getBtn = d.querySelector('.getBtn'); var closeBtn = d.querySelector('.closeBtn'); setBtn.onclick = importJson; getBtn.onclick = exportJson; closeBtn.onclick = () => { document.body.removeChild(d); }; document.body.appendChild(d); textarea.focus(); function exportJson() { var v = JSON.stringify(Object.fromEntries(Array.from(document.querySelectorAll('.pro
@victornpb
victornpb / .eslintrc.json5
Last active May 22, 2019
eslintrc containing all rules with description
View .eslintrc.json5
// All rules
// (R=Recommended,F=Fixable)
// Use .json5 highlighting
{
// Possible Errors
// These rules relate to possible syntax or logic errors in JavaScript code:
"for-direction": "error", // (R,) enforce “for” loop update clause moving the counter in the right direction.
"getter-return": "error", // (R,) enforce return statements in getters
"no-async-promise-executor": "error", // (R,) disallow using an async function as a Promise executor
"no-await-in-loop": "off", // (,) disallow await inside of loops
@victornpb
victornpb / v-tooltip.js
Last active May 7, 2019
Using Bootstrap tooltips in Vue.js with a simple directive
View v-tooltip.js
/**
* Enable Bootstrap tooltips using Vue directive
* @author Vitim.us
* @see https://gist.github.com/victornpb/020d393f2f5b866437d13d49a4695b47
* @example
* <button v-tooltip="foo">Hover me</button>
* <button v-tooltip.click="bar">Click me</button>
* <button v-tooltip.html="baz">Html</button>
* <button v-tooltip:top="foo">Top</button>
* <button v-tooltip:left="foo">Left</button>
@victornpb
victornpb / bindForm.js
Created Apr 14, 2019
Two way data binding DOM and vanilla Javascript in under 100 lines
View bindForm.js
function dd(context = {}) {
const values = {};
const boundElms = {};
const elms = Array.from(document.querySelectorAll('[data-bind]'));
elms.forEach(el => {
const prop = el.getAttribute('data-bind');
if (!boundElms[prop]) boundElms[prop] = [];
You can’t perform that action at this time.