Skip to content

Instantly share code, notes, and snippets.

@jstaursky
jstaursky / line-centering.patch
Created May 3, 2021 12:03
emacs line centering
From 60532f6087d0f3cc20197da1790d2f5cec0ecbee Mon Sep 17 00:00:00 2001
From: Jesse Nazario <address@hidden>
Date: Sat, 31 Aug 2019 15:35:34 -0300
Subject: [PATCH] Center lines vertically with line-spacing-vertical-center
When using line-spacing, the new variable line-spacing-vertical-center
can be set to non-nil to center the line content vertically.
---
src/buffer.c | 13 +++++++++++++
src/buffer.h | 4 ++++
@jstaursky
jstaursky / sqrt-approx.c
Created May 25, 2021 00:22
square root approximation in C
// Note: sqrt -- approximate method for calculating the square root of a number.
double sqrt (double num)
{
double start = 0.0;
double epsilon = 0.1; // Accuracy granularity.
// Find nearest perfect square.
while ((num - start * start) > 0)
start += 1;
(use-package rtags
;; Note that if you recompile and create new compile_commands.json
;; you will need to run "rc -J ." for rtags to reflect the changes.
;; REMEMBER RTAGS DOES NOT WORK FOR PROJECTS INSIDE /tmp
:init
(add-hook 'c++-mode-hook #'rtags-start-process-unless-running)
(add-hook 'c-mode-hook #'rtags-start-process-unless-running)
(add-hook 'rtags-jump-hook 'evil-set-jump)
(setq rtags-completions-enabled t)
@jstaursky
jstaursky / move-semantics.cpp
Last active July 13, 2021 00:55
move semantics tutorial program from https://www.youtube.com/watch?v=ehMg6zvXuMY "The Cherno"
#include <iostream>
#include <cstring>
class String
{
public:
String () = default;
String (const char* string)
{
#include <iostream>
#include <vector>
#include <cstdint>
#include <fmt/format.h>
using namespace std;
int main(int argc, char *argv[])
{
uint8_t a = 0b1111'0000;
#include <iostream>
class Exhibit;
class Season;
class Zoo {
public:
Zoo();
virtual ~Zoo();
#include <iostream>
#include <memory>
using namespace std;
unique_ptr<int> factory(int i)
{
return unique_ptr<int>(new int(i));
}
(use-package evil
:config
(setq evil-jmp-list '(
xref-goto-xref xref-quit-and-goto-xref
evil-scroll-page-down evil-scroll-page-up
jump-to-register))
(dolist (jumper evil-jmp-list)
(evil-add-command-properties jumper :jump t))
)
;-----------------------------------------------------------
; LAYERS
(c-c++ :variables
c-c++-backend 'lsp-ccls
c-c++-adopt-subprojects t)
(lsp :variables
lsp-ui-peek-enable nil
lsp-use-lsp-ui nil
lsp-headerline-breadcrumb-enable nil
lsp-remap-xref-keybindings t

C++ bit shifting and how it is reflected in memory.

The number

int16_t num =  0b1000_0000_0000_0001

stored as:

Little Endian.

                    LSB         MSB