Skip to content

Instantly share code, notes, and snippets.

View hannibal1296's full-sized avatar

Haneul Bae hannibal1296

  • NAVER Corp
  • South Korea
View GitHub Profile
@hannibal1296
hannibal1296 / restapi_get_users_uid_cars.py
Created May 9, 2020 07:34
[Recipe of Code] GET /users/<uid>/cars
View restapi_get_users_uid_cars.py
import pandas as pd
import pymysql
import requests
from flask import Flask, request
from flask_restful import Api, Resource
host = 'your_mysql_ip'
user = 'your_username'
password = 'your_password'
@hannibal1296
hannibal1296 / restapi_get_makers_mid.py
Last active May 9, 2020 07:45
[Recipe of Code] GET /makers/{mid}
View restapi_get_makers_mid.py
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'
@hannibal1296
hannibal1296 / restapi_get_makers.py
Last active May 9, 2020 07:38
[Recipe of Code] GET /makers
View restapi_get_makers.py
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'
@hannibal1296
hannibal1296 / mysql_foreign_keys_example.sql
Last active May 9, 2020 07:32
[Recipe of Code] MySQL Table Creation with Foreign Keys
View mysql_foreign_keys_example.sql
-- 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(
@hannibal1296
hannibal1296 / flask_restapi_example.py
Last active May 2, 2020 07:14
Simple RestApi with Flask Example
View flask_restapi_example.py
"""
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
"""
@hannibal1296
hannibal1296 / .py
Created May 18, 2018 06:05
Quicksort example
View .py
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
@hannibal1296
hannibal1296 / .py
Last active May 17, 2018 02:48
Heap example
View .py
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):
@hannibal1296
hannibal1296 / .py
Created May 16, 2018 02:19
Example of class method and static method in Python
View .py
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])
@hannibal1296
hannibal1296 / .cpp
Created May 15, 2018 13:26
Volatile example
View .cpp
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;
}
@hannibal1296
hannibal1296 / .cpp
Created May 15, 2018 11:57
Virtual Function Example in C++
View .cpp
#include <iostream>
using namespace std;
class Parent{
public:
virtual void print(){
cout<<"PARENT PRINT"<<endl;
}
void display(){
cout<<"PARENT DISPLAY"<<endl;