Skip to content

Instantly share code, notes, and snippets.

View cassiozen's full-sized avatar
:atom:

Cassio Zen cassiozen

:atom:
View GitHub Profile
let newStudent = React.addons.update(student, {grades:{$push: ['A']}})
let newStudent = update(student, {grades:{$set: ['A','A','B']}})
let newTicket = update(originalTicket, {
arrival: {
airport: {$set: 'MCO'}
}
});
let newTicket = update(originalTicket,{
codeshare: {
0: { $set: {company:'AZ', flightNo:'7320'} }
}
});
@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);
/* 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;
import React, { Component } from 'react';
import {render} from 'react-dom';
class SearchBox extends Component {
render(){
return (
<input type="search"
value={this.props.value}
onChange={this.props.onSearch.bind(this)}/>
import React, { Component } from 'react'
import {render} from 'react-dom'
import Toggable from './Toggable'
class App extends Component {
constructor() {
super()
this.state = {
amountOfItems: 0,
totalPrice: 0
import React, { Component } from 'react'
import {render} from 'react-dom'
import Toggable from './Toggable'
class App extends Component {
constructor() {
super()
this.state = {
amountOfItems: 0,
totalPrice: 0
import React, { Component } from 'react';
class Toggable extends Component {
onBuyClick(){
this.props.onBuy(this.props.price)
}
onHeaderClick(){
this.props.onToggle(this.props.id)
}