Skip to content

Instantly share code, notes, and snippets.

@raphamorim
raphamorim / clone.js
Last active August 29, 2015 13:56
A elegant way to clone antoher object in JavaScript
function cloneObject(obj){
if ("object" != typeof obj) return obj;
var copy = obj.constructor();
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr];
}
return copy;
}
@raphamorim
raphamorim / firstExercise.py
Created September 27, 2014 03:33
First exercise from a sequence of challenges
#!/usr/bin/python
import numpy as np
print "1 = Faca um algoritmo que troque o valor de duas variaveis. Por exemplo, o algoritmo le n1 igual a 3 e n2 a 17, e mostra n1 igual a 17 e n2 a 3."
print "2 = Faca um algoritmo para calcular a media de duas notas digitadas pelo usuario."
print "3 = Faca um algoritmo que calcule a area de um quadrado, sendo que o comprimento do lado e informado pelo usuario. A area do quadrado e calculada elevando-se o lado ao quadrado."
exerc = int(raw_input("Defina qual o numero do exercicio: "))
if exerc == 1:
@raphamorim
raphamorim / promisesBlueBird.js
Last active August 29, 2015 14:17
Promise Example
// using bluebird
var Servico = {
listarUsuarios: function(callback) {
setTimeout(function(){ callback(null, [{nome:"Gabriel"}, {nome:"Raphael"}]) }, 100);
},
listarFavoritos: function(usuario, callback) {
if (usuario.nome === "Gabriel") {
setTimeout(function(){ callback(null, ["http://www.google.com.br"]) }, Math.random() * 100);
// From QUnit.js
function objectType( obj ) {
if ( typeof obj === "undefined" ) {
return "undefined";
}
// Consider: typeof null === object
if ( obj === null ) {
return "null";
}
@raphamorim
raphamorim / webgl-init.js
Created May 15, 2016 22:58
WebGL Boilerplate
function createShaders(gl) {
var vertexShaderSrc = String(); // fill it with shader string or Script Text
var vertexShader = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(vertexShader, vertexShaderSrc);
gl.compileShader(vertexShader);
var success = gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS);
if (!success) {
throw "could not compile shader:" + gl.getShaderInfoLog(vertexShader);
}
/* reset */
* {
padding: 0;
margin: 0;
border: 0;
outline: 0;
font-size: 100%;
line-height: 1em;
list-style: none;
text-decoration: none;
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Some Random Page</title>
<link href="style.css" rel="stylesheet">
<script src="jquery.js"></script>
</head>
<body>
<div><img src="polemic-photo.jpg"></div>
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Some Random Page</title>
<link href="style.css" rel="stylesheet">
<script src="jquery.js" async></script>
</head>
<body>
<div><img src="polemic-photo.jpg"></div>
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Some Random Page</title>
<style>
body {
border: 1px solid black;
background: white;
}
p {
#!/bin/sh
# Parts of this file come from:
# http://en.wikibooks.org/wiki/Clojure_Programming/Getting_Started#Create_clj_Script
BREAK_CHARS="\(\){}[],^%$#@\"\";:''|\\"
CLOJURE_DIR=/usr/local/lib/clojure
CLOJURE_JAR=$CLOJURE_DIR/clojure.jar
CLASSPATH="$CLOJURE_DIR/*:$CLOJURE_JAR"
while [ $# -gt 0 ]