This file contains hidden or 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
#!/usr/bin/env python3 | |
import sys | |
import numpy | |
import math | |
class ImplicitBinarySearchTree: | |
def __init__(self, size) -> None: |
This file contains hidden or 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 sys | |
# calculate multiplicative inverse of odd number mod 2^64 | |
# from https://groups.google.com/forum/m/#!msg/sci.crypt/UI-UMbUnYGk/hX2-wQVyE3oJ | |
def inverse(a): | |
x = a | |
assert (x * a & 0x7) == 1 | |
x += x - a * x * x | |
assert (x * a & 0x3F) == 1 | |
x += x - a * x * x |
This file contains hidden or 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 sys | |
# calculate multiplicative inverse of odd number mod 2^32 | |
# from https://groups.google.com/forum/m/#!msg/sci.crypt/UI-UMbUnYGk/hX2-wQVyE3oJ | |
def inverse(a): | |
x = a | |
assert (x * a & 0x7) == 1 | |
x += x - a * x * x | |
assert (x * a & 0x3F) == 1 | |
x += x - a * x * x |
This file contains hidden or 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.Arrays; | |
public class BLPIntHashSet { | |
private int[] arr; | |
private int size = 0; | |
public BLPIntHashSet(int maxEntries, double loadFactor) { | |
assert maxEntries > 0; |
This file contains hidden or 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
#!/usr/bin/env python | |
import sys | |
import logging | |
from speck import SpeckCipher | |
from runstats import Statistics | |
import numpy | |
from collections import Counter | |
This file contains hidden or 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
#!/usr/bin/env python | |
import sys | |
import logging | |
from speck import SpeckCipher | |
import numpy | |
from runstats import Statistics | |
from collections import Counter | |
This file contains hidden or 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 boto3 | |
def get_best_spot_price(instance_type, ec2_client=None): | |
client = ec2_client or boto3.client('ec2') | |
zones = [az['ZoneName'] for az in client.describe_availability_zones()['AvailabilityZones']] | |
best_price = None | |
best_zone = None | |
last_price = float('inf') | |
for zone in zones: | |
price = float(client.describe_spot_price_history( |
This file contains hidden or 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
#!/usr/bin/env python | |
import sys | |
import math | |
from bisect import * | |
from collections import defaultdict | |
from collections import Counter | |
"""Find rightmost value less than or equal to x""" |
This file contains hidden or 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
#!/usr/bin/env python | |
import sys | |
import math | |
import random | |
from collections import defaultdict | |
from collections import Counter | |
def consistent_hash(key, num_buckets): |
This file contains hidden or 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
for s in `cat servers.txt`; do | |
echo $s | |
ssh username@$s "sudo -u nobody bash -s" < cmds.sh | |
done |