Skip to content

Instantly share code, notes, and snippets.

View ppeeou's full-sized avatar
🎯
Focusing

hyunwoo jo ppeeou

🎯
Focusing
View GitHub Profile
@ppeeou
ppeeou / fetch.js
Last active February 18, 2019 14:05
fetch base script
const toParams = (body) => Object.keys(body).map(k => `${k}=${body[k]}`).join('&');
const errorJSON = (err) => ({ code: 500, data: err });
const resultJSON = (data) => data.status != 200 ? ({ code: 500, data: data }) : ({ code: 0, data: data.json() });
const baseFetch = (method: string) => {
method = method.toUpperCase();
return (url, { body = null, headers = null } = {}) => {
const options: RequestInit = { method };
@ppeeou
ppeeou / deepFindValue.js
Last active February 20, 2019 04:28
deep obj find value from key
function deepFindValue(obj, value) {
let results = [];
return function recur(obj, value) {
for (let key of Object.keys(obj)) {
if (typeof obj[key] === 'object') {
recur(obj[key], value)
} else if (obj[key] === value) {
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build_c",
"type": "shell",
"command": "gcc",
"args": [
@ppeeou
ppeeou / python_install.sh
Created March 28, 2019 09:15
python install
## ssl issue
apt-get install libssl-dev libncurses5-dev libsqlite3-dev libreadline-dev libtk8.5 libgdm-dev libdb4o-cil-dev libpcap-dev -y
## python version 3.6.8
wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz
tar -xf Python-3.6.8.tar.xz
/tmp/python-temp/Python-3.6.8/configure --enable-loadable-sqlite-extensions && \
make && make install
const curry = f => (a, ..._) => _.length > 0
? f(a, ..._)
: (..._) => f(a, ..._);
const isIter = iter => iter && iter[Symbol.iterator];
const toIter = iter => isIter(iter) ? iter[Symbol.iterator]() : function* () { }
const go1 = (a, f) => a instanceof Promise ? a.then(f) : f(a);
// const go2 = (acc, value, f) => value instanceof Promise
const promise1 = Promise.resolve(3);
const promise2 = new Promise((resolve, reject) => setTimeout(reject, 100, 'foo'));
const promises = [promise1, promise2];
Promise.allSettled(promises)
.then((results) => results.forEach((result) => console.log(result.status)));
// expected output:
// "fulfilled"
// "rejected"
Promise
.all([promise1,promise2,promise3])
.then(fn)
.catch(fn)
// -- simple
function isIterator(obj) {
return !!obj && !!obj[Symbol.iterator];
}
function allSettled(iterable) {
if (!isIterator(iterable)) {
throw new Error('[allSettled] first param must be iterable');
}
#include "stdio.h"
#include <stack>
#include <vector>
#include <iostream>
#include "string"
using namespace std;
struct Comparator
{
const fetch = require("node-fetch");
const fs = require("fs");
const url = "your url";
(async () => {
const response = await fetch(url);
const buffer = await response.buffer();