Skip to content

Instantly share code, notes, and snippets.

View ruimaranhao's full-sized avatar

Rui Maranhao ruimaranhao

View GitHub Profile
@ruimaranhao
ruimaranhao / crazy_simple_sorting.py
Created May 9, 2022 00:23
Crazy simple sorting
# Described in As found in https://arxiv.org/pdf/2110.01111.pdf.
import random
def generate_random_list(size, min_value=0, max_value=10):
return random.sample(range(min_value, max_value), size)
def simple_sort(lst):
for i in range(len(lst)):
for j in range(len(lst)):
if lst[i] < lst[j]:
@ruimaranhao
ruimaranhao / lanterna_and_fonts.java
Created November 23, 2021 10:38
How to use another font in Laterna.
public class Application {
public static void main(String[] args) throws IOException, FontFormatException, URISyntaxException {
new Application().run();
}
private void run() throws IOException, FontFormatException, URISyntaxException {
URL resource = getClass().getClassLoader().getResource("square.ttf");
File fontFile = new File(resource.toURI());
Font font = Font.createFont(Font.TRUETYPE_FONT, fontFile);
@ruimaranhao
ruimaranhao / AI4SE-CFP-BookChapters.md
Last active November 23, 2019 15:15
Call for Book Chapters: Artificial Intelligence Methods for Software Engineering

Call for Book Chapters:
Artificial Intelligence Methods for Software Engineering

Publisher: World Scientific, Singapore.

Editors

Scope and Purpose

Software is an integral part of our lives today. It is in the heart of a wide range of systems, from large management systems for health care or electricity power stations to small and local systems as smart home or even coffee machines. Modern software systems are highly complex and often have multiple dependencies on external parts such as other processes or services. This poses new challenges and exacerbate existing challenges in different aspects of Software Engineering (SE) including design, testing, debugging, and software lifec

@ruimaranhao
ruimaranhao / sign_commits.md
Last active January 17, 2019 22:55
Using gpg to sign git commits (MacOS)

Run the following to install the gpg agent:

brew upgrade gnupg  # This has a make step which takes a while
brew link --overwrite gnupg
brew install pinentry-mac
echo "pinentry-program /usr/local/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
killall gpg-agent

echo "test" | gpg --clearsign
@ruimaranhao
ruimaranhao / python-guide-ist.md
Last active February 7, 2021 03:34
A guide of best practices to developing in Python (meant for the first year students of the Instituto Superior Técnico, U.Lisboa).

A Guide of Best Practices for Python

A guide of best practices to developing in Python (meant for the first year students of the Instituto Superior Técnico, University of Lisbon). Do you want to have a hard-cover book on this, check this list out.

Inspired in Steve Sloria's gist.

In General

"Beautiful is better than ugly." - [PEP 20][]

@ruimaranhao
ruimaranhao / google_foobar_decrypt.py
Created September 25, 2018 09:29
Google's Foobar: Decrypt last message, once all puzzles are solved.
#!/usr/bin/python
import base64
MESSAGE = '''
CVIaWw4CFxIdT0FVUlIOXAgABkZCSEYMHRkFSwwGBwRJSFtPVRAaWggEHwQKT01PVRAPSAITBhJJ SFtPVRwHTR8EFggMBARIXlVOTw4JGwQYDQwKHAFODldBVRQABA4MGRANCUFBVRMPCgMGBgZODldB VRIPDgRIXlVOSAIOVUFUSEYYGxtICRA=
'''
KEY = 'rui.maranhao'
print(''.join(map(lambda x: chr(x[1] ^ ord(KEY[x[0] % len(KEY)])), enumerate(base64.b64decode(MESSAGE)))))
@ruimaranhao
ruimaranhao / bulkdelete.sh
Created February 1, 2018 22:21
Bulk delete of GitHub repositories
#!/bin/sh
set -x
# For it to work, you need to install
# -- jq, https://stedolan.github.io/jq/
# -- http, https://httpie.org/
if [ "$#" -ne 1 ]; then
echo "Usage: $0 AUTORIZATION_TOKEN" >&2
@ruimaranhao
ruimaranhao / large.py
Last active January 16, 2018 11:22
Read a large dataset
import multiprocessing
import time
import os
import mmap
from math import ceil
def size_and_chunks(file_name, processes):
sz = os.path.getsize(file_name)
return sz, sz / processes + 1

Keybase proof

I hereby claim:

  • I am ruimaranhao on github.
  • I am ruimaranhao (https://keybase.io/ruimaranhao) on keybase.
  • I have a public key ASA5IGnak26zARIq1V0Dc1fsdaUQh7v5lCoE_F_DMiyECgo

To claim this, I am signing this object:

@ruimaranhao
ruimaranhao / query.py
Last active March 29, 2016 22:27
Gremlin query
import asyncio
from aiogremlin import GremlinClient
QUERY="1+1"
loop = asyncio.get_event_loop()
gc = GremlinClient(loop=loop)
execute = gc.execute(QUERY)
result = loop.run_until_complete(execute)