Skip to content

Instantly share code, notes, and snippets.

@jmilet
jmilet / pydantic_mapping_fields.py
Last active June 5, 2022 08:34
Pydantic mapping fields
import os
from typing import Generic, Optional, TypeVar
from unittest.mock import patch
import pytest
from pydantic import BaseModel, BaseSettings, HttpUrl, ValidationError, error_wrappers, parse_obj_as
from pydantic.generics import GenericModel
class MySettings(BaseSettings):
@jmilet
jmilet / asyncio.py
Last active December 5, 2021 20:34
Python notes
import asyncio
async def espera():
await asyncio.sleep(2)
print("---finished---")
async def main():
try:
@jmilet
jmilet / MainTest.java
Created December 16, 2018 15:17
Java Stream examples
package jmi;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.partitioningBy;
import static java.util.stream.Collectors.toMap;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
@jmilet
jmilet / web_socket_client.cr
Created September 29, 2018 22:26
WebSocket client in Crystal
require "http"
def pick_word(words)
words[rand(words.size)]
end
def compose_message(me, text)
"#{me}: #{text}"
end
@jmilet
jmilet / bable_jsx.md
Last active July 1, 2018 08:03
React, Static and Bable basic configuration

Install Static HTTP server.

npm i -g node-static

Install Babel.

npm i --save-dev babel-preset-react
@jmilet
jmilet / func_implements_method.go
Created June 24, 2018 09:35
Function implements method in Go
package main
import (
"fmt"
)
type Test func()
func (t Test) Hello() {
t()

The server

package main

import (
	"flag"
	"log"
	"strconv"
	"time"
@jmilet
jmilet / websocket_binary_data_go.md
Last active May 2, 2024 21:36
Example of WebSocket binary data in Go

The server

package main

import (
	"bytes"
	"encoding/binary"
	"flag"
	"fmt"
@jmilet
jmilet / pocgob.go
Last active November 26, 2017 14:54
Basic Gob encoding/deconding
package main
import (
"bytes"
"encoding/gob"
"fmt"
)
type record struct {
Field1 string
@jmilet
jmilet / rabbitmq.txt
Last active November 26, 2017 12:55
Rabbitmq notes
# Start the server
./rabbitmq-server
# Stop the server
./rabbitmqctl stop
# Enable console plugin
./rabbitmq-plugins enable rabbitmq_management
# Create an admin user