Skip to content

Instantly share code, notes, and snippets.

@m-radzikowski
m-radzikowski / script-template.sh
Last active April 8, 2024 03:04
Minimal safe Bash script template - see the article with full description: https://betterdev.blog/minimal-safe-bash-script-template/
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
@Som1Lse
Som1Lse / deps.md
Last active January 4, 2023 12:44
CMake dependency flexibility

What we want to do

Lets say we have a library that is part of a larger CMake project, and we want to seperate it out so it can be used in more projects. For the sake of convenience lets say it is already largely seperate from the parent project, i.e. in its own directory with a CMakeLists.txt, and referenced with add_subdirectory from the parent project.

In order to fully seperate it we need to:

  1. Make it buildable on its own. If it has depencies, it needs to use find_package itself to find them. If it has
@jdarpinian
jdarpinian / executable.c
Last active March 20, 2024 15:28
Add one line to your C/C++ source to make it executable.
///bin/true;COMPILER_OPTIONS="-g -Wall -Wextra --std=c99 -O1 -fsanitize=address,undefined";THIS_FILE="$(cd "$(dirname "$0")"; pwd -P)/$(basename "$0")";OUT_FILE="/tmp/build-cache/$THIS_FILE";mkdir -p "$(dirname "$OUT_FILE")";test "$THIS_FILE" -ot "$OUT_FILE" || $(which clang || which gcc) $COMPILER_OPTIONS -xc "$THIS_FILE" -o "$OUT_FILE" || exit;exec "$OUT_FILE" "$@"
#include <stdio.h>
int main() {
printf("Hello world!\n");
return 0;
}
@loganakamatsu
loganakamatsu / mute.sh
Created April 25, 2016 15:58
(Un)Mute OS X
# works nicely as an Automator 'run shell script' task
osascript -e 'set volume output muted true'
@VictorLaskin
VictorLaskin / NamedTuple.h
Last active April 14, 2023 18:56
Named tuple for C++
// Named tuple for C++
// Example code from http://vitiy.info/
// Written by Victor Laskin (victor.laskin@gmail.com)
// Parts of code were taken from: https://gist.github.com/Manu343726/081512c43814d098fe4b
namespace foonathan {
namespace string_id {
namespace detail
{
@imjasonh
imjasonh / markdown.css
Last active February 12, 2024 17:18
Render Markdown as unrendered Markdown (see http://jsbin.com/huwosomawo)
* {
font-size: 12pt;
font-family: monospace;
font-weight: normal;
font-style: normal;
text-decoration: none;
color: black;
cursor: default;
}
@RomkeVdMeulen
RomkeVdMeulen / up.sh
Created February 4, 2015 20:33
Script for automatically updating a number of projects in your workspace
#!/bin/bash
###############################################
# #
# Auto-update externals #
# #
# Will go into your workspace (~/workspace) #
# and `git pull` all projects listed in #
# .git-auto-pull, and will `svn up` all #
# projects listed in .svn-auto-up #
@matthiasbeyer
matthiasbeyer / select_remind_entry.sh
Last active March 8, 2017 18:17
remind entry to ics with selection
#!/bin/bash
#
# The following script is a ugly hack. But it works, so yeah \m/
#
# It uses awk, cut, head, tail, rem2ics and fzf (whereas this is only for the
# selection-process and could be replaced).
#
# Purpose:
#
@kachayev
kachayev / concurrency-in-go.md
Last active March 11, 2024 11:27
Channels Are Not Enough or Why Pipelining Is Not That Easy
// XPath CheatSheet
// To test XPath in your Chrome Debugger: $x('/html/body')
// http://www.jittuu.com/2012/2/14/Testing-XPath-In-Chrome/
// 0. XPath Examples.
// More: http://xpath.alephzarro.com/content/cheatsheet.html
'//hr[@class="edge" and position()=1]' // every first hr of 'edge' class