Skip to content

Instantly share code, notes, and snippets.

Avatar

Yasushi SHOJI yashi

View GitHub Profile
View gist:a26795aaa0132362f52575e50c98fb3f
$ cat a.c
#include <stdint.h>
uint16_t GetTimer(void);
void delay_us(uint16_t dt) {
uint16_t t1 = GetTimer();
uint16_t t2 = GetTimer() - t1;
while (t2 < dt) {
}
View gist:8ddd3efa283202eecf4ad4d31baf89a4
$ gdb -p $(pidof rviz2)
GNU gdb (Debian 12.1-4+b1) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
@yashi
yashi / CMakeLists.txt
Created January 5, 2023 13:34
Interface library with a generated header file
View CMakeLists.txt
cmake_minimum_required(VERSION 3.25)
project(test)
add_executable(hello hello.c)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/include/foo.h
# Ninja always implicitly creates target directories
COMMAND mkdir -p include/
COMMAND touch include/foo.h)
@yashi
yashi / pixelsize.c
Last active February 20, 2022 23:13
List pixel widths from front size 10 to 30 for given fonts
View pixelsize.c
#include <libgen.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#define DPI (96) /* device resolution */
void die(void)
{
printf("oops\n");
exit(1);
View time.dot
digraph G {
edge [weight=10]
TAI -> UTC [label="−∆AT"];
UTC -> UT1 [label="+∆UT1"]
UT1 -> TT [label="+∆T"]
TT -> TCG [label="linear"]
TCG -> TCB [label="4 D"]
TCB -> TDB [label="Linear"]
edge [weight=2]
@yashi
yashi / print_radius.c
Created January 15, 2022 07:13
Print radius with NASA NAIF SPICE
View print_radius.c
#include <stdio.h>
#include "SpiceUsr.h"
int main()
{
SpiceBoolean found;
SpiceInt nr;
SpiceDouble radii[3];
SpiceInt code;
SpiceChar name[] = "Io";
@yashi
yashi / gist:69f44b16fd00825a717724174b6e1a64
Created December 20, 2021 12:33
Emulate hashFiles() with sha256sum
View gist:69f44b16fd00825a717724174b6e1a64
To emulate `hashFiles()` in GitHub Actions with `sha256sum`, you can do
```shell
sha256sum file | cut -f1 -d ' ' | xxd -r -p | sha256sum
```
@yashi
yashi / rinngbuf.c
Last active November 4, 2021 18:10
View rinngbuf.c
#include <zephyr.h>
#include <sys/printk.h>
#include <sys/ring_buffer.h>
#define RING_BUF_SIZE 10
RING_BUF_ITEM_DECLARE_SIZE(ringbuf, RING_BUF_SIZE);
void dump(struct ring_buf *r, uint32_t ret)
{
printk("ret %3u, size %3u space %3u head %3u tail %3u\n",
View hello_led.c
#include <drivers/led.h>
void main(void)
{
const struct device *led = device_get_binding("SC LED");
while (1) {
led_on(led, 1);
k_msleep(1000);
led_off(led, 1);
@yashi
yashi / main.c
Created July 30, 2019 13:06
k_sched_unlock debug code
View main.c
#include <zephyr.h>
#define MY_STACK_SIZE 5000
K_THREAD_STACK_DEFINE(preempt_stack, MY_STACK_SIZE);
struct k_thread preempt_thread;
K_THREAD_STACK_DEFINE(coop_stack, MY_STACK_SIZE);
struct k_thread coop_thread;