Skip to content

Instantly share code, notes, and snippets.

sudo apt install docker.io
# add user to docker group for non-sudo access
sudo groupadd docker # add docker group
sudo usermod -aG docker $USER # add your user to the docker group.
newgrp docker # activate the changes to groups. Run this command on each new terminal session
docker ps # verify that user can run Docker without sudo
def model_builder(hp):
if TASK == "r":
loss_fn = "mean_absolute_error"
elif TASK == "c":
if OUTPUT_NODES == 1:
loss_fn = tf.keras.losses.BinaryCrossentropy(from_logits=True)
else:
loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
if TASK == "r":
def string_input_processor(inputs):
if not inputs:
return
vocabularies = defaultdict(set)
for batch, _ in get_dataset(batch_size=BATCH_SIZE):
for col_name in inputs.keys():
for st in np.array(batch[col_name]).astype("str"):
vocabularies[col_name].add(st.lower().strip())
def numerical_input_processor(inputs):
if not inputs:
return
concat = None
if len(inputs.values()) > 1:
concat = tf.keras.layers.Concatenate()(list(inputs.values()))
norm = tf.keras.layers.experimental.preprocessing.Normalization()
@zahash
zahash / movie_magnet.py
Last active April 27, 2020 06:25
get torrent magnet links of movies
#! /usr/bin/env python3
"""
Install these packages before running the script
beautifulsoup4==4.9.0
bs4==0.0.1
certifi==2020.4.5.1
chardet==3.0.4
idna==2.9
def search(grid_dict):
# try to solve the board
grid_dict = run_episode(grid_dict)
if grid_dict is False:
# it means the current configuration of the board is unsolvable
# this happens when any of the boxes have no possible value to fix
def run_episode(grid_dict):
stuck = False
while not stuck:
# Check how many boxes have a fixed value
solved_values_before = len([box for box in grid_dict.keys() if len(grid_dict[box]) == 1])
# Use the Eliminate Strategy
grid_dict = eliminate(grid_dict)
# Use the Only Choice Strategy
def only_choice(grid_dict):
for unit in unit_list:
for num in '123456789':
num_places = [box for box in unit if num in grid_dict[box]]
if len(num_places) == 1:
grid_dict[num_places[0]] = num
return grid_dict
def eliminate(grid_dict):
for k,v in grid_dict.items():
if len(v) != 1: # if the box needs elimination
peers = peer_dict[k] # get all the peers
peer_values = set([grid_dict[p] for p in peers if len(grid_dict[p]) == 1])
grid_dict[k] = ''.join(set(grid_dict[k]) - peer_values)
return grid_dict
start = '53..7....6..195....98....6.8...6...34..8.3..17...2...6.6....28....419..5....8..79'
rows = 'ABCDEFGHI'
cols = '123456789'
boxes = cartesian_product(rows, cols)
row_units = [cartesian_product(r, cols) for r in rows]
col_units = [cartesian_product(rows, c) for c in cols]
box_units = [cartesian_product(r,c)
for r in ['ABC', 'DEF', 'GHI']