Skip to content

Instantly share code, notes, and snippets.

View rbrito's full-sized avatar
☹️
Having (YET another) kidney stone surgery in a few days...

Rogério Brito rbrito

☹️
Having (YET another) kidney stone surgery in a few days...
View GitHub Profile
@rbrito
rbrito / gist:8e17e6bbc93bc2999d92b979d080c9c3
Created July 7, 2020 00:22 — forked from bazub/gist:3877971
Grayscale/Binary images using PIL
im=Image.open("1.jpg")
#im=im.rotate(1)
im.save("e.jpg")
im2=im.convert("L")
im2.save("b.jpg")
threshold = 100
im = im2.point(lambda p: p > threshold and 255)
im.save("d.jpg")
img="d.jpg"
result = tesseract.ProcessPagesWrapper(img,api)
@rbrito
rbrito / mathology.html
Created March 30, 2020 23:16 — forked from rosinality/mathology.html
Very simple latex sketchpad
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Mathology</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
}
@rbrito
rbrito / galois.c
Created May 23, 2019 03:06 — forked from meagtan/galois.c
Quick implementation of Galois fields
/*
* The following is an implementation of the finite field GF(2^8) as bit vectors of length 8, where the nth bit represents the
* coefficient of the nth power of the generator in each element, and the generator satisfies the minimal polynomial
* x^8 + x^4 + x ^3 + x^2 + 1 in the prime field Z_2, in which addition is equivalent to XOR and multiplication to AND.
* The elements of GF(2^8) thus represent polynomials of degree < 8 in the generator x. Addition in this field is simply
* bitwise XOR, but multiplication requires the elimination of powers of x <= 8.
*/
#include <stdio.h>
#include <stdint.h>
@rbrito
rbrito / gimp-autosave.py
Created December 7, 2018 01:27 — forked from Iunius118/gimp_autosave.py
Auto save plug-in for GIMP [2.8, 2.9]
#!/usr/bin/env python
# Original (by yahvuu): http://www.gimpusers.com/forums/gimp-developer/11718-autosave-plugin
import tempfile, os
from time import *
from gimpfu import *
def autosave(image, layer):
backupInterval = 10 * 60
@rbrito
rbrito / 0.README.md
Created July 20, 2018 22:45 — forked from agentcooper/0.README.md
Telegram chat backup/export

How to use

  1. Login to https://web.telegram.org
  2. Copy-paste contents of telegram-scripts.js into JS console
  3. Run showContacts() to get the list of contacts with ids
  4. Run saveChat(userId) where userId is the id from step 3

Process can take a while, check console for progress. Occasionall FLOOD_WAIT errors are expected. Once done, browser will download the JSON file.

Motivation

@rbrito
rbrito / spectre.c
Created January 5, 2018 03:58 — forked from ErikAugust/spectre.c
Spectre example code
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#ifdef _MSC_VER
#include <intrin.h> /* for rdtscp and clflush */
#pragma optimize("gt",on)
#else
#include <x86intrin.h> /* for rdtscp and clflush */
#endif
@rbrito
rbrito / remove-duplicate-subs
Created June 24, 2017 16:03 — forked from otsaloma/remove-duplicate-subs
Remove duplicate subtitles with aeidon
#!/usr/bin/env python3
import aeidon, sys, time
if len(sys.argv) < 2:
print("Usage: {} SUBTITLE_FILE...".format(__file__))
raise SystemExit(1)
for fname in sys.argv[1:]:
print("{}:".format(fname))
project = aeidon.Project()
project.open_main(fname, "utf_8")
before = len(project.subtitles)
@rbrito
rbrito / README.md
Last active November 2, 2015 16:18 — forked from hubgit/README.md
Remove metadata from a PDF file, using exiftool and qpdf. Note that embedded objects may still contain metadata.

Anonymising PDFs

PDF metadata

Metadata in PDF files can be stored in at least two places:

  • the Info Dictionary, a limited set of key/value pairs
  • XMP packets, which contain RDF statements expressed as XML

PDF files

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import string
import re
INPUT_FILE = 'balanced_smileystxt.txt'
input = open(INPUT_FILE, 'r')

Disclaimer: I have no idea if this are indeed the correct answers. I just solved the exercises like this. I think that they are right though.

I have added my own code to this gist. It is ugly as hell, just like you can expect from code created in a contest like this.

Beautiful Strings

Difficulty: easy

It is simple to see that a greedy solution is good enough.