Skip to content

Instantly share code, notes, and snippets.

View ramonvictor's full-sized avatar

Ramon Bezerra ramonvictor

View GitHub Profile
// Reducer (pure function)
function updatePlayer(player, action) {
switch (action.type) {
case 'PICK_SIDE':
return action.side;
default:
return player || '';
}
}
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)
});
});
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 },
@ramonvictor
ramonvictor / wait-function.js
Created April 23, 2016 16:05
Fancy setTimeout wrapper using native Promise.
var wait = function(ms) {
ms = ms || 500;
return new Promise(function(resolve, reject){
window.setTimeout(function() {
resolve();
}, ms);
});
};
// USAGE
(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;
@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 / 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 / get-youtube-info.js
Last active December 9, 2020 15:43
Javascript/jQuery function to get youtube video information by passing video url.
var getYoutubeIdByUrl = function( url ){
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
var match = url.match(regExp);
if(match&&match[7].length==11){
return match[7];
}
return false;
};
@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';
@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 -->