Skip to content

Instantly share code, notes, and snippets.

💭
It's probably about Segment Trees

Juan Lopes juanplopes

💭
It's probably about Segment Trees
Block or report user

Report or block juanplopes

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@juanplopes
juanplopes / rsa.py
Last active Oct 19, 2019
RSA by example
View rsa.py
from random import randint
#----Step 1
# First, choose two random primes.
# In real world, they should be really big primes (hundreds of digits).
p, q = 41, 47
#----Step 2
# From them we have n=p*q and phi(n)=(p-1)*(q-1).
@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)
@juanplopes
juanplopes / dfa.py
Last active Aug 13, 2019
simple dfa in python
View dfa.py
class Automaton:
def __init__(self, nstates):
self.transitions = [{} for i in range(nstates)]
self.accept_states = [False] * nstates
def register(self, source_state, char, target_state):
self.transitions[source_state][char] = target_state
def register_accept(self, state):
self.accept_states[state] = True
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):
You can’t perform that action at this time.