Skip to content

Instantly share code, notes, and snippets.

View ehudthelefthand's full-sized avatar

Pongneng ehudthelefthand

  • Pair-Co Software, ODDS
  • Chiang Mai
View GitHub Profile
@ehudthelefthand
ehudthelefthand / assert_throw.js
Last active May 16, 2016 07:16
Try to assert.throws on the function that check the condition before throwing error
// How do I assert.throws this function?
describe("Test assert.throws", function() {
it("should throw when called with isThrow == true", function() {
function willThrow(isThrow) {
if (isThrow) {
throw new Error("Some error");
}
}
@ehudthelefthand
ehudthelefthand / promise-sequence.js
Last active March 14, 2017 06:37
Demonstrate the promise parallel and sequence
function load_data() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve([1,2,3,4,5,6]);
}, 3000);
});
}
function process_data_step1(item) {
return new Promise((resolve, reject) => {
@ehudthelefthand
ehudthelefthand / retries.js
Last active June 8, 2017 15:24
Promise Retries Pattern
// NOTE
// npm install q
// Before proceeded
const Q = require("q");
let MAX_FAIL = 1;
function talkingToDatabase() {
return Q.Promise((resolve, reject) => {
@ehudthelefthand
ehudthelefthand / bs.c
Created June 18, 2017 06:36
Simple Binary Search
#include <stdio.h>
#include <stdlib.h>
// or int *a
int binary_search(int a[], int x, int left, int right) {
if (left > right) return -1;
int mid = (left + right) / 2;
if (a[mid] == x) return mid;
if (x < a[mid]) return search(a, x, left, mid - 1);
else return search(a, x, mid + 1, right);
}
@ehudthelefthand
ehudthelefthand / api_process.js
Created October 5, 2017 07:11
Code snippet to demonstrate the way the validator and preparing object should work
// 1
// requestBody.fundCode
IndividualApiValidator.validate(requestBody)
.then((requestBody) => {
// requestBody.fundId
// call save();
});
// 3
let domain = covertToDomain(requestBody)
class DB {
execute(sql, callback) {
// .. execute SQL
setTimeout(() => {
callback({ id: 1, name: 'Pongeng' })
}, 2000)
}
}
class DBPromise {
@ehudthelefthand
ehudthelefthand / strange.js
Created June 27, 2018 07:28
JS - The stranger things
([]+![])[+!+[]+!+[]+!+[]][([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]]+([][([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]]+([]+[][+!+[]])[+!+[]]+([]+![])[+!+[]+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+!![])[+!+[]]+([]+!![])[+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]]+([]+!![])[+!+[]]][([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]]+([]+[][+!+[]])[+!+[]]+([]+![])[+!+[]+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+!![])[+!+[]]+([]+!![])[+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]]+([]+!![])[+!+[]]](([]+!![])[+!+[]]+([]+[][+[]])[+!+[]+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+!![])[+!+[]+!+[]]+([]+!![])[+!+[]]+([]+[][+!+[]])[+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+(+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[])[([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[
package main
import (
"fmt"
"golang.org/x/tour/tree"
)
// Walk walks the tree t sending all values
// from the tree to the channel ch.

Workshop React JS @ CMU CAMT

[ Project Name ]

  • Giphy

[ Requirements ]

  1. Manage Account
@ehudthelefthand
ehudthelefthand / review_math_for_working_programmer.md
Last active February 8, 2020 16:33
Collection of Review for class "Math for working programmer"

Reviewed By Jerapong Nampetch

Math for working programmers - public 3

เป็นคลาสที่เปิดหูเปิดตาผมได้เยอะมาก ผมได้รู้ที่มาที่ไปของการ “programming” ที่เราทำๆกันอยู่ทุกเมื่อเชื่อวัน ว่ามันคืออะไร มีที่มายังไง ทำไมพอเราได้โจทย์ขึ้นมา เราก็เริ่มทำกันอย่างนี้

What Why เป็นสิ่งสำคัญที่เราควรรู้ ทั้งหมดมันมาเชื่อมโยงกันได้อย่างไร คลาสนี้บอกกระจ่างเลย

จนมาถึง “อนาคต” (ที่มาถึงแล้ว) ของ programming อย่าง fp คลาสนี้บอกที่มาที่ไปของมัน และสอนให้เราคิดแก้ปัญหา “ในทางของมันจริงๆ” ไม่ใช่การคิดแบบเดิมแค่ใช้ syntax ใหม่ จุดนี้คลิกผมมาก ทำให้ผมกลับมาย้อนคิดใหม่ว่า “กุใช้มันถูกรึยังวะ” รวมถึงการตอบคำถาม ปรับ mindset วิธีคิดต่อ fp ไปอย่างสิ้นเชิง