Skip to content

Instantly share code, notes, and snippets.

View chaintng's full-sized avatar

Chainarong Tangsurakit chaintng

View GitHub Profile
@chaintng
chaintng / page2.js
Last active March 19, 2019 08:35
page2.js
// Step 1: Create rich menu, and retrieve richMenuId
client.createRichMenu({
size: { width: 2500, height: 1686 }, // Define size of rich menu
selected: true, // Always display
name: 'CryptoCurrency Page 2', // rich menu name
chatBarText: 'CryptoCurrency', // show to user
areas: [ // Area and action of each boundary
{
bounds: {
x: 0,
@chaintng
chaintng / rich-menu-api.js
Last active February 24, 2018 14:16
rich-menu-api.js
const config = require('../config.js')
const request = require('request-promise')
// When user send NEXT, Bot will call Rich Menu API for attaching Rich Menu Page 2 to that user
const nextPage = (userId) => {
return request({
method: 'POST',
uri: `https://api.line.me/v2/bot/user/${userId}/richmenu/${config.cryptoPage2RichMenuId}`,
headers: {
Authorization: `Bearer ${config.channelAccessToken}`
@chaintng
chaintng / handler.js
Created February 24, 2018 14:02
handler.js
// File: index.js
// Express listen POST /webhook call and call handler.webhook() function
const app = express();
app.post('/webhook', line.middleware(config), handler.webhook);
// File: handler/index.js
// Response {status: ok} to LINE call right away, but process the actual event in the background
const webhook = (req, res) => {
console.log("User id: " + req.body.events[0].source.userId)
Promise
QUERY PLAN
------------------------------------------------------------------------------------------------
Custom Scan (Citus Real-Time) (cost=0.00..0.00 rows=0 width=0)
Task Count: 32
Tasks Shown: All
-> Task
Node: host=10.140.0.4 port=5432 dbname=temp_db
-> Bitmap Heap Scan on record_102008 record (cost=10.74..31.37 rows=850 width=4)
Recheck Cond: (id < 3)
-> Bitmap Index Scan on record_pkey_102008 (cost=0.00..10.53 rows=850 width=0)
@chaintng
chaintng / dist_shard.sql
Last active December 17, 2017 15:12
dist_shard.sql
SELECT * from pg_dist_shard;
logicalrelid | shardid | shardstorage | shardminvalue | shardmaxvalue
---------------+---------+--------------+---------------+---------------
github_events | 102026 | t | 268435456 | 402653183
github_events | 102027 | t | 402653184 | 536870911
github_events | 102028 | t | 536870912 | 671088639
github_events | 102029 | t | 671088640 | 805306367
(4 rows)
@chaintng
chaintng / create_distributed_table.sql
Created December 17, 2017 15:10
create_distributed_table.sql
SELECT create_distributed_table('table', 'id');
@chaintng
chaintng / react-step-2-3.jsx
Created October 16, 2016 04:32
react-step-2-3.jsx
var Result = React.createClass({
propTypes: {
filterPokemon: React.PropTypes.array,
},
render: function() {
return (<div>
<div>--- Total Filter Pokemon: {this.props.filterPokemon.length} ---</div>
<ul>
{this.props.filterPokemon.map(function (item, i) {
return <li key={i}>{item.name} (Atk: {item.attack}, Def: {item.defense})</li>
@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>);
}
});