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). |
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 */ |
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 |
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) | |
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) { |
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; | |
} |
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() |
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 |
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) |
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 }; | |
NewerOlder