Skip to content

Instantly share code, notes, and snippets.

@annesteenbeek
annesteenbeek / bash_template.sh
Created December 15, 2020 13:57
Basic template for safe bash
#!/usr/bin/env bash
# source: https://betterdev.blog/minimal-safe-bash-script-template/
set -Eeuo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1
trap cleanup SIGINT SIGTERM ERR EXIT
usage() {
cat <<EOF
@annesteenbeek
annesteenbeek / cloudprint
Created April 11, 2017 23:42
Cloudprint init.d script
#!/bin/sh
### BEGIN INIT INFO
# Provides: cloudprint
# Required-Start: $local_fs $network $named $time $syslog
# Required-Stop: $local_fs $network $named $time $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Manage cloudprint deamon.
### END INIT INFO

Ubuntu Demon Creator

An automated way of creating services/demons for ubuntu 16.04. source: https://github.com/x13machine/ubuntu-demon-creator

I made this script for other automated bash scripts and to fix some bugs in this https://gist.github.com/naholyr/4275302.

Example

curl https://gist.githubusercontent.com/annesteenbeek/757b67163baea35735094fe93da14017/raw/df7a3a84eef139d445a99bd2cf7382797dc739c8/create-deamon.sh | sudo name="web" username="web" command="/home/web/start.sh" bash

Logs

/var/log/.log
@annesteenbeek
annesteenbeek / ROS init.d
Created February 13, 2017 15:19
A simple function for init.d to have a roslaunch run at startup at tty8 and tty9
start_ros () {
source /opt/ros/setup.sh
roscore <>/dev/tty8 2>/dev/tty8 & disown
until rostopic list ; do sleep 1; done
roslaunch YOUR_PACKAGE YOUR_LAUNCH_FILE.launch <> /dev/tty9 2>/dev/tty9 & disown
}
stop_ros () {
source /opt/ros/setup.sh
@annesteenbeek
annesteenbeek / latency.txt
Created January 31, 2017 19:57 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
#!/usr/bin/env python
import rospy
import mavros
from geometry_msgs.msg import PoseStamped
from mavros.msg import State
from mavros.srv import CommandBool, SetMode
# callback method for state sub
current_state = State()
@annesteenbeek
annesteenbeek / christmasSpirit.sh
Created January 5, 2016 14:12
small shell script to make sure the living room computer can only play christmas music
#!/bin/bash
while true
do
hasChristmasSpirit=false;
curSong=$(spotify-control getTitle)
declare -a whitelist=("christmas" "Lord" "Winter" "Xmas" "snow" "rudolph" "cold" "sleigh" "frosty");
## loop trough array of christmas spirit
@annesteenbeek
annesteenbeek / src2pdf.sh
Last active November 2, 2015 14:35
bash script to convert c++ source code to one Tex file
\documentclass[10pt,a4paper,twoside]{article}
\usepackage[a4paper,top=1in, bottom=1in, right=1in, left=1in]{geometry}
\usepackage{listings}
\usepackage{textcomp}
\usepackage[usenames,dvipsnames]{color} %% Allow color names
\definecolor{listinggray}{gray}{0.9}
\definecolor{lbcolor}{rgb}{0.95,0.95,0.95}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{dred}{rgb}{0.545,0,0}
\lstset{