Skip to content

Instantly share code, notes, and snippets.

View carloscarvallo's full-sized avatar
🏠
Working from home

Carlos Carvallo carloscarvallo

🏠
Working from home
View GitHub Profile
@carloscarvallo
carloscarvallo / structs.go
Last active March 31, 2016 20:14
Simple example using structs in Go taken from the book "An Introduction to Programming in Go"
package main
import ("fmt"; "math")
type Circle struct {
x, y, r float64
}
type Rectangle struct {
x1, y1, x2, y2 float64
@carloscarvallo
carloscarvallo / interfaces.go
Created March 31, 2016 20:53
Similar to structs.go but implementing Interfaces and using a name for the return type on totalArea()
package main
import ("fmt"; "math")
type Circle struct {
x, y, r float64
}
type Rectangle struct {
x1, y1, x2, y2 float64
@carloscarvallo
carloscarvallo / regex.js
Created April 1, 2016 18:51
Verifies whether the expression exists
function regex( str ) {
console.log(/EXISTS/.test(str))
}
regex( process.argv[2] );
@carloscarvallo
carloscarvallo / promises.js
Created April 3, 2016 22:25
Basic throw for Promises in Javascript
var http = require('http');
var url = process.argv[2];
// ej: http://www.html5rocks.com/en/tutorials/es6/promises/story.json
function get(url) {
return new Promise(function(resolve, reject){
http.get(url, function (res) {
if (res.statusCode === 200) {
res.setEncoding('utf8');
@carloscarvallo
carloscarvallo / throw-error-promises.js
Created April 6, 2016 16:54
Great example how is Throws a error in Promises
function iterate (num) {
console.log(num);
return ++num;
};
function alwaysThrows () {
throw new Error("OH NO!!!");
};
Promise.resolve(iterate(1))
<!doctype html>
<html>
<head>
</head>
<body>
<div>
<p>score 1:</p>
<iframe id="soundslice-score" src="https://www.soundslice.com/scores/12802/embed/?api=1" width="100%" height="500" frameborder="0" allowfullscreen=""></iframe>
<script type="text/javascript">
// Array#map() for async!
function counter (limit, callback) {
var count = 0;
return function () {
count++;
if (count === limit)
callback();
}
}
function countdownTimer(target, timeLeft, options = {}) {
let defaults = {
container: ".timer-display",
timeUnit: "seconds",
clonedDataAttribute: "cloned",
timeoutClass: ".is-timeout",
timeoutSoonClass: ".is-timeout-soon",
timeoutSoonTime: 10
};
@carloscarvallo
carloscarvallo / index.jsx
Last active May 31, 2016 20:14
Ejemplo de props dinámicos React
import React from 'react';
export default class CommentBox extends React.Component {
render() {
const comments = this._getComments();
return(
<div className="comment-box">
<h3>Comments</h3>
<h4 className="comment-count">{this._getCommentsTitle( comments.length )}</h4>
<div className="comment-list">
@carloscarvallo
carloscarvallo / states.jsx
Created June 2, 2016 08:58
States in React
import React from 'react';
export default class CommentBox extends React.Component {
constructor() {
super();
this.state = {
showComments: false
};
}