Skip to content

Instantly share code, notes, and snippets.

View cassiozen's full-sized avatar
:atom:

Cassio Zen cassiozen

:atom:
View GitHub Profile
/* Card basic structure and positioning (Including front and back) */
/* Slightly modified version from the original: http://selfthinker.github.io/CSS-Playing-Cards/ (CC BY-SA) */
.card-group {
transform-style: preserve-3d;
transform-origin: 3em 4.5em; /* half of card size */
}
.card {
width: 6em;
height: 9em;
@cassiozen
cassiozen / rankPokerHand.js
Last active August 29, 2015 13:14
Calculates the Rank of a 5 card Poker hand using bit manipulations.
// Calculates the Rank of a 5 card Poker hand using bit manipulations.
// Adapted from the original CPOL-Licensed code by subskybox
// In-depth article explaining how the rank function works available here:
// http://www.codeproject.com/Articles/569271/A-Poker-hand-analyzer-in-JavaScript-using-bit-math
rankPokerHand(hand) {
if(hand.length < 5) return;
let v, i, o, s = 1 << hand[0].rank | 1 << hand[1].rank | 1 << hand[2].rank | 1 << hand[3].rank | 1 << hand[4].rank;
for (i = 0, v = o = 0; i < 5; i++) {
o = Math.pow(2, hand[i].rank * 4);
v += o * ((v / o & 15) + 1);
var Dispatcher = require('flux').Dispatcher;
/*
* Do not create helper methods such as "handleViewAction" unless you have a use case in your app
var AppDispatcher = new Dispatcher();
AppDispatcher.handleViewAction = function(action) {
this.dispatch({
source: 'VIEW_ACTION',
action: action
});
create: function(text) {
// Instead of using the helper
// AppDispatcher.handleViewAction(...)
// Dispatch directly
AppDispatcher.dispatch({
actionType: TodoConstants.TODO_CREATE,
text: text
});
}
var TodoStore = assign({}, EventEmitter.prototype, {
/*
* These aren't really necessary:
*
addChangeListener: function(callback) {
this.on(CHANGE_EVENT, callback);
},
removeChangeListener: function(callback) {
this.removeListener(CHANGE_EVENT, callback);
}
componentDidMount: function() {
// Instead of TodoStore.addChangeListener(this._onChange);
TodoStore.addListener(StoreConstants.CHANGE, this._onChange);
},
componentWillUnmount: function() {
// Instead of TodoStore.removeChangeListener(this._onChange);
TodoStore.removeListener(StoreConstants.CHANGE,this._onChange);
},
var contacts = {};
var handleAddContact = (action) => {
contacts.assign(contacts, action.contact);
ContactsStore.emitChange();
}
var handleRemoveContact = (action) => {
var updatedContacts = state.contacts.filter((contact) => {
return contact.id !== action.contact.id;
var keyMirror = require('react/lib/keyMirror');
module.exports = {
API: 'http://my-rest-api.com',
ActionTypes: keyMirror({
ADD_CONTACT: null,
DELETE_CONTACT: null
})
};
var events = new EventEmitter();
var CHANGE_EVENT = 'CHANGE';
var todos = {};
var TodoStore = {
addChangeListener: function(callback) {
events.addListener(CHANGE_EVENT, callback);
},
import React, { Component } from 'react';
class Voucher extends Component {
constructor() {
super(…arguments)
this.state = {
passengers: [
'Simmon, Robert A.',
'Taylor, Kathleen R.'
],