Skip to content

Instantly share code, notes, and snippets.

View MarcoWorms's full-sized avatar
:shipit:
undefined

Marco Guaspari Worms MarcoWorms

:shipit:
undefined
View GitHub Profile
body {
background-color: black;
font-family: Lucida Sans Unicode;
color: #ffffff;
}
div {
border: 1px solid black;
}
@MarcoWorms
MarcoWorms / closure1.js
Last active July 6, 2016 16:49
Closure 1
function pai (umNumero) {
var metadeDoNumero = umNumero / 2
function filho () {
console.log(umNumero)
console.log(metadeDoNumero)
}
filho()
}
function pai (carro) {
var comida = 'pizza'
function filho () {
console.log(comida)
function neto () {
console.log(carro)
}
function contador () {
var valor = 0
return {
incrementar: function () {
valor += 1
},
getValor: function () {
return valor
}
@MarcoWorms
MarcoWorms / closure4.js
Last active March 17, 2017 06:39
Closure 4
function player (forca, stamina, agilidade) {
var hp = stamina * 10
function umaFuncaoPrivadaGrande (que, recebe, varios, parametros) {
// essa função é um método privado de um objeto.
// você pode chamar ela quando precisar ou até torná-la pública
}
return {
// example of what this code would produce => http://worms.io/pocDeclarative
const makePlayer = () => {
return {
initial: {
size: [50, 50],
position: [10, 10],
physics: true
},
//
// Motivations:
//
// * bring accessible functional programming to game development
// * handy and easy default options for quick game prototyping
// * flexibility for advanced game developers
const W = {
getAngle: (pointA, pointB) => null,
emit: (channel, message, data) => null
const Immutable = require('immutable')
const add = (channels, name) => {
return channels.set(name, Immutable.List())
}
const addAction = (channels, name, action) => {
return channels.set(name, channels.get(name).push(action))
}
@MarcoWorms
MarcoWorms / mini-redux.js
Last active August 7, 2023 19:06
Redux in a nutshell
function createStore (reducers) {
var state = reducers()
const store = {
dispatch: (action) => {
state = reducers(state, action)
},
getState: () => {
return state
}
}
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<div id="root"></div>
<script src="main.js"></script>
</body>
</html>