Skip to content

Instantly share code, notes, and snippets.

View ramonvictor's full-sized avatar

Ramon Bezerra ramonvictor

View GitHub Profile
@ramonvictor
ramonvictor / index.js
Created April 4, 2014 13:23
Synchronous nodejs directory loop
var glob = require("glob");
var fs = require("fs");
// async map file contents
var async = function async(arg, callback) {
fs.readFile(arg, 'utf8', function (err, data) {
if (err) throw err;
callback(arg, data);
});
};
@ramonvictor
ramonvictor / ng-commerce-guide.md
Created April 11, 2014 14:37
Guia para apresentação sobre AngularJS

Intro

  1. Apresentacao da gente
  2. Gileno: Segue com os slides

Home

  1. Gileno: Insere angularjs, ng-app, app, data, homecontroller.

  2. Ramon:

@ramonvictor
ramonvictor / archive.php
Created August 12, 2012 21:20
Wordpress ajax share buttons render
<!doctype html>
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="pt-br"> <![endif]-->
<!--[if IE 7]> <html class="no-js ie7 oldie" lang="pt-br"> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8 oldie" lang="pt-br"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="pt-br"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<title>Title of your website</title>
<!-- SEO meta tags -->
@ramonvictor
ramonvictor / _base.scss
Created April 19, 2013 02:26
Mixin experiment for compass sprite.
// this file would be under "sass" directory
@mixin new-icon( $name, $is-sprite: false ){
$icon-path: 'icons/' + $name + '-icon.png';
display: inline-block;
width: image-width($icon-path);
height: image-height($icon-path);
@if $is-sprite {
$sprite-name: $name + '-icon';
(function() {
function getTreeWalker(root, onlyComponents) {
return document.createTreeWalker(
root,
NodeFilter.SHOW_ELEMENT,
{
acceptNode: function(node) {
if (onlyComponents) {
if (node && node.nodeType === 1 && node.dataset.component) {
return NodeFilter.FILTER_ACCEPT;
this.$table.addEventListener('click', function(event) {
var state = store.getState();
// [Prevent dispatch under certain conditions]
// Otherwise, trigger `SET_X` or `SET_O`
store.dispatch({
type: state.turn === 'x' ? 'SET_X' : 'SET_O',
index: parseInt(index, 10)
});
});
// [require modules and do some express setup]
// ...and here is where the magic happens:
io.on('connection', function(socket) {
socket.on('room', function(room) {
socket.join(room);
});
socket.on('dispatch', function(data) {
socket.broadcast.to(data.room).emit('dispatch', data);
});
function Store() {
this.state = {};
this.state = this.update(this.state, {});
// `this.update()` will return the initial state:
// ----------------------------------------------
// {
// grid: ['', '', '', '', '', '', '', '', ''],
// turn: 'x',
// score: { x: 0, o: 0 },
// `config.room` is a random ID generated on page load.
var socket = io();
TicTacToe.prototype.init = function(config) {
this.room = config.room;
};
TicTacToe.prototype.eventListeners = function() {
socket.on('connect', this.onSocketConnect.bind(this));
socket.on('dispatch', this.onSocketDispatch.bind(this));
// Reducer (pure function)
function updatePlayer(player, action) {
switch (action.type) {
case 'PICK_SIDE':
return action.side;
default:
return player || '';
}
}