Skip to content

Instantly share code, notes, and snippets.

@warlock
warlock / pad.js
Last active June 20, 2017 10:26
Javascript Pad : How To Add/Insert Leading Zeros To Numbers
var pad = (n, width, z) => {
z = z || '0'
n = n + ''
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n
}
@warlock
warlock / express-cache.js
Created June 20, 2017 10:00
Express Static Cache
app.configure('production', function() {
var oneYear = 31557600000;
app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
app.use(express.errorHandler());});
@warlock
warlock / locales.bash
Created June 20, 2017 10:02
Debian Locales Configuration
export LANG=es_ES.UTF-8
export LANGUAGE=es_ES.UTF-8
export LC_ALL=es_ES.UTF-8
dpkg-reconfigure locales
@warlock
warlock / express-no-body-parser.js
Last active October 18, 2017 12:22
Expres.js without body-parser
app.use((req, res, next) => {
var data = "";
req.on('data', chunk => { data += chunk })
req.on('end', () => {
req.rawBody = data
req.jsonBody = JSON.parse(data)
next()
})
})
@warlock
warlock / repeat.js
Last active June 20, 2017 10:24
Repeat polyfill in Javascript
if (!String.prototype.repeat) {
String.prototype.repeat = function(count) {
'use strict';
if (this == null) {
throw new TypeError('can\'t convert ' + this + ' to object');
}
var str = '' + this;
count = +count;
if (count != count) {
count = 0;
@warlock
warlock / load_jquery_in_browser.js
Created June 20, 2017 10:14
Load JQuery in Browser
var script = document.createElement('script');script.src = "https://code.jquery.com/jquery-3.2.1.min.js";
document.getElementsByTagName('head')[0].appendChild(script);
@warlock
warlock / dom-to-json.js
Created June 21, 2017 13:44 — forked from sstur/dom-to-json.js
Stringify DOM nodes using JSON (and revive again)
function toJSON(node) {
node = node || this;
var obj = {
nodeType: node.nodeType
};
if (node.tagName) {
obj.tagName = node.tagName.toLowerCase();
} else
if (node.nodeName) {
obj.nodeName = node.nodeName;
@warlock
warlock / make-component.js
Last active June 30, 2017 16:20
Angular 1.5 Client (angular-1.5-cli -g is gen)
/* ANGULAR 1.5 CLIENT BASIC COMANDS
gen -h => help
gen new project_name => make new project
gen -c component_name => make new component
npm start => run development server
npm run build => build distribution bundle
*/
/* COMPONENT HTML
<h1 id="ar"><span ng-click="homeController.funcio()">{{homeController.name}}</span> world! </h1>
@warlock
warlock / app.module.js
Last active June 30, 2017 16:20
angular-1.5-cli Router with Components (angular-ui-router)
/*
<body ng-app="routerApp">
<nav class="navbar navbar-inverse" role="navigation">
<div class="navbar-header">
<a class="navbar-brand" ui-sref="#">AngularUI Router</a>
</div>
<ul class="nav navbar-nav">
<li><a ui-sref="home">Home</a></li>
<li><a ui-sref="proba">Proba</a></li>
</ul>
@warlock
warlock / index.js
Last active August 2, 2017 12:00
NPX TESTING
#!/usr/bin/env node
const sb = require('spellbook')
console.log('test')
console.log(sb.random(0,5))