Skip to content

Instantly share code, notes, and snippets.

@kervel
kervel / CMakeLists.txt
Last active November 6, 2023 09:50
Small ros2 python using pybind11
# will need to be tweaked for your project
make_minimum_required(VERSION 3.5)
project(test_ros_pb11)
# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()
# Default to C++14
@kervel
kervel / example1.py
Created April 2, 2020 14:05
say my name
def say_my_name(name):
"""
Print the current widget value in short sentence
"""
print(f'My name is {name}')
widgets.interact(say_my_name, name=["Jim", "Emma", "Bond"]);
%matplotlib widget
import ipywidgets as widgets
import matplotlib.pyplot as plt
import numpy as np
def say_my_name(name):
"""
Print the current widget value in short sentence
"""
print(f'My name is {name}')
widgets.interact(say_my_name, name=["Jim", "Emma", "Bond"]);
def say_something(x):
"""
Print the current widget value in short sentence
"""
print(f'Widget says: {x}')
widgets.interact(say_something, x=[0, 1, 2, 3])
widgets.interact(say_something, x=(0, 10, 1))
widgets.interact(say_something, x=(0, 10, .5))
_ = widgets.interact(say_something, x=True)
def three(x, y, z):
return (x, y, z)
_ = widgets.interact(
three,
x=(0, 10, 1),
y=True,
z=['a', 'b', 'c']
)
_ = widgets.interact(
three,
x=(0, 10, 1),
y=True,
z=widgets.fixed('I am fixed')
)
@widgets.interact(x=(0, 10, 1))
def foo(x):
"""
Print the current widget value in short sentence
"""
print(f'Slider says: {x}')
# set up plot
fig, ax = plt.subplots(figsize=(6, 4))
ax.set_ylim([-4, 4])
ax.grid(True)
# generate x values
x = np.linspace(0, 2 * np.pi, 100)
def my_sine(x, w, amp, phi):
widgets.Textarea(
'\n'.join([w for w in dir(widgets) if not w.islower()]),
layout=widgets.Layout(height='200px')
)