Skip to content

Instantly share code, notes, and snippets.

Avatar
This is not a verified profile. Or is it?

Juan Lopes juanplopes

This is not a verified profile. Or is it?
View GitHub Profile
@juanplopes
juanplopes / gist:2295119
Created Apr 3, 2012
Quick Sort in python
View gist:2295119
def quicksort(V):
if len(V) <= 1:
return V
pivot = V[0]
equal = [x for x in V if x == pivot]
lesser = [x for x in V if x < pivot]
greater = [x for x in V if x > pivot]
return quicksort(lesser) + equal + quicksort(greater)
View gist:93e687e65dca1eeb44640c122dbdcb0d
(async () => {
var get = async(url, prop, dataless) => {
var data = (await (await fetch(url)).json());
if (!dataless) data = data.data;
var result = {};
data.forEach(element => {
result[element[prop]] = element;
});
return result;
View gist:558a46c06eb52aeff5c64a3861943105
def push(stack, el): stack+(el,);
def pop(stack): (stack:take(len(stack)-1), stack:get(len(stack)-1));
def memset(state, key, value): (state |> @filter({0}!=key)) + ((key, value),);
def memget(state, key): state |> last({1}):if({0}==key)# ?? 0;
def memadd(state, key, value): memset(state, key, memget(state, key)+value);
def findclosing(code, i):
(1, i+1):unfold(fun(count, i):
i >= len(code) or count == 0 ? null,
code:get(i) == '[' ? (i, (count+1, i+1)),
View 1579.cpp
#include <iostream>
using namespace std;
int X[200];
int trucks(int P, int maximum) {
int count = 0, current = 0;
for(int i=0; i<P; i++) {
if (X[i] > maximum) return 10000000;
if (current + X[i] > maximum) {
View LazyOutputStream.java
import java.io.IOException;
import java.io.OutputStream;
public class LazyOutputStream<T extends OutputStream> extends OutputStream {
private final Factory<T> factory;
private T stream;
public LazyOutputStream(Factory<T> factory) {
this.factory = factory;
}
@juanplopes
juanplopes / download.py
Created Oct 23, 2016
Downloads problems, best submissions and leaderboard from IEEExtreme 10 competition
View download.py
#!/usr/bin/env python2
from collections import defaultdict
import requests, json, zipfile
PREFIX = 'https://ieee.hackerrank.com/rest/contests/ieeextreme10'
USER='PUT USERNAME HERE'
PASS='PUT PASSWORD HERE'
EXT = {'python': 'py'}
View B.cpp
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <set>
using namespace std;
int T[][501] = {{0,1,1,2,2,2,3,3,3,3,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,
@juanplopes
juanplopes / mvngithub.py
Last active May 19, 2018
Python 2 script that asks github for new application token and saves it on .m2/settings.xml
View mvngithub.py
#!/usr/bin/env python
import httplib, getpass, base64, json, datetime, sys, socket, xml.etree.ElementTree as ET, os.path as path, os
NS = {'n':'http://maven.apache.org/SETTINGS/1.0.0'}
DEFAULT_REPO_KEY = 'your-repo-key'
def make_auth(username, password):
return base64.b64encode('{}:{}'.format(username, password))
def make_token(repokey, username, password, token2fa):
View cpf.py
def next_digit(value, base):
return value + str(sum(int(a)*b for a,b in zip(value, base))%11%10)
def make_valid(value, ap2, base):
return next_digit(next_digit(value, base), ap2+base)
def is_valid_cpf(cpf):
return make_valid(cpf[:9], [0], [1,2,3,4,5,6,7,8,9]) == cpf
def is_valid_cnpj(cnpj):
View test.py
def cnt(v):
x, y, z, u, w = bool(v&1), bool(v&2), bool(v&4), bool(v&8), bool(v&16)
return ("T" if
(x or y or w) and (z or not w or v) and (not z or not w or not v) and
len(set([x, y, w])) == 2 and
len(set([z, not w, v])) == 2 and
len(set([not z, not w, not v])) == 2
else "F")
You can’t perform that action at this time.