Skip to content

Instantly share code, notes, and snippets.

View FerdinaKusumah's full-sized avatar
🧑‍🚀
✌🏻

Ferdina Kusumah FerdinaKusumah

🧑‍🚀
✌🏻
View GitHub Profile
@FerdinaKusumah
FerdinaKusumah / class_attr_shared_object.py
Last active October 4, 2021 08:30
Class Attributes vs Instance Attributes
class FooBar:
class_attr: str = "foo bar"
def __init__(self, instance_attr: str):
self.instance_attr = instance_attr
if __name__ == "__main__":
@FerdinaKusumah
FerdinaKusumah / decorator.py
Created August 31, 2021 04:12
Python simple decorator
from functools import wraps
# Defining our custom decorator
def my_decorator(function):
@wraps(function)
def wrapper(a, b, c):
print("wrapper running!")
a += 1
b += 2
@FerdinaKusumah
FerdinaKusumah / flask-decorator.py
Created August 31, 2021 03:28
Flask builtin decorator
from flask import Flask
from flask import session, g
app = Flask(__name__)
app.secret_key = "iufh4857o3yfhh3"
@app.before_first_request
def before_first_request_func():
@FerdinaKusumah
FerdinaKusumah / app.py
Created August 22, 2021 03:40
Run Python from compile file
import base64
"""
step 1. python -m compileall app.py
step 2. run python with compiled files
python __pycache__/app.cpython-39.pyc
"""
def encode_message(msg):
@FerdinaKusumah
FerdinaKusumah / main.py
Created August 22, 2021 03:26
Python extract audio from mp4 video
# Python code to convert video to audio
import moviepy.editor as mp
def convert_mp4_to_mp3():
print("convert".center(20, "#"))
# Insert Local Video File Path
clip = mp.VideoFileClip("videoplayback.mp4")
# get duration file video in seconds
duration = clip.duration
@FerdinaKusumah
FerdinaKusumah / data_class.py
Last active July 29, 2021 05:51
Python data class
from dataclasses import dataclass
@dataclass()
class Hobby:
name: str = None
@dataclass()
class Student:
@FerdinaKusumah
FerdinaKusumah / python_nametuple.py
Last active July 29, 2021 05:52
Python Namedtuple
from collections import namedtuple
HobbyNameTuple = namedtuple("Hobby", ["name"])
StudentNameTuple = namedtuple("Student", ["name", "age", "hobby"])
if __name__ == "__main__":
h = HobbyNameTuple("swimming")
s = StudentNameTuple("John toer", 18, [h._asdict()])
result = s._asdict()
@FerdinaKusumah
FerdinaKusumah / go_struct.go
Last active July 29, 2021 04:45
Example Go Struct
package main
import (
"encoding/json"
"fmt"
)
type Hobby struct {
Name string `json:"name"`
}
@FerdinaKusumah
FerdinaKusumah / server.py
Created June 6, 2021 07:48
Python Simple Http Server
import json
import http.server
import socketserver
from typing import Tuple
from http import HTTPStatus
class Handler(http.server.SimpleHTTPRequestHandler):
def __init__(self, request: bytes, client_address: Tuple[str, int], server: socketserver.BaseServer):
@FerdinaKusumah
FerdinaKusumah / psql_useful_stat_queries.sql
Created December 21, 2020 04:28 — forked from anvk/psql_useful_stat_queries.sql
List of some useful Stat Queries for PSQL
--- PSQL queries which also duplicated from https://github.com/anvk/AwesomePSQLList/blob/master/README.md
--- some of them taken from https://www.slideshare.net/alexeylesovsky/deep-dive-into-postgresql-statistics-54594192
-- I'm not an expert in PSQL. Just a developer who is trying to accumulate useful stat queries which could potentially explain problems in your Postgres DB.
------------
-- Basics --
------------
-- Get indexes of tables