Skip to content

Instantly share code, notes, and snippets.

View pedropedruzzi's full-sized avatar

Pedro Pedruzzi pedropedruzzi

View GitHub Profile
@pedropedruzzi
pedropedruzzi / crack-djbx31a.py
Last active August 29, 2015 14:02
Meet-in-the-middle crack for DJBX31A hash function
# http://events.ccc.de/congress/2011/Fahrplan/attachments/2007_28C3_Effective_DoS_on_web_application_platforms.pdf
import random
# djbx31a backward
def rev(h, s):
for c in reversed(s):
h = ((h - ord(c)) * 3186588639) & 0xffffffff;
return h
class Digraph:
def __init__(self):
self.d = {}
def has(self, x, y):
return x in self.d and y in self.d[x]
def _safe_get(self, x):
return self.d.setdefault(x, set())
#include <iostream>
using Age = unsigned int;
using Name = std::string;
using Country = std::string;
template <class PersonSubtype>
class Person
{
#include <iostream>
#define STRONG_TYPEDEF(original, newtype) \
class newtype : public original \
{ \
using original::original; \
};
using Age = unsigned int;
@pedropedruzzi
pedropedruzzi / watertanks.py
Created April 25, 2017 04:29
Water Tanks Problem
# gets list of key walls from a sorted list of walls
def _keywalls(walls):
prevheight = pos = highest = 0
keywalls = []
for pos, height in walls:
if height > highest: # raises globally
highest = height
elif height >= prevheight: # raises locally
while keywalls[-1][1] < height:
keywalls.pop() # discard recent walls until we see with one higher than height (always occurs)
@pedropedruzzi
pedropedruzzi / rnaa.rs
Created May 29, 2017 13:16
Experimenting with Rust
use std::cmp;
// Note: this is a suboptimal solution made to exercise the Rust language.
// Approach A: using a struct/class
// Gotcha: Had to add lifetime specifier to store a reference to the byte array of a external
// string inside my struct.
struct Rnaa<'a> {
chain: &'a [u8], // 'a is to get rid of "missing lifetype specifier"
@pedropedruzzi
pedropedruzzi / download-na-busca-do-legendas-tv.user.js
Last active April 7, 2021 03:10
Greasemonkey script que permite download de legendas a partir dos resultados de busca do site legendas.tv. Instruções: 1. Instale o Greasemonkey (Firefox) ou Tampermonkey (Chrome ou Firefox). 2. Clique em https://gist.githubusercontent.com/pedropedruzzi/f25a010f8a787352575d8f312433979b/raw/download-na-busca-do-legendas-tv.user.js
// ==UserScript==
// @name Download na busca do legendas.tv
// @namespace http://tampermonkey.net/
// @version 0.4
// @description Permite download de legendas a partir dos resultados de busca do site legendas.tv
// @author Pedro Pedruzzi
// @match http://legendas.tv/busca/*
// @match https://legendas.tv/busca/*
// @grant none
// @downloadURL https://gist.githubusercontent.com/pedropedruzzi/f25a010f8a787352575d8f312433979b/raw/download-na-busca-do-legendas-tv.user.js
@pedropedruzzi
pedropedruzzi / array.py
Created April 12, 2018 22:17
Array Problem
import random
def solve(a):
n = len(a)
# get inside the loop by moving n steps (better approach is part 1 of Floyds's below)
x = 0
for i in range(n):
x = a[x]
# measure the period
period = 1
@pedropedruzzi
pedropedruzzi / QuickSort.java
Created March 5, 2019 15:49
Iterative QuickSort
package algorithms;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Random;
public class QuickSort {
private static class Interval {
int low;
@pedropedruzzi
pedropedruzzi / MiBACT-Antenati-direct-image-links.user.js
Last active September 18, 2020 12:31
Greasemonkey script that replaces links on image galleries with direct (faster) image links on MiBACT Antenati website. Instructions: 1. Install Greasemonkey (Firefox) or Tampermonkey (Chrome/Firefox). 2. Click https://gist.github.com/pedrox/365fd278393b651a9e6780e7866c469d/raw/MiBACT-Antenati-direct-image-links.user.js