Skip to content

Instantly share code, notes, and snippets.

View always-hii's full-sized avatar

Always Hi always-hii

View GitHub Profile
#include <iostream>
#include <vector>
using namespace std;
int T; // 테스트 횟수
int L; // 막대 사이즈
int N; // 개미수
vector<int> positions; // 입력값들이 저장됨
vector<int> earlies; // 최소시간들이 저장됨
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int N; // 로프 개수
vector<int> rope; // 로프 한계 무게가 저장됨
bool compare_rope(int r1, int r2){
if(r1 > r2) return true;
@always-hii
always-hii / .cpp
Created May 15, 2018 11:57
Virtual Function Example in C++
#include <iostream>
using namespace std;
class Parent{
public:
virtual void print(){
cout<<"PARENT PRINT"<<endl;
}
void display(){
cout<<"PARENT DISPLAY"<<endl;
@always-hii
always-hii / .cpp
Created May 15, 2018 13:26
Volatile example
int main(){
volatile int impenetrable_variable=10;
for(int i=1; i<=3; i++){
// Every time the value is changed, it really changes the value in the main memory.
impenetrable_variable += i;
}
return 0;
}
@always-hii
always-hii / .py
Created May 16, 2018 02:19
Example of class method and static method in Python
class iPhone:
iphone_list = ["3g", "3gs", "4", "4S", "5", "5s"]
def __init__(self, model):
self.model = model
@classmethod
def from_year(cls, year):
return cls(iPhone.iphone_list[int(year) - 2008])
@always-hii
always-hii / .py
Last active May 17, 2018 02:48
Heap example
def parent_index(i):
return (i-1)//2
def lchild_index(i):
return i*2+1
def rchild_index(i):
return i*2+2
# max_min==1 means a max-heap. -1 means a min-heap.
# right means the rightmost index (not the length)
def recursive_heapify(list, i, right, max_min=1):
@always-hii
always-hii / .py
Created May 18, 2018 06:05
Quicksort example
def partition(list, l, r):
pivot = list[r]
i=l
j=r-1
while True:
while i<r and list[i]<=pivot:
i+=1
while j>l and list[j]>pivot:
j-=1
@always-hii
always-hii / flask_restapi_example.py
Last active May 2, 2020 07:14
Simple RestApi with Flask Example
"""
Other request methods to use in the Resource object:
- request.get_json()
- request.path
- request.base_url
- request.get_data()
- request.query_string
- request.args -> Kind of dict
"""
@always-hii
always-hii / mysql_foreign_keys_example.sql
Last active May 9, 2020 07:32
[Recipe of Code] MySQL Table Creation with Foreign Keys
-- Worked on MySQL 5.7
CREATE DATABASE IF NOT EXISTS rest;
CREATE TABLE IF NOT EXISTS rest.Users(
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(128) NOT NULL,
email VARCHAR(128) NOT NULL,
joined_datetime DATETIME DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS rest.Makers(
@always-hii
always-hii / restapi_get_makers.py
Last active May 9, 2020 07:38
[Recipe of Code] GET /makers
import pandas as pd
import pymysql
from flask import Flask, request
from flask_restful import Api, Resource
host = 'your_mysql_ip'
user = 'your_username'
password = 'your_password'
database = 'rest'