Instantly share code, notes, and snippets.

🌲
Is that a Segment Tree problem?

# Juan Lopes juanplopes

🌲
Is that a Segment Tree problem?
Last active July 14, 2023 17:35
RSA by example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 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).
Created March 22, 2022 12:36
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 #!/bin/bash set -e mkdir -p ~/Library/KeyBindings cat > ~/Library/KeyBindings/DefaultKeyBinding.dict << EOF { /* Remap Home / End keys to be correct */ "\UF729" = "moveToBeginningOfLine:"; /* Home */ "\UF72B" = "moveToEndOfLine:"; /* End */ "\$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */ "\$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* Shift + End */
Last active September 28, 2021 16:37
simple dfa in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 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
Created September 30, 2014 13:13
Simple scheduling algorithm in python (2nd version)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import heapq def schedule(tasks): heap = [] def offer(begin, end): while heap and heap[0] <= begin: heapq.heappop(heap) heapq.heappush(heap, end) return len(heap)
Created July 5, 2015 01:22
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 #include "stdio.h" typedef struct tree tree; struct tree{ int value; tree *left ; tree *right; }; tree *tree_first_bigger(tree *t) {
Last active February 4, 2021 16:52
CharSequence with timeout (useful to timeout a backtracking regex)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import java.util.Objects; public class TimeoutString implements CharSequence { private final CharSequence child; private final long target; private TimeoutString(CharSequence child, long target) { this.child = child; this.target = target; }
Created May 9, 2020 17:45
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # -*- coding: utf-8 -*- from collections import deque from functools import reduce def rex(pattern): tokens = deque(pattern) def walk(chars): while tokens and tokens[0] in chars: yield tokens.popleft()
Created March 24, 2020 13:11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 Crescimento por dia: 36.84% 2020-02-26 0 1 2020-02-27 0 1 2020-02-28 1 1 2020-02-29 1 2 2020-03-01 2 2 2020-03-02 2 2 2020-03-03 3 2 2020-03-04 5 4 2020-03-05 7 4
Last active March 22, 2020 16:02
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import datetime, numpy as np first_day = datetime.date(2020, 2, 26) y = np.array([1, 1, 1, 2, 2, 2, 2, 4, 4, 13, 13, 20, 25, 31, 38, 52, 151, 151, 162, 200, 321, 372, 621, 793]) x = np.arange(1, len(y)+1) curve = np.exp(np.polyfit(x, np.log(y), 1)) #y = b*a^x #log(y) = xlog(a)+log(b)
Created February 18, 2020 14:57
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 var performanceReport = function(perf) { if (perf == null) return console.log("No storage query was run yet!"); var perc = n => isNaN(n) ? 0 : Math.round(n*1000.0)/10; var expectedEvents = 0, actualEvents = 0, cacheReads=0, cacheWrites=0, metrics = {}; var count = {'init': 0, 'read': 0, 'flow': 0, 'misc': 0, 'filter': 0 }; var time = {'init': 0, 'read': 0, 'flow': 0, 'misc': 0, 'filter': 0 };