Skip to content

Instantly share code, notes, and snippets.

View juanmaguitar's full-sized avatar

JuanMa juanmaguitar

View GitHub Profile
@juanmaguitar
juanmaguitar / .babelrc
Created November 24, 2016 19:39 — forked from ifraixedes/.babelrc
Generators & Async function - Source files used for talks (meetups, etc)
{
"env": {
"development": {
"presets":["es2015-node5"],
"plugins": ["transform-async-to-generator"]
}
}
}
@juanmaguitar
juanmaguitar / app.js
Last active November 17, 2016 15:43
Demo jQuery POST - Express
const express = require('express');
const bodyParser = require('body-parser')
const app = express()
const PORT = 3000;
app.use( express.static('public') )
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
function saySomething( message, name ) {
console.log (message + " " + name + "!")
}
saySomething("Hi", "juanma") // "Hi juanma!"
saySomething("Bye", "juanma") // "Bye juanma!"
var sayHi = saySomething.bind(null, "Hi");
typeof sayHi === 'function' // true
sayHi("juanma") // "Hi juanma!"
@juanmaguitar
juanmaguitar / app.js
Created November 4, 2016 11:29
Promises Examples
const fs = require("fs")
fs.readFile('test.txt', 'utf-8', (err, contentFile) => {
setTimeout( ()=> {
contentFile = contentFile.toUpperCase();
fs.writeFile('output.txt', contentFile, (err) => {
console.log("file written")
@juanmaguitar
juanmaguitar / studentShuffle.js
Last active September 21, 2017 11:25
shuffle and group
function shuffleAndGroup (students, sizeGroups = 2) {
var shuffled = students.reduce( (acc, item, i, array) => {
var random = Math.floor(Math.random() * array.length);
array[i] = array.splice(random,1,item)[0]
return array
},[])
var grouped = shuffled.reduce((acc, current, index, array) => {
if (index % sizeGroups) {
@juanmaguitar
juanmaguitar / es2015-enhanced-objects-examples.js
Last active November 3, 2016 11:52
es2015 Enhanced Objects Example
var name = "juanma";
var handler = () => `handling things for ${this.name}...`;
var theProtoObj = {
location: "barcelona",
toString() {
return `I'm super!!`
}
}
@juanmaguitar
juanmaguitar / GeospacialSpherical.png
Last active February 21, 2018 03:40
MongoDb notes
GeospacialSpherical.png
@juanmaguitar
juanmaguitar / index3.html
Created October 15, 2016 08:44
React component change state (basic example)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>First Component</title>
</head>
<body>
<!-- container node -->
<div id="app"></div>
@juanmaguitar
juanmaguitar / index.html
Last active October 15, 2016 08:44
Basic React Component
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>First Component</title>
</head>
<body>
<!-- container node -->
<div id="app"></div>
@juanmaguitar
juanmaguitar / user-pass-generated.js
Last active October 6, 2016 17:13
User password genrerated
function User ( name, username ) {
var password = User.generatePassword(15);
this.name = name;
this.username = username;
this.password = User.encryptPassword( password );
console.log("Your password is : " + password)