Skip to content

Instantly share code, notes, and snippets.

View akkartik's full-sized avatar

Kartik Agaram akkartik

View GitHub Profile
@akkartik
akkartik / line.wart
Last active December 9, 2015 19:58
Bresenham's line-drawing algorithm in my toy language.
# doesn't handle vertical lines
def (line x0 y0 x1 y1)
collect+let steep ((> abs) y1-y0 x1-x0)
when steep
swap! x0 y0
swap! x1 y1
when (x0 > x1)
swap! x0 x1
swap! y0 y1
withs (deltax x1-x0
@akkartik
akkartik / ondemandhighlight.vim
Last active January 4, 2016 15:39
Highlight a word from inside vim. The color is chosen at random but persisted across sessions.
" Highlight a word from inside vim. The color is chosen at random but
" persisted across sessions.
" By Kartik Agaram -- http://akkartik.name -- [email protected]
" Experimenting with an idea by Evan Brooks: https://medium.com/p/3a6db2743a1e
" Discussion: http://www.reddit.com/r/programming/comments/1w76um/coding_in_color
let highlight_file = &viewdir."/highlights"
if !filereadable(highlight_file)
call system("mkdir -p ".&viewdir)
@akkartik
akkartik / pre-commit
Last active July 5, 2017 17:40
A git pre-commit hook to not permit commits with files larger than 100MB
#!/bin/sh
#
# Github won't permit files larger than 100MB (https://help.github.com/articles/working-with-large-files);
# don't wait to realize this until you try to push a bunch of commits.
git diff --cached --name-only |
while read file
do
if [ $(du -m $file |cut -f 1) -ge 100 ]
then
@akkartik
akkartik / kakoune.main.cc.patch
Last active December 20, 2016 17:50
cleaner shutdown for kakoune
diff --git a/src/main.cc b/src/main.cc
index 1af5493..c9a17c8 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -466,7 +466,8 @@ int run_client(StringView session, StringView init_cmds, UIType ui_type)
}
catch (disconnected& e)
{
- write_stderr(format("{}\ndisconnecting\n", e.what()));
+ if (!e.m_graceful)
@akkartik
akkartik / kakrc
Created December 22, 2016 04:09
My Kakoune config after 2 days of use
set global tabstop 2
set global indentwidth 2
# simulate Vim's autochdir
# since we're always running in client mode, since Kakoune doesn't do windows
# https://www.reddit.com/r/kakoune/comments/5dgpze/vimlike_autochdir_option
set global autochdir true
# simulate Vim's expandtab (poorly)
map global insert <tab> '<space><space>'
# simulate Vim's textwidth (but hardcoded to some value)
@akkartik
akkartik / ide
Created February 17, 2017 23:17
Structuring tmux usage
#!/bin/bash
#
# Use the regular 'tmux' command and '.tmux.conf' to run tmux for managing
# multiple sessions running long-running commands that you might need to
# detach from to go offline.
#
# Use this script to manage a special hard-coded session called 'ide' with
# editor and shell windows configured how you want it.
if tmux has-session -t ide >&/dev/null
@akkartik
akkartik / commandline.sh
Last active March 7, 2017 02:45
Script to emit lines prefixed by line length
cat *.cc |line-length.pl |sort -nr |less
@akkartik
akkartik / session.md
Last active July 25, 2018 04:02
SubX online help, 2018-07-20

$ subx

Welcome to SubX, a better way to program in machine code.
SubX uses a subset of the x86 instruction set. SubX programs will run without modification on Linux computers.
It provides a better experience and better error messages than programming directly in machine code, but you have to stick to the instructions it supports.

== Ways to invoke subx
- Run tests:
    subx test
- See this message:
@akkartik
akkartik / x.s
Created August 29, 2018 06:36
attempt to read argc
; attempt to read argc
;
; Build and run on 32-bit Linux:
; $ nasm -f elf x.s
; $ gcc -Wall -s -nostdlib x.o -o x
; $ ./x; echo $?
; 77 # expected: 1
; $ ./x abc; echo $?
; 73 # expected: 2
; $ ./x abc def; echo $?
(mac every (n . body)
`(thread
(while t
(sleep ,n)
,@body)))
;; try it out
; print a heartbeat every second
(every 1 (prn "."))