Skip to content

Instantly share code, notes, and snippets.

View chaintng's full-sized avatar

Chainarong Tangsurakit chaintng

View GitHub Profile
@chaintng
chaintng / react-step-2-2.jsx
Last active October 16, 2016 04:29
react-step-2-2.jsx
var Filter = React.createClass({
propTypes: { // 1) assign expected parameter type
onFilterPokemonAtkChange: React.PropTypes.func,
onFilterPokemonTypeChange: React.PropTypes.func,
},
render: function() {
return (<div id="filterBar">
<label>Select Pokemon Type: </label>
<select name="type" id="pokemonTypeFilter" onChange={this.props.onFilterPokemonTypeChange}> {/* 2) assign event listener function for pokemon filter */}
<option value="">- ALL -</option>
@chaintng
chaintng / react-step-2-1.jsx
Last active October 16, 2016 04:20
react-step-2.jsx
var Pokedex = React.createClass({
getInitialState: function() { // 1) Setup initial state
return {
filterPokemonType: null,
filterPokemonAtk: null,
};
},
filterPokemonByTypeAndMinAtk: function (allPokemons, filterPokemonType, filterPokemonAtk) {
// ... Filter function just like in jQuery
},
@chaintng
chaintng / react-step-1.jsx
Last active October 16, 2016 04:12
react-step-1.jsx
var Result = React.createClass({
render: function() {
return (<div>
<div>--- Total Filter Pokemon: {this.props.filterPokemon.length} ---</div>
<ul>
<li></li> {/* how each pokemon display */}
</ul>
</div>);
}
});
@chaintng
chaintng / pokemonComponent.js
Created July 23, 2016 11:52
pokemonComponent.js
return <PokemonInfo pokemonDetail={item} />
@chaintng
chaintng / pokedex-react-2.js
Last active August 19, 2016 10:54
pokedex-react-2.js
// 3. set render function
var render = function() {
var filterPokemonType = store.getState().pokemonType;
var filterPokemonAtk = store.getState().pokemonAtk;
var filterPokemon = filterPokemonByTypeAndMinAtk(allPokemons, filterPokemonType, filterPokemonAtk);
ReactDOM.render(
<div>
<div>--- Total Filter Pokemon: {filterPokemon.length} ---</div>
<ul>
@chaintng
chaintng / pokedex-react-1.js
Last active August 19, 2016 10:54
pokedex-react-1.js
// 1. set Reducer function to accept store.dispatch()
var reducer = function (state, action) {
var newState = state;
if (typeof state === 'undefined') {
return {
pokemonType: null,
pokemonAtk: null
};
}
switch (action.type) {
@chaintng
chaintng / pokedex-jquery-2.js
Created July 23, 2016 10:21
pokedex-jquery-2.js
// 2. set render function
var renderPokemonList = function(filterPokemon) {
$("#filterPokemonCount").html(filterPokemon.length);
var liStrings = filterPokemon.map(function (item) {
return "<li>" + item.name + " (Atk: " + item.attack + ", Def: " + item.defense + ")</li>";
});
$("#pokemonListUl").html(liStrings);
}
@chaintng
chaintng / pokedex-jquery-1.js
Last active August 19, 2016 10:49
pokedex-jquery-1
// 1. set Listener for each filter
$("#pokemonTypeFilter").on('change', function(){
var filterPokemonType = this.value;
var filterPokemonAtk = $("#pokemonAtkFilter").val();
var filterPokemon = filterPokemonByTypeAndMinAtk(allPokemons, filterPokemonType, filterPokemonAtk);
renderPokemonList(filterPokemon);
});
$("#pokemonAtkFilter").on('keyup', function(){
var filterPokemonAtk = this.value;
@chaintng
chaintng / SearchHotelPriceRequest-request.xml
Last active June 17, 2016 02:04
2016-06-09T10:05:44.000Z
<?xml version="1.0" encoding="utf-8"?>
<Request>
<Source>
<RequestorID Client="15858" EMailAddress="XML@HOTELQUICKLY.COM" Password="2KS0JPZT5O"/>
<RequestorPreferences Currency="USD" Country="TW">
<RequestMode>SYNCHRONOUS</RequestMode>
</RequestorPreferences>
</Source>
<RequestDetails>
<SearchHotelPriceRequest>
@chaintng
chaintng / test.cs
Last active September 17, 2015 03:05
CreateUserUnique
public UserUnique CreateUserUniqueIfNotExisted(CustomerInsight_DBEntities refDb, Dictionary<int, UserUnique> existedUserUnique)
{
UserUnique tmpUu;
if (!existedUserUnique.TryGetValue(this.user_unique_id, out tmpUu))
{
tmpUu = UserUnique.CreateUserUniqueFromUui(this.user_unique_id, refDb);
existedUserUnique.Add(tmpUu.user_unique_id, tmpUu);
}
return tmpUu;
}