Skip to content

Instantly share code, notes, and snippets.

@Vladmel1234
Vladmel1234 / gist:2438d3da2af11b72338eccedd3f68e2c
Created July 17, 2016 06:16
logger factory for printing sourcepath
var logger = require('logger')(module);
logger.info('My log statement');
Inside your logger module:
var winston = require('winston');
module.exports = function (module) {
var filename = module.id;
@Vladmel1234
Vladmel1234 / gist:def90501b10220e48d2f6c28a14f4c8f
Created August 14, 2016 04:49 — forked from matthewp/gist:3099268
XMLHttpRequest wrapped into a promise
function xhr(options) {
var deferred = Q.defer(),
req = new XMLHttpRequest();
req.open(options.method || 'GET', options.url, true);
// Set request headers if provided.
Object.keys(options.headers || {}).forEach(function (key) {
req.setRequestHeader(key, options.headers[key]);
});
@Vladmel1234
Vladmel1234 / customer.js
Created October 1, 2016 15:57 — forked from geek0x23/customer.js
A mongoose model that takes advantage of the handy invalidate method to run multiple validations
var mongoose = require('./db-connect'),
Schema = mongoose.Schema,
ObjectId = Schema.ObjectId,
uuid = require('node-uuid'),
Validator = require('validator').Validator,
val = new Validator(),
bcrypt = require('bcrypt');
Validator.prototype.error = function(msg) { return false; };
@Vladmel1234
Vladmel1234 / ready.js
Last active October 19, 2016 07:06
document ready vanial js
let ready = function () {
}
document.addEventListener('DOMContentLoaded', ready )
@Vladmel1234
Vladmel1234 / ObjCheck.js
Created October 19, 2016 07:02
chech if object is empty js
Object.keys(myObject).length === 0
@Vladmel1234
Vladmel1234 / strIsEmpty.js
Created October 26, 2016 09:36
For checking if a string is blank or contains only white-space:
String.prototype.isEmpty = function() {
return (this.length === 0 || !this.trim());
};
@Vladmel1234
Vladmel1234 / replace.js
Created November 1, 2016 09:23
regex for all non leters js
replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g,"")
@Vladmel1234
Vladmel1234 / reactArray.js
Created December 18, 2016 14:47
render react array
var forms = [];
for (var i = 0; i < json.length; i++) {
forms.push(<formjs data={json[i]} submitState={submitState} currentState={currentState} />);
}
React.renderComponent(
<div>{forms}</div>,
document.body
);
# atom conf
@Vladmel1234
Vladmel1234 / swaparrayelements.js
Created June 12, 2017 06:31 — forked from eerohele/swaparrayelements.js
Swap two array elements (JavaScript)
/**
* Swap the elements in an array at indexes x and y.
*
* @param (a) The array.
* @param (x) The index of the first element to swap.
* @param (y) The index of the second element to swap.
* @return {Array} A new array with the elements swapped.
*/
var swapArrayElements = function (a, x, y) {
if (a.length === 1) return a;