Skip to content

Instantly share code, notes, and snippets.

View adamnew123456's full-sized avatar

Chris Marchetti adamnew123456

  • Chapel Hill, NC
View GitHub Profile
@adamnew123456
adamnew123456 / diff.py
Last active March 4, 2024 08:03
An implementation of the Myers diff algorithm
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
@adamnew123456
adamnew123456 / arithmetic.py
Last active February 11, 2024 15:49
Pratt Parser For Arithmetic Expressions
"""
This implements a fairly simple expression language via a Pratt-style parser.
The language supports fairly standard floating point literals, such as:
5
1.09
.16
12e7
@adamnew123456
adamnew123456 / curses.js
Last active January 19, 2024 00:08
A Small Javascript Library For Emulating Curses
/**
* An implementation of an API similar to ncurses, but which instead runs on
* HTMl5 canvas.
*
* Specifically, this is designed to duplicate the following elements of ncurses:
*
* - Basic text printing
* - Colors
* - Handling window hierarchies, which respect their parents bounds (so that
* drawing doesn't occur outside of a window's boundaries). They have their own
@adamnew123456
adamnew123456 / pyc.py
Last active October 31, 2023 11:39
Using Inline C Code In Python Programs
"""
Inserts C code directly into Python files, which can then be dynamically linked
in and called via ctypes.
"""
import atexit
import ctypes
import os
import shlex
import sys
import tempfile
@adamnew123456
adamnew123456 / leaderkey.py
Last active September 18, 2021 19:01
A launcher based upon Spacemacs-like leaders
#!/usr/bin/python3
#
# Command Line
# ------------
# ``python3 leaderkey.py CONFIG-FIlE``
#
# Configuration format
# --------------------
#
# A leaderkey configuration is a normal Python file, with the following
@adamnew123456
adamnew123456 / sane_decoder.lua
Created March 13, 2021 21:20
A Wireshark dissector for the SANE network protocol
--[[
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
@adamnew123456
adamnew123456 / dispatchmethod.py
Last active May 15, 2020 15:37
dispatchmethod - Using functools.singledispatch For Methods
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
@adamnew123456
adamnew123456 / rpnjit-1.md
Created March 8, 2020 21:53
A Programmable RPN Calculator and JIT Compiler

A Basic RPN Calculator

We're going to start with a basic RPN interpreter and add function definitions to it. That will serve as a good starting point for adding on JIT compilation later. There are only going to be a few primitives to start with:

  • Integer constants
  • Arithmetic operators: +, -, *, /, %
  • Stack manipulation: swap, dup, drop
  • Display: print
@adamnew123456
adamnew123456 / checktask2.tcl
Last active February 28, 2020 02:15
Task Checker
package require Tk
# Checktask format:
#
# %Y-%m-%d,%H:%M:%S,message
if [string equal $tcl_platform(platform) "windows"] {
set checktask_file $env(APPDATA)/checktask.csv
} else {
set checktask_file $env(HOME)/.checktask.csv
}
@adamnew123456
adamnew123456 / dayclock.tcl
Created February 15, 2020 05:39
Day Clock
package require Tk
wm title . "Dayclock"
wm geometry . 200x225
canvas .clock
pack .clock
set expired_slice [.clock create arc 1 1 200 200 \
-start 225 -extent -270 -fill red]