Skip to content

Instantly share code, notes, and snippets.

test
@OhadRubin
OhadRubin / bash-cheatsheet.sh
Created May 5, 2017 02:40 — forked from LeCoupa/bash-cheatsheet.sh
Bash CheatSheet for UNIX Systems
#!/bin/bash
#####################################################
# Name: Bash CheatSheet for Mac OSX
#
# A little overlook of the Bash basics
#
# Usage:
#
# Author: J. Le Coupanec
# Date: 2014/11/04
@OhadRubin
OhadRubin / dist.py
Created December 17, 2020 12:58
print a colored distribution in cli
import matplotlib.cm as cm
from blessed import Terminal
def print_dist(prob,cmap=cm.gray):
term = Terminal()
for i_list in prob.tolist():
result =""
for i in i_list:
r,g,b,a = cmap(i,bytes=True)
@OhadRubin
OhadRubin / import_from_gist.py
Last active December 17, 2020 13:09 — forked from koji-kojiro/import_from_gist.py
[Python] import from Gist (works on python3)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def load_gist(gist_id):
"""translate Gist ID to URL"""
from json import load
from urllib.request import Request, urlopen
gist_api = urlopen("https://api.github.com/gists/" + gist_id)
@OhadRubin
OhadRubin / rewriting-interface.ipynb
Last active December 28, 2021 10:43
rewriting-interface.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@OhadRubin
OhadRubin / infer_features.py
Last active April 26, 2022 05:42
Infer huggingface datasets features from a single example
import datasets
from datasets import Value,Sequence,Features
def dict_generator(indict):
if isinstance(indict,str):
return datasets.Value("string")
elif isinstance(indict,int):
return datasets.Value("int32")
elif isinstance(indict,float):
return datasets.Value("float32")
elif isinstance(indict,list):
@OhadRubin
OhadRubin / killgpu.sh
Created April 23, 2022 05:02
Kill all the processes on a given GPU
# usage: `killgpu 0` will kill all the processes that are using gpu 0
killgpu (){
# https://forums.developer.nvidia.com/t/11-gb-of-gpu-ram-used-and-no-process-listed-by-nvidia-smi/44459/14
fuser -v /dev/nvidia$@ 2>&1 | grep python | grep -o -E " [0-9]+ " | xargs kill -9
}
analog_keys = {0:0, 1:0, 2:0, 3:0, 5:0}
import numpy as np
# START OF GAME LOOP
while running:
state = np.array(mycobot.get_angles())
if len(state)!=6:
state = np.zeros(6)
################################# CHECK PLAYER INPUT #################################
for event in pygame.event.get():
def hf_features_to_tf_features(features):
output_types= {}
output_shapes = {}
for x,y in features.items():
output_types[x] = getattr(tf.dtypes,y.dtype) if y.dtype!="list" else getattr(tf.dtypes,y.feature.dtype)
output_shapes[x] = [] if y.dtype!="list" else [None]
return dict(output_types=output_types,output_shapes=output_shapes)
@OhadRubin
OhadRubin / state_machine.py
Created January 8, 2023 16:40
Robot state machine
from transitions import Machine
import random
import numpy as np
class RobotModel(object):
# Define some states. Most of the time, narcoleptic superheroes are just like
# everyone else. Except for...
states = ['LeftY', 'LeftN', 'MidY', 'MidN', 'RightY','RightN']
def __init__(self):