Skip to content

Instantly share code, notes, and snippets.

View sansarun's full-sized avatar
🥸

Sansarun Sukawongviwat sansarun

🥸
  • Agoda.com
  • Thailand
View GitHub Profile
function getLeafNodes(data) {
const leafNodes = [];
function traverse(node) {
if (node.children.length === 0) {
leafNodes.push(node.name);
} else {
for (let i = 0; i < node.children.length; i++) {
traverse(node.children[i]);
}
tumbons = [
{"province":"Bangkok", "aumper": "thonburi", "tumbon": "klong san" },
{"province":"Songkhla", "aumper": "hatyai", "tumbon": "swan neck" },
{"province":"Songkhla", "aumper": "hatyai", "tumbon": "something" }
]
selectable_provinces = ko.computed(function(){
return tumbons.map(e => e.province)
.distinct
tumbons = [
{"province":"Bangkok", "aumper": "thonburi", "tumbon": "klong san" },
{"province":"Songkhla", "aumper": "hatyai", "tumbon": "swan neck" },
{"province":"Songkhla", "aumper": "hatyai", "tumbon": "something" }
]
selectable_provinces = ko.computed(function(){
return tumbons.map(e => e.province)
.distinct
function getSensors(callback) {
var sensorList = [1, 2, 3];
setTimeout(function(){
callback(sensorList);
}, 3000);
}
function getSensorData(id, callback) {
setTimeout(function(){
callback("Sensor data for id:" + id);
def toDict(network):
result = {}
for c in network:
left, right = c.split("-")
if left in result:
result[left].append(right)
else:
result[left] = [right]
def golf(n):
while True:
n+=1
if not p(n)and str(n)[::-1]==str(n):return n
def p(n):
for i in range(2,n):
if n%i==0:return True
def min(*args, **kwargs):
key = kwargs.get("key", None)
iterable = args if len(args) > 1 else list(args[0])
minValue = iterable[0]
for e in iterable:
if (e if not key else key(e)) < (minValue if not key else key(minValue)):
minValue = e