Skip to content

Instantly share code, notes, and snippets.

View djom202's full-sized avatar

Jonathan Olier djom202

View GitHub Profile
@djom202
djom202 / number_format.js
Created March 15, 2018 22:56
Function to give them format an numbers. #javascript #numbers
function number_format(amount, decimals) {
amount += ''; // por si pasan un numero en vez de un string
amount = parseFloat(amount.replace(/[^0-9\.]/g, '')); // elimino cualquier cosa que no sea numero o punto
decimals = decimals || 0; // por si la variable no fue fue pasada
// si no es un numero o es igual a cero retorno el mismo cero
if (isNaN(amount) || amount === 0)
return parseFloat(0).toFixed(decimals);
@djom202
djom202 / .htaccess
Created February 19, 2018 23:42
force ssl and redirect to index.php
RewriteEngine On
RewriteBase /
#if the request is not secure
RewriteCond %{HTTPS} off
#redirect to the secure version
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]
#These are your existing rules
RewriteCond %{REQUEST_FILENAME} !.(jpg|jpeg|gif|png|css|js|pl|txt)$ [NC]
@djom202
djom202 / README.md
Created December 31, 2017 03:37
Objetos en JavaScript

Objetos en JavaScript

Cuando se está comenzando a aprender JavaScript se suele adquirir la mala costumbre de crear funciones e ir copiando el mismo código fuente en archivos de otros proyectos nuevos. El problema es que a medida que el número de proyectos y funciones va creciendo y es necesario modificar éstas, hay que realizar dicha modificación en todos los proyectos.

Una forma de evitarlo, es guardar todas las funciones del mismo tipo (por ejemplo, referentes a fechas) en un archivo y copiarlo a otros proyectos.

Pero aún mejor es crear un Objeto en JavaScript con dichas funciones encapsuladas dentro del mismo (pasarían a denominarse métodos), teniendo así nuestro código fuente mejor estructurado y controlado.

Para crear un Objeto en JavaScript, como sucede en todo Lenguaje de Programación Orientado a Objetos es preciso crear su constructor (digamos que sería la función principal), propiedades (o variables internas del Objeto) y métodos (las funciones internas del mismo).

function randomId(lenght) {
var charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_';
var id = '';
var randPos = 0;
for (var i = 1; i <= lenght; i++) {
randPos = Math.floor(Math.random() * charSet.length);
id += charSet[randPos];
}
@djom202
djom202 / index.js
Created November 17, 2017 19:53 — forked from max-mapper/index.js
requirebin sketch
var observer = require('continuous-observer')
var cave = require('cave-automata-2d')
var fill = require('ndarray-fill')
var zero = require('zeros')
var raf = require('raf')
var canvas = document.createElement('canvas')
var ctx = canvas.getContext('2d')
// Set up the controls, so that we can control
@djom202
djom202 / run-test-build-and-deploy.sh
Created October 31, 2017 16:28 — forked from EstebanMDQ/run-test-build-and-deploy.sh
run gulp build in codeship and deploy that to heroku
gulp test
gulp build
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
git add build
git commit -am "app built"
export CI_COMMIT_ID=$(git rev-parse HEAD)

Change default Mac OS X PHP to MAMP's PHP Installation and Install Composer Package Management


Instructions to Change PHP Installation


First, Lets find out what version of PHP we're running (To find out if it's the default version).

To do that, Within the terminal, Fire this command:

which php

@djom202
djom202 / docsRouter.js
Last active May 26, 2017 13:46
Listing the routes in express
/*
Routers Docs
*/
'use strict';
var Table = require('cli-table'),
table = null;
@djom202
djom202 / base64.js
Created May 25, 2017 02:46 — forked from inadarei/base64.js
base64 encode/decode in Node.js
var url = "http://cdn1.giltcdn.com/images/share/uploads/0000/0001/7250/172502872/420x560.jpg";
var encoded = new Buffer(url).toString('base64');
var decoded = new Buffer(encoded, 'base64').toString('ascii')
console.log(encoded);
console.log(decoded);
@djom202
djom202 / sendEmail.js
Created May 5, 2017 19:39
Sending an email with Nodejs
var nodemailer = require('nodemailer');
exports.send = function(){
var mailTransport = nodemailer.createTransport('smtps://user%40gmail.com:[email protected]'),
email = '[email protected]',
mailOptions = {
from: '"Firebase Database Quickstart" <[email protected]>',
to: email,
subject: 'New star!',
text: 'One of your posts has received a new star!'