Skip to content

Instantly share code, notes, and snippets.

View Gabrielcarvfer's full-sized avatar

Gabriel Ferreira Gabrielcarvfer

  • Brasília, Brasil
View GitHub Profile
@Gabrielcarvfer
Gabrielcarvfer / gist:eb227a44b009d90c07f50b7fa69a483c
Last active December 16, 2016 16:25
Condorcet-like alternative voting algorithm
#CSV file in https://docs.google.com/spreadsheets/d/1tnMbbfBJH2fnNcn73t1oypcq8HrmFJZcdaek0CWapxY/edit?usp=sharing
import csv
import random
voters = []
#load csv into array of arrays
with open('Voto ordenado - Respostas ao formulário 1.csv', 'r') as csvfile:
lineReader = csv.DictReader(csvfile, delimiter=',')
for row in lineReader:
@Gabrielcarvfer
Gabrielcarvfer / RecursiveTangent.py
Last active December 27, 2019 00:28
Recursive tangent demonstrated by Mathologer Burkard Polster in "Pi is IRRATIONAL: animation of a gorgeous proof" https://www.youtube.com/watch?v=Lk_QF_hcM8A
# You will need matplotlib to run this script (python -m pip install matplotlib)
#
# Recursive tangent demonstrated by Mathologer Burkard Polster in "Pi is IRRATIONAL: animation of a gorgeous proof"
# https://www.youtube.com/watch?v=Lk_QF_hcM8A
#
# tan(x) = x
# -----------------------------------------
# 1 - x^2
# -------------------------------------
# 3 - x^2
@Gabrielcarvfer
Gabrielcarvfer / ns3_global_include_to_relative_path.py
Last active September 30, 2019 23:52
Replaces #include "ns3/.h" with the relative paths to the header in question. An energy example might include a core header as #include "../../src/core/model/log.h". No reason to keep copying headers to the build folder as module headers can point to the originals.
SOURCE_PATH = "/mnt/dev/tools/source/NS3_relative_path/"
import os
import re
REGEX_MATCH_STRING = "#include*.*[<\"](?!sys|net|linux|netinet|unistd|errno)(.*.h)[>\"]"
"""
Test cases for regex matching of header files finishing with .h
Resulting header file without <> or "" is stored in re.search(REGEX_MATCH_STRING, string_to_match).group(1)
@Gabrielcarvfer
Gabrielcarvfer / ns3_compilation_performance_analyzer.py
Last active October 4, 2019 04:00
Little script to analyze how compilation time is spent during ns-3 build
"""
Configure gcc with -ftime-report and run "make -j1 1 > compile_targets.txt 2 > time_reports.txt"
Yes, -j1 will take a long time, but you really want these results to analyze your compilation time,
don't you?
"""
sample_compile_target = """
[ 12%] Building CXX object src/internet/CMakeFiles/ns3.30.1-internet-reldeb-obj.dir/model/icmpv4.cc.o
[ 12%] Building CXX object src/internet/CMakeFiles/ns3.30.1-internet-reldeb-obj.dir/model/icmpv4-l4-protocol.cc.o
"""
sample_time_report = """
@Gabrielcarvfer
Gabrielcarvfer / crawlerRottenTomatoesRiseOfSkywalker.py
Last active December 31, 2019 17:41
Rise of Skywalker rotten score
from selenium import webdriver
from scrapy import Spider
import time
#url = 'https://www.rottentomatoes.com/m/empire_strikes_back/reviews'
url = 'https://www.rottentomatoes.com/m/star_wars_the_rise_of_skywalker/reviews'
class SkywalkaSpider(Spider):
name = 'Skywalka'
allowed_domains = [url]
@Gabrielcarvfer
Gabrielcarvfer / fetch_cases_covid19_g1.py
Last active March 24, 2020 20:50
Fetch COVID-19 cases from the G1 website
import requests
import json
from datetime import datetime
import csv
import sys
#G1 source https://especiais.g1.globo.com/bemestar/coronavirus/mapa-coronavirus/
urlBrazilMap = "https://especiais.g1.globo.com/bemestar/coronavirus/mapa-coronavirus/data/brazil-map.json"
urlCases = "https://especiais.g1.globo.com/bemestar/coronavirus/mapa-coronavirus/data/brazil-cases.json"
@Gabrielcarvfer
Gabrielcarvfer / Latex2Markdown.py
Created August 31, 2021 23:20
Latex2Markdown.py script for alshedivat/al-folio theme
#!/usr/bin/python3
#
# Latex2Markdown
#
# Copyright (C) 2021 Gabriel Ferreira
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
#include <cmath>
#include <ns3/core-module.h>
#include <ns3/mobility-module.h>
#include <ns3/netanim-module.h>
using namespace ns3;
Vector polarToRectangular(double radius, double theta, double offsetx, double offsety)
{
@Gabrielcarvfer
Gabrielcarvfer / launch_sims.py
Last active July 6, 2022 22:18
launch_sims.py
import pickle
import os
import glob
import subprocess
import lzma
# Simulation_path is the CWD for the simulation (where results will be saved)
# Base_dir is the path to the directory containing the simulation program
# args is a list of arguments for the simulation program
def execute_simulation(simulation_path, base_dir, args):
@Gabrielcarvfer
Gabrielcarvfer / gitlab_navigation_userscript.js
Last active February 10, 2024 01:08
Make Gitlab navigation less bad
// ==UserScript==
// @name Make Gitlab navigation great again
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Trying to make the new Gitlab navigation feel less crappy
// @author Gabriel Ferreira
// @match https://gitlab.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=gitlab.com
// @grant none
// ==/UserScript==