Skip to content

Instantly share code, notes, and snippets.

View twopoint718's full-sized avatar
yo

Christopher Wilson twopoint718

yo
View GitHub Profile
@twopoint718
twopoint718 / program_02.rb
Created December 2, 2022 17:16
Advent of Code 2022 (parts 1 & 2) using matrix multiplication
#! /usr/bin/env ruby
require 'matrix'
class RPS
attr_accessor :scoring, :choices
def initialize
@scoring = Matrix[
[1, 0, 2],
@twopoint718
twopoint718 / jshell.el
Created August 16, 2022 15:10
Create a Java repl in Emacs
(define-derived-mode
jshell-mode comint-mode "JShell"
"An Emacs mode to interact with an inferior JShell
process. JShell is an interacive Java REPL included from JDK 9
and up."
:syntax-table java-mode-syntax-table
(setq comint-prompt-regexp (concat "^" (regexp-quote "jshell>")))
(make-comint-in-buffer "JShell" nil "jshell"))
#include <arpa/inet.h>
#include <assert.h>
#include <netinet/ip.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
int main() {
@twopoint718
twopoint718 / pom_editor.rb
Created July 5, 2022 19:04
Modify a `pom.xml` file in place so that when using `mvn package` it generates an executable jar file.
#!/usr/bin/env ruby
require 'nokogiri'
if ARGV.length == 0
puts "\nUSAGE:\n\tpom_editor.rb path/to/pom.xml\n\n"
end
filename = ARGV[0]
@doc = Nokogiri::XML.parse(File.read(filename))
@twopoint718
twopoint718 / util.el
Created April 18, 2022 17:34
A bunch of Emacs Lisp utilities.
(defun cjw-load-env-from-file (filename)
"Open a file of environment variable definitions like:
export FOO=bar
export BAZ=quux
and load them into the current environment using `setenv`"
(with-temp-buffer
(insert-file-contents filename)
(goto-char (point-min))
(while (re-search-forward "^export \\(.*\\)=\\(.*\\)$")
(apply 'setenv (list (match-string 1) (match-string 2))))))
@twopoint718
twopoint718 / main.c
Created March 16, 2022 22:07
Public/private struct members in C
#include <stdio.h>
/* #include "private.h" */
#include "public.h"
#include "s.h"
int main() {
struct s foo;
init_s(&foo);
printf("foo.public.a %d\n", foo.public.a);
#ifndef INCLUDE_TRACE_H
#define INCLUDE_TRACE_H
#include <stdio.h>
#include <stdint.h>
#define TRACE_STR(variable) do { fprintf(stderr, __FILE__":%d "#variable"=%s\n", __LINE__, variable); } while(0)
#define TRACE_INT(variable) do { fprintf(stderr, __FILE__":%d "#variable"=%d\n", __LINE__, variable); } while(0)
#define TRACE_PTR(variable) do { fprintf(stderr, __FILE__":%d "#variable"=0x%016lx\n", __LINE__, (uint64_t)(variable)); } while(0)
#define TRACE_SIZ(variable) do { fprintf(stderr, __FILE__":%d "#variable"=%zu\n", __LINE__, variable); } while(0)
#include <stdint.h>
#include <stdio.h>
#define BUFFER_SIZE 16
struct Buffer {
uint8_t data[BUFFER_SIZE];
uint8_t newest_index;
uint8_t oldest_index;
};
APP
Start*
app created -> NewPolicy
NewPolicy
submit to new business -> Policy
Policy
underwriting accept -> PolicyUnderwritten
underwriting reject -> PolicyClosed
PolicyUnderwritten
PolicyClosed
@twopoint718
twopoint718 / case_range.c
Created September 15, 2021 22:26
Cases in a switch statement can have ranges (there must be space around the `...` though). It is supported by GCC and Clang.
#include <stdio.h>
int
main(int argc, char **argv) {
int i = 0;
switch(i) {
case 0 ... 10:
printf("0 through 10\n");
break;
default: