Skip to content

Instantly share code, notes, and snippets.

View giuliano-macedo's full-sized avatar
🏠
Working from home

Giuliano Macedo giuliano-macedo

🏠
Working from home
  • Brazil
  • 15:27 (UTC -03:00)
View GitHub Profile
@giuliano-macedo
giuliano-macedo / ptytest.c
Last active September 5, 2018 16:03
Get ping realtime stdout and exit code in C using forkpty and execvp
#include <stdlib.h>
#include <stdio.h>
#include <pty.h>
#include <unistd.h>
#include <sys/wait.h>
int ptytest(){
int master;
pid_t pid;
pid = forkpty(&master, NULL, NULL, NULL);
@giuliano-macedo
giuliano-macedo / timer.c
Last active October 4, 2018 01:01
Not mt safe time.h nanoseconds timer function
#include<stdio.h>
#include <time.h>
struct timespec TIMER_START,TIMER_END;
long unsigned int timer(int f){
if(f){
clock_gettime(CLOCK_MONOTONIC_RAW, &TIMER_START);
return 0;
}
clock_gettime(CLOCK_MONOTONIC_RAW, &TIMER_END);
return (TIMER_END.tv_sec - TIMER_START.tv_sec) * 1e9 + (TIMER_END.tv_nsec - TIMER_START.tv_nsec);
from random import shuffle,choice
from itertools import repeat,chain
from functools import partial
from multiprocessing.pool import Pool
from argparse import ArgumentParser
def cheat(l,x):return True
def findIt1(l,x):
for i in range(50):
if l[i]==x:return True
return False
@giuliano-macedo
giuliano-macedo / ptytest.py
Last active August 19, 2019 13:43
Get ping realtime stdout and exit code in python using forkpty and execvp
import os
def bash_real_time(command):
pid,fd = os.forkpty()
if pid == 0:
os.execv('/bin/bash',['bash','-c',command])
exit(0)
while True:
try:
output = os.read(fd,1024).decode("utf-8").rstrip()
@giuliano-macedo
giuliano-macedo / paladins.py
Created December 30, 2019 22:43
helper script to get how many matches i have to do so i can get "Variety is the Spice of Life", "The Dedicated" and "The Insane" achievements by scraping paladins-tracker.de for the updated stats
import requests
from bs4 import BeautifulSoup as BS
from collections import namedtuple
from math import ceil
#config
lvs=[10,15,20]
mean_exp=32000
#----
table=[20000,60000,120000,200000,300000,420000,560000,720000,900000,1100000,1320000,1560000,1820000,2100000,2400000,2720000,3060000,3420000,3800000,4200000]
def fix_exp(exp,lvl):
@giuliano-macedo
giuliano-macedo / paladins_elo.py
Last active January 8, 2020 00:21
script to get players elo using paladins-tracker.de
import requests
from bs4 import BeautifulSoup as BS
from multiprocessing.dummy import Pool
def get_elo(nickname):
sess=requests.Session()
r=sess.get(f"https://paladins-tracker.de/search/player/{nickname}")
soup=BS(r.text,"html.parser")
link=soup.select_one(".player-meta.clearfix a")
if link==None:
@giuliano-macedo
giuliano-macedo / file_picker_form_field.dart
Last active June 1, 2020 19:16
A String path form field for the file_picker package.
import 'dart:io';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
class FilePickerFormField extends StatelessWidget {
final Function(String) validator;
final Function(String) onSaved;
final String labelText;
final String hintText;
@giuliano-macedo
giuliano-macedo / focus_node_mem_leak_test.dart
Created June 2, 2020 21:17
FocusScope.of(context).requestFocus(new MyFocusNode()) memleak test
import 'package:flutter/material.dart';
class MyFocusNode extends FocusNode {
MyFocusNode() : super() {
print("constructor");
}
@override
void dispose() {
print("dispose");
@giuliano-macedo
giuliano-macedo / tex.py
Last active August 16, 2020 18:42
Move tex files and compiles them in a temp dir, then move pdf file to root. Works on linux and requires nodemon and latexmk
#!/usr/bin/env python3
import argparse
import os
from tempfile import mkdtemp
parser=argparse.ArgumentParser()
parser.add_argument("input",type=str)
args=parser.parse_args()
pwd=os.path.realpath(os.getcwd())
@giuliano-macedo
giuliano-macedo / pandoc.py
Created August 28, 2020 23:59
pandoc + nodemon tool, need eisvogel template
#!/usr/bin/env python3
import argparse
import os
parser=argparse.ArgumentParser()
parser.add_argument("input",type=str)
args=parser.parse_args()
out_pdf=os.path.splitext(os.path.split(args.input)[-1])[0] +".pdf"