Skip to content

Instantly share code, notes, and snippets.

(use-package hydra
:config
(defhydra hydra-zoom ()
"zoom"
("+" text-scale-increase "in")
("-" text-scale-decrease "out")
("0" (text-scale-adjust 0) "reset")
("q" nil "quit" :color red))
(defhydra hydra-move ()
int __attribute__((noinline)) test_saturate_add(int x, int y) {
int c = x + y;
if(c < x || c < y)
c = INT_MAX;
return c >= x && c >= y;
}
# Compiles to (with clang -O2)
@travitch
travitch / TypedDatalog.hs
Created August 17, 2020 15:22
Typed Datalog API
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wall #-}
import Control.Monad.ST ( RealWorld )
import Control.Monad ( guard )
@travitch
travitch / gist:5707b702f81751afd7a8fa33456f62ea
Created April 8, 2020 15:16
ARM disassembly and abstract view
ASM
0001010c <f1>:
1010c: e92d4800 push {fp, lr}
10110: e28db004 add fp, sp, #4
10114: e24dd008 sub sp, sp, #8
10118: e50b0008 str r0, [fp, #-8]
1011c: e51b3008 ldr r3, [fp, #-8]
10120: e2833001 add r3, r3, #1
10124: e1a00003 mov r0, r3
10128: ebffffea bl 100d8 <f2>
0001010c <f1>:
1010c: e92d4800 push {fp, lr}
10110: e28db004 add fp, sp, #4
10114: e24dd008 sub sp, sp, #8
10118: e50b0008 str r0, [fp, #-8]
1011c: e51b3008 ldr r3, [fp, #-8]
10120: e2833001 add r3, r3, #1
10124: e1a00003 mov r0, r3
10128: ebffffea bl 100d8 <f2>
1012c: e1a00000 nop ; (mov r0, r0)
Machine code
0001010c <f1>:
1010c: e92d4800 push {fp, lr}
10110: e28db004 add fp, sp, #4
10114: e24dd008 sub sp, sp, #8
10118: e50b0008 str r0, [fp, #-8]
1011c: e51b3008 ldr r3, [fp, #-8]
10120: e2833001 add r3, r3, #1
10124: e1a00003 mov r0, r3
(setq custom-file "~/.emacs.d/custom.el")
(load custom-file 'noerror)
;; Speed startup
(setq inhibit-startup-message t)
(setq inhibit-startup-buffer-menu t)
(defconst gui-font (if (eq system-type 'darwin)
"Source Code Pro-14"
"Source Code Pro-12"))
@travitch
travitch / .ghci
Created May 19, 2013 16:23
A handy .ghci configuration to replace many prelude functions with their more general forms
import Prelude hiding ( mapM, mapM_, catch, sequence, sequence_, foldl, foldr, concat, concatMap, and, or, any, all, elem, notElem, maximum, minimum, sum, product, foldl1, foldr1, (.), id)
import Control.Applicative
import Control.Arrow
import Control.Category
import Control.Exception
import Data.Foldable
import Data.Monoid
import Data.Traversable
:set prompt "> "
@travitch
travitch / gist:4709193
Created February 4, 2013 19:59
A pthread_create wrapper to launch any callable object in another thread.
#include <pthread.h>
struct ThreadBase
{
virtual ~ThreadBase(){}
virtual void* operator() () = 0;
};
template<typename CallableObject>
struct ThreadTask : public ThreadBase
@travitch
travitch / NotificationDaemon.hs
Created September 12, 2012 14:37
A freedesktop notification plugin for xmobar
{-# LANGUAGE OverloadedStrings, RankNTypes, KindSignatures, FlexibleContexts #-}
module Plugins.NotificationDaemon where
-- xmobar plugin API
import Plugins
import DBus.Bus
import DBus.Client
import DBus.Constants