Skip to content

Instantly share code, notes, and snippets.

View carlosvega20's full-sized avatar

Carlos Vega carlosvega20

  • San Francisco, CA
View GitHub Profile
@carlosvega20
carlosvega20 / rpio_python_init_sh
Last active August 29, 2015 14:26
Configure Rasperry Pi, I2C and The RPi.GPIO Python Library
#!/bin/bash
#You need to enable i2c port
#sudo raspi-config
# Choose option: (8) Advanced Options
# A7 I2C and then enable yes.
#sudo reboot
#Update and install python rpi
sudo apt-get update
sudo apt-get dist-upgrade
@carlosvega20
carlosvega20 / .js
Created September 24, 2015 21:56 — forked from hzhu/.js
Data Transformation
var x = [ {node: "ip2", app: "dbsyncer", containerId: "1234"},
{node: "ip2", app: "logforwa", containerId: "3423"},
{node: "ip4", app: "dbsyncer", containerId: "2213"},
{node: "ip4", app: "logforwa", containerId: "3434"} ]
var newObj = {};
x.forEach(function (item) {
newObj[item.node] = newObj[item.node] || [];
//Simulation
var world = {gravity: 9.8, intervalTime: 100, verticalLimit: 600, dt: 0.1}
function simulation (obj) {
var t = 0, top = 0;
var interval = setInterval(function () {
if(top>world.verticalLimit) clearInterval(interval);
top += (world.gravity*obj.mass)*t;
obj.el.style.top = top+"px";
t += world.dt;
@carlosvega20
carlosvega20 / Js Inheritance
Created December 4, 2015 06:10
prototype chain
//Inheritance
var Mass = function () {this.material = "rock"; console.log("init Mass")};
var Planet = function (name) {Mass.call(this); this.name = name || "Planet"; console.log("init "+this.name)};
Planet.prototype = Object.create(Mass.prototype);
Planet.prototype.constructor = Planet;
var earth = new Planet("earth");
// Second Way
@carlosvega20
carlosvega20 / slim-redux.js
Created December 11, 2015 06:17 — forked from gaearon/slim-redux.js
Redux without the sanity checks in a single file. Don't use this, use normal Redux. :-)
function mapValues(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
result[key] = fn(obj[key], key);
return result;
}, {});
}
function pick(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
if (fn(obj[key])) {
const add = (list, item) => {
return […list, item]
}
const remove = (list, index) => {
return [
…list.slice(0,index),
…list.slice(index+1)
]
}
//based on https://github.com/krasimir/absurd/blob/master/lib/processors/html/helpers/TemplateEngine.js
//Basic
var TemplateEngine = function(tpl, data) {
var re = /<%(.+?)%>/g, match;
while(match = re.exec(tpl)) {
tpl = tpl.replace(match[0], data[match[1]])
}
return tpl;
}
@carlosvega20
carlosvega20 / Counter.js
Last active November 1, 2016 14:15 — forked from gaearon/Counter.js
import React, { Component } from 'react';
const counter = (state = { value: 0 }, action) => {
switch (action.type) {
case 'INCREMENT':
return { value: state.value + 1 };
case 'DECREMENT':
return { value: state.value - 1 };
default:
return state;
//StackOverflow:
//http://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb
//Solution 1.
//////////////////////////////////////////////
function rgbToHex(r, g, b) {
return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
}
//////////////////////////////////////////////
Hablar sobre variables(fuerte tipado),
luego funciones (como se crean function, var function, arrow function),
luego scopes (var, const, let)
luego variables como templates
Classes, interfaces, herencia (polimorfismo, encapsulamient)
luego hablar sobre OOP con classes y extend
vs functional programing( fp are verbs, oop is nouns)