Skip to content

Instantly share code, notes, and snippets.

#include "lib/error_functions.h"
#include "sockets/unix_socket.h"
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#define BACKLOG 5
extends Sprite
const VELOCITY: float = -1.5
var g_texture_width: float = 0
func _ready():
g_texture_width = texture.get_size().x * scale.x
func _process(delta: float) -> void:
position.x += VELOCITY
##### Protobuf Rules for Bazel
##### See https://github.com/bazelbuild/rules_proto
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rules_proto",
sha256 = "602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208",
strip_prefix = "rules_proto-97d8af4dc474595af3900dd85cb3a29ad28cc313",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
##### History stuff
# Avoid consecutive duplicates. See https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html
export HISTCONTROL=ignoredups
# When the shell exits, append to the history file instead of overwriting it
shopt -s histappend
# See https://unix.stackexchange.com/questions/18212/bash-history-ignoredups-and-erasedups-setting-conflict-with-common-history
export PROMPT_COMMAND="history -n; history -w; history -c; history -r; $PROMPT_COMMAND"
# Unlimited history size
export HISTFILESIZE=
export HISTSIZE=
set editing-mode vi
$if mode=vi
set keymap vi-command
Control-l: clear-screen
set keymap vi-insert
Control-l: clear-screen
$endif
##### STARTUP
echo "hello mlim"
RPS1="${${KEYMAP/vicmd/-- NORMAL --}/(main|viins)/-- INSERT --}"
RPS2=$RPS1
##### BINDINGS
bindkey "^R" history-incremental-search-backward
bindkey "\e[A" history-beginning-search-backward
bindkey "\e[B" history-beginning-search-forward
template <typename Function>
class RaiiThread {
public:
RaiiThread(Function &&f) : t_(f){};
~RaiiThread() {
std::cout << "Joining thread in ~RaiiThread" << std::endl;
t_.join();
};
class CustomScopedLock {
public:
CustomScopedLock(std::mutex &m) : m_(m) {
std::cout << "CustomScopedLock locking mutex..." << std::endl;
m_.lock();
std::cout << "CustomScopedLock has locked mutex!" << std::endl;
};
~CustomScopedLock() {
m_.unlock();
void lockMutexGood(bool shouldThrow) {
std::cout << "Locking mutex with scoped_lock..." << std::endl;
std::scoped_lock lock(globalMutex);
std::cout << "Mutex is locked!" << std::endl;
if (shouldThrow) {
std::cout << "Throwing exception" << std::endl;
throw 1;
}
}
void lockMutexBad(bool shouldThrow) {
std::cout << "Locking mutex manually..." << std::endl;
globalMutex.lock();
std::cout << "Mutex is locked!" << std::endl;
// Could also imagine this as an early return. If you use a plain old
// mutex, you have to remember to manually unlock before every return...
// and it's quite easy to forget.
if (shouldThrow) {
std::cout << "Throwing exception" << std::endl;