Skip to content

Instantly share code, notes, and snippets.

View danielomiya's full-sized avatar
🏠
Working from home

Daniel Omiya danielomiya

🏠
Working from home
View GitHub Profile
@danielomiya
danielomiya / mysql-async-example.js
Created November 2, 2020 02:37
Simple example of wrapping mysql functionalities on Promises and calling them with async/await interfaces.
// conn.js
const mysql = require('mysql');
exports.openConnectionAsync = function openConnectionAsync() {
const conn = mysql.createConnection({
// ... config
});
return new Promise((resolve, reject) => {
@danielomiya
danielomiya / fib.c
Last active February 22, 2021 23:34
Recursive Fibonacci algorithm in C
#include <stdio.h>
#include <stdlib.h>
int fib(int n);
int main(int argc, char **argv) {
// compiling: gcc fib.c -o fib
// exec with: ./fib <n>
int i_num;
@danielomiya
danielomiya / Sudoku.java
Created April 26, 2021 04:33
Simple (and probably naive) validation of a Sudoku instance in Java.
import java.util.Arrays;
import java.util.stream.IntStream;
public final class Sudoku {
private static final int[][] SQUARE_CORNERS = new int[9][2];
static {
var lastIndex = 0;
for (var i = 0; i < 9; i += 3) {
for (var j = 0; j < 9; j += 3) {
@danielomiya
danielomiya / fibd.c
Created August 20, 2021 23:52
A Fibonacci sequence algorithm using Dynamic programming written in C.
#include <stdio.h>
#include <stdlib.h>
#define N 512
long long int CACHE[N] = { 0, 1 };
long long int fib(int n) {
if (n > 0 && !CACHE[n])
CACHE[n] = fib(n - 2) + fib(n - 1);
@danielomiya
danielomiya / client.py
Last active March 24, 2022 23:37
Server/client chat over TCP protocol on Python
import socket
import threading
import utils
class DMClient:
def __init__(
self, *, ip_addr: str = "127.0.0.1", port: int = 41995, buffer_size: int = 4192
) -> None:
self.ip_addr = ip_addr
@danielomiya
danielomiya / hashtable.cpp
Created November 2, 2021 21:37
Hash table implementation in C++
#include "hashtable.hpp"
#include <sstream>
HashTable::HashTable(int size) {
int i;
count = 0;
colisions = 0;
capacity = size;
array = new int *[capacity];
@danielomiya
danielomiya / a2_python_exerc.ipynb
Created February 23, 2023 21:27
A2_Python_Exerc.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@danielomiya
danielomiya / usage.py
Last active August 24, 2023 17:03
Flask wrapper for Cloud Functions
from http import HTTPStatus
import flask.typing as ft
from flask import Flask
from wrapper import as_cloudfunction
app = Flask(__name__)
@danielomiya
danielomiya / main.py
Created January 5, 2024 06:41
ASGI wrapper for Cloud Functions
"""
This is an example of how to wrap an ASGI application to run it as a Cloud
Function. Since I did it purely for academic purpose, I'm not quite sure of
how well it performs, but as someone simply trying to run my FastAPI code
inside the GCP serverless platform, it did great.
Also, credits to jordaneremieff/mangum, I got a lot of inspiration from their
work that has enabled running ASGI in AWS Lambda too.
"""
from __future__ import annotations
@danielomiya
danielomiya / main.py
Created January 16, 2024 04:42
Brazilian Portuguese custom error messages for Pydantic
from pydantic import ValidationError
from pydantic_core import ErrorDetails
CUSTOM_MESSAGES = {
"arguments_type": "Os argumentos devem ser uma tupla, lista ou um dicionário",
"assertion_error": "Falha na asserção, {error}",
"bool_parsing": "A entrada deve ser um booleano válido, não foi possível interpretar a entrada",
"bool_type": "A entrada deve ser um booleano válido",
"bytes_too_long": "Os dados devem ter no máximo {max_length} byte{expected_plural}",
"bytes_too_short": "Os dados devem ter pelo menos {min_length} byte{expected_plural}",