Skip to content

Instantly share code, notes, and snippets.

View rcabreu's full-sized avatar

Roberto Abreu rcabreu

View GitHub Profile

Keybase proof

I hereby claim:

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

To claim this, I am signing this object:

FROM ubuntu:18.04
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get -y update
RUN apt-get -qq -y install curl wget unzip zip openjdk-11-jdk
RUN apt-get -y install nano
ENV JAVA_HOME /usr/lib/jvm/java-11-openjdk-amd64/
RUN export JAVA_HOME
RUN curl -s "https://get.sdkman.io" | bash
@rcabreu
rcabreu / post-dumper-ws.js
Created October 9, 2019 18:13
Only reacts to POST requests. Prints request body in stdout.
const http = require('http')
const server = http.createServer(function(request, response) {
console.dir(request.param)
if (request.method == 'POST') {
console.log('POST')
var body = ''
request.on('data', function(data) {
body += data
namespace FastFFT {
typedef long double Double;
typedef long long Long;
typedef vector<int> VI;
struct point {
Double x, y;
point(Double x = 0, Double y = 0) : x(x), y(y) { }
point conjugate() const { return point(x, -y); }
};
point operator+(const point &a, const point &b) { return {a.x + b.x, a.y + b.y}; }
@rcabreu
rcabreu / rename_inputs.sh
Last active February 19, 2022 04:33
Add extension to extensionless files
find . -type f -regex '\.[^.]*$' -exec mv {} {}.in \;
@rcabreu
rcabreu / erathostenes.cpp
Created October 15, 2015 20:05
Sieve of Erathostenes
vi primes;
bool prime[1000100];
void generatePrimes(int n) {
for (int i = 2; i * i <= n; i++)
if (prime[i])
for (int j = i * i; j <= n; j += i)
prime[j] = false;
int cnt = 0;
for (int i = 2; i <= n; i++)
@rcabreu
rcabreu / lca.cpp
Created October 2, 2015 03:08
Lowest Common Ancestor, O(N log N) pre-processing, O(log N) query time.
#define MAXN 1005
#define MAXE 1005
#define MAXL 25
struct Node {
int p, h;
};
Node V[MAXN];
vi E[MAXE];
vector<int> kmp(string s, string w) {
vector<int> T(w.size() + 1, 0), matches;
T[0] = -1, T[1] = 0; // default values, will never change
int pos = 0;
for (int i = 2; i <= w.size(); ++i) {
if (w[i - 1] == w[pos]) { // keep matching, and if we ever failing at position i - 1, we've matched pos characters
++pos;
T[i] = pos;
}
@rcabreu
rcabreu / tctemplate.cpp
Created October 12, 2014 17:59
TopCoder Arena Code Template
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define GCD(a,b) __gcd(a, b)
#define mp make_pair
#define DEBUG(x) cout << x << "\n"
#define ALL(x) x.begin(), x.end()
@rcabreu
rcabreu / TarjanSCC.cpp
Created October 6, 2014 22:30
Tarjan's Strongly Connected Components
#define MAX_V 123456
struct Node {
int id;
int ind, lowlink;
int SCC;
bool visited;
};
int N, M;
Node V[MAX_V];