Skip to content

Instantly share code, notes, and snippets.

Avatar
😈
Radical Candor

Dale Seo DaleSeo

😈
Radical Candor
View GitHub Profile
@DaleSeo
DaleSeo / index.js
Created Apr 28, 2019
GraphQL Apollo Server
View index.js
const { ApolloServer, gql } = require('apollo-server');
const typeDefs = gql`
type Query {
ping: String
}
`;
const resolvers = {
Query: {
View fetchAuthorName_async_await.js
async function fetchAuthorName(postId) {
const postResponse = await fetch(`https://jsonplaceholder.typicode.com/posts/${postId}`);
const post = await postResponse.json();
const userId = post.userId;
const userResponse = await fetch(`https://jsonplaceholder.typicode.com/users/${userId}`)
const user = await userResponse.json();
return user.name;
}
fetchAuthorName(1).then(name => console.log("name:", name));
View 1_findUser.js
findUser(1)
.then(function(user) {
console.log("user:", user);
});
function findUser(id) {
return new Promise(function (resolve) {
setTimeout(function() {
console.log("waited 0.1 sec.");
const user = {
View asyncFindUser.js
function findUser(id) {
let user;
setTimeout(function() {
console.log("waited 0.1 sec.");
user = {
id: id,
name: "User" + id,
email: id + "@test.com"
};
}, 100);
@DaleSeo
DaleSeo / unique-substrings-in-wraparound-string.py
Created Dec 7, 2016
unique-substrings-in-wraparound-string
View unique-substrings-in-wraparound-string.py
class Solution(object):
def findSubstringInWraproundString(self, p):
dic = {}
for i, v in enumerate(p):
if i > 0 and ((ord(p[i]) - ord(p[i - 1])) % 26) == 1:
subs += 1
else:
subs = 1
dic[v] = max(subs, dic.get(v, 0))
return sum(dic.values())
View access.js
// 배열의 원소에 개별 접근하기
var fruit1 = fruits[0];
var fruit2 = fruits[1];
var fruit3 = fruits[2];
var fruit3 = fruits[3]; // undefined
View company_investment.py
"""
https://www.acmicpc.net/problem/2662
"""
def maximize(total, cnt, table):
dp = [[0] * (cnt + 1) for _ in range(total + 1)]
investments = [[0] * (cnt + 1) for _ in range(total + 1)]
for company in range(1, cnt + 1):