Skip to content

Instantly share code, notes, and snippets.

View chaintng's full-sized avatar

Chainarong Tangsurakit chaintng

View GitHub Profile
@chaintng
chaintng / review_structure.js
Last active December 11, 2018 09:00
review_structure.js
/*
TBD: AGODA, BOOKING => Should be ID or Enum string ?
TBD: Demographic (ALL_GUEST, BUSINESS_TRAVELLER) => ,
TBD: Score Category (OVERVIEW, CLEANLINESS) => Should be ID or Enum string ?
*/
{
reviews: {
displayingProviderId: AGODA,
@chaintng
chaintng / javascript.js
Created June 9, 2018 05:34
Encryption Decryption Javascript and Ruby
// IDEA FROM: https://stackoverflow.com/questions/33929712/crypto-in-nodejs-and-ruby
var crypto = require('crypto'),
algorithm = 'aes-256-cbc',
key = 'SOME_RANDOM_KEY_32_CHR_123456789', // 32 Characters
iv = "0000000000000000"; // 16 Characters
function encrypt(text){
var cipher = crypto.createCipheriv(algorithm,key,iv)
var crypted = cipher.update(text,'utf-8',"base64")
@chaintng
chaintng / line-webhook-event.json
Created February 26, 2018 06:32
line-webhook-event.json
{
"events": [
{
"replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
"type": "message",
"timestamp": 1462629479859,
"source": {
"type": "user",
"userId": "U206d25c2ea6bd87c17655609a1c37cb8"
},
@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>