Skip to content

Instantly share code, notes, and snippets.

View akkartik's full-sized avatar

Kartik Agaram akkartik

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 080qq.test
Created October 29, 2012 06:27
Porting fallintothis's quasiquote implementation
map (fn((input expected)) (test "" :valueof qq_expand.input :should be expected))
pair:list 1 ''1 # force paren
'(x)
''(x)
'(,x)
'(list x)
'(,x ,y)
'(list x y)
@akkartik
akkartik / 099cargobot.wart
Created May 19, 2012 17:52
William Tozier's Cargo-Bot error heuristic
;; Draft solution of William Tozier's Cargo-Bot problem:
;; http://www.vagueinnovation.com/pragmatic_gp/more-on-moving-blocks
;;
;; Built in a private lisp dialect I've been working on:
;; http://github.com/akkartik/wart#readme
;; Requires gcc and linux/macos.
;;
;; Instructions to run tests:
;; $ git clone http://github.com/akkartik/wart.git
;; $ cd wart
@akkartik
akkartik / time_magazine_covers.py
Created November 26, 2011 12:57
Generate URLs for the pages containing the covers of all editions of Time Magazine
from BeautifulSoup import BeautifulSoup
from urllib2 import urlopen
url = '/time/magazine/current'
while 1:
url='http://www.time.com'+url
soup = BeautifulSoup(urlopen(url))
print url, '--', soup.find('time').renderContents()
url = soup.find(text='Previous Issue').parent['href']
@akkartik
akkartik / 090chessboard.wart
Last active September 27, 2015 15:27
Simple chessboard app. Nothing funky, just putting wart through its paces. (Compare with python version at http://gist.github.com/1218667)
# Requirements: g++
# $ git clone http://github.com/akkartik/wart.git
# $ cd wart
# $ git checkout b5fb9cbccb
# $ wget --no-check-certificate https://raw.github.com/gist/1291243/080chessboard.wart
# $ wart
# Use the 'm' function to make a move. P-K4 is m.5254, etc. m.-1 is undo.
# type chessboard
# Uppercase is white, lowercase is black
@akkartik
akkartik / gist:1218667
Created September 15, 2011 06:27
Nakamura - Fierro Baquero, Kings vs Queens Tournament, 2011
from sys import stdout, stdin
from string import atoi
import copy
p = 'p'
r = 'r'
n = 'n'
b = 'b'
q = 'q'
k = 'k'