Skip to content

Instantly share code, notes, and snippets.

(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 / 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;
@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 ++++

Simplest java maven hello-world style project.

  1. create the directory structure

mkdir -p tutorial/src/main/java/hello then touch tutorial/src/main/java/hello/Main.java

  1. put in the java file tutorial/src/main/java/hello/Main.java
package hello;
public class Main {
@jstaursky
jstaursky / README.org
Last active September 7, 2022 20:04
Ghidra plugin development with emacs
  1. Need to create ghidra.jar and place into the lib directory.
  2. run below script to create the directory structure
  3. put the following contents in the src/main/java/MyProject.java file
    import ghidra.app.script.GhidraScript;
    
      public class MyProject extends GhidraScript {
    
      @Override
      public void run() throws Exception {
        

First make sure you install the dependencies

  • cmake
  • sudo apt install llvm-11 libclang-11-dev llvm-11 llvm-11-dev llvm-11-runtime llvm-11-tools

(may or may not be missing one, but they are all in the repositories, no need to manually install or build from src)

  1. git clone https://github.com/Andersbakken/rtags
  2. git submodule init
  3. git submodule update

and finally,


May only need sudo apt-get install libc6-dev-i386 gcc-multilib g++-multilib but if there is a version mismatch between this gcc and the x64 gcc then there will be issues. So check update-alternatives --config gcc and use that info to find gcc-<version>-multilib and then install it.

credit to https://askubuntu.com/questions/453681/gcc-wont-link-with-m32

// Credit: https://stackoverflow.com/questions/189725/what-is-a-trampoline-function
#include <stdio.h>
typedef struct _trampoline_data {
void(*callback)(struct _trampoline_data*);
void* parameters;
} trampoline_data;
void trampoline(trampoline_data* data) {
/*
* tl;dr: C program initialization, written in C!
*
* This applies to an executable dynamically linked with glibc.
* It is current as of glibc 2.26.
*
* A LOT of information has been omitted for simplicity; hell,
* some of it might be flat-out wrong (I wrote this after about
* 3 hours of experimenting with GDB). If you want to know EXACTLY
* what goes on under the covers, I advise you to read the
@jstaursky
jstaursky / c-program-with-no-glibc.org
Last active January 16, 2021 19:18
IA32, 32-bit, x86

C lang program w/out glibc

SYSV ABI requirement

See http://www.sco.com/developers/devspecs/abi386-4.pdf page 54 for diagram. This tells us 1 implementation of the stack layout of a SYSV compliant system (At the moment the only one I am aware of). However the spec. mentions this to only be a potiential implementation that is complient. To quote,

Argument strings, environment strings, and the auxiliary information appear in no specific order within the information block; the system makes no guarantees about their arrangement