Skip to content

Instantly share code, notes, and snippets.

View djom202's full-sized avatar

Jonathan Olier djom202

View GitHub Profile
@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 "you@email.com"
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:pass$@smtp.gmail.com'),
email = 'user@gmail.com',
mailOptions = {
from: '"Firebase Database Quickstart" <noreply@firebase.com>',
to: email,
subject: 'New star!',
text: 'One of your posts has received a new star!'
@djom202
djom202 / Gulpfile.js
Created May 2, 2017 14:12 — forked from webdesserts/Gulpfile.js
Automatically reload your node.js app on file change with Gulp (https://github.com/wearefractal/gulp).
// NOTE: I previously suggested doing this through Grunt, but had plenty of problems with
// my set up. Grunt did some weird things with scope, and I ended up using nodemon. This
// setup is now using Gulp. It works exactly how I expect it to and is WAY more concise.
var gulp = require('gulp'),
spawn = require('child_process').spawn,
node;
/**
* $ gulp server
* description: launch the server. If there's a server already running, kill it.
@djom202
djom202 / Food.js
Created April 4, 2017 19:08 — forked from ryanlanciaux/Food.js
Files for AngularJS blog post.
/*---------------------
:: Food
-> model
---------------------*/
module.exports = {
attributes : {
name: 'STRING',
type: 'STRING',
expiration: 'DATE',
quantity: 'STRING',