Skip to content

Instantly share code, notes, and snippets.

View pwener's full-sized avatar
📖
Learning...

Phelipe Wener pwener

📖
Learning...
View GitHub Profile
@pwener
pwener / bad_code.go
Last active March 20, 2023 05:22
Code to invert words and numbers escaping special characters
package main
import (
"fmt"
"regexp"
"strings"
)
func invert(str string) string {
result := ""
#!/bin/python3
import math
import os
import random
import re
import sys
def findNextDivByFive(number):
count = 0
@pwener
pwener / lz4-decompress.kt
Last active May 24, 2021 14:17
Descompression using lz4 (frame compressed) in kotlin
fun uncompressLz4File(path: String): ByteArray {
var f: File = File(path)
val megabytes = 1024 * 1024;
val inputStream = ByteArrayInputStream(f.readBytes())
var lz4In: LZ4FrameInputStream = LZ4FrameInputStream(inputStream)
var frameIndex: Int = 0
var decompressed: ByteArray = ByteArray( megabytes * 50) // should be greater than file descompressed size
var filled: Int = 0;
while (true) {
@pwener
pwener / lz4-compress-file.go
Last active March 16, 2021 21:06
Compress file content and save in another file
package main
import (
"bytes"
"encoding/binary"
"io"
"io/ioutil"
"log"
"os"
@pwener
pwener / randomString.ts
Last active February 3, 2021 21:31
Random string with lenght n (Typescript/Javascript)
function randomString(range: number) {
let str = '';
for(let index=0; index <= range; index++) {
str += Math.random().toString(36).replace(/\./g,'');
}
return str;
}
@pwener
pwener / di.py
Created October 14, 2020 16:11
DI e repo
class ICorporationGovernanceRepo(Protocol):
def persist(self, dto: CreateCorporationGovernanceDto) -> CorporationGovernance:
...
def update(
self, id_: int, dto: UpdateCorporationGovernanceDto
) -> Optional[CorporationGovernance]:
...
# TODO: This should be fetch_by_corporation
const getDate = (): string => {
const now = new Date();
const day = now.getDate();
const month = `0${now.getMonth() + 1}`.slice(-2);
const year = now.getFullYear();
return `${day}-${month}-${year}`;
};
@pwener
pwener / client.js
Last active September 27, 2019 17:16
Trying to connect to zrp socket
const net = require('net');
const client = new net.Socket();
client.connect(80, 'zrp-challenge-socket.herokuapp.com', () => {
console.log('Connected...');
});
client.on('ocurrence', (data) => console.log('Received: ' + data));
@pwener
pwener / path.js
Created September 27, 2019 02:07
Get changes of pathname using history in React functional
const [pathname, setPathname] = useState(history.location.pathname);
useEffect(() => {
history.listen((location) => {
setPathname(location.pathname);
});
}, []);
# Not tested yet!
# This algorithm uses vector rotation.
# I will soon do a project explaining!
  • crie um arquivo map[k] com 4 pontos de uma reta
  • declare uma var size do fractal a ser desenhado
  • declare uma var k = 1, i = 0
  • enquanto i < size