Skip to content

Instantly share code, notes, and snippets.

@agam
agam / grouper.lisp
Created December 12, 2017 07:35
Count frequency of all symbols in a list
(defun group-reducer (groups elem)
(let ((last-elem (first (first groups)))
(last-count (second (first groups))))
(if (eql last-elem elem)
(cons (list last-elem (1+ last-count))
(rest groups))
(cons (list elem 1) groups))))
(defun countit (mylist)
(let ((sorted-mylist (sort mylist #'string-lessp :key #'(lambda (s) (symbol-name s)))))
@agam
agam / list-symbols.lisp
Created November 7, 2017 20:38
List symbols in current package
(defmacro dir-symbols ()
(let ((s (gensym)))
`(do-symbols (,s *package*)
(if (equal (symbol-package ,s) *package*)
(print ,s)))))
@agam
agam / big_integere_factorial.cc
Created October 24, 2017 17:49
Quick and dirty Big Integer for Factorial
#include <iostream>
#include <iomanip>
#include <vector>
#include <iterator>
#include <algorithm>
#include <type_traits>
using namespace std;
class BigInteger {
@agam
agam / simple_fold_sum.cc
Last active October 18, 2017 22:25
Another simple fold, this time for arithmetic expressions
#include <iostream>
using namespace std;
template <typename ...Args>
auto sum(Args... args) {
return (args + ...);
}
@agam
agam / simple_fold.cc
Created October 18, 2017 22:21
Try out a simple "fold" in C++
#include <iostream>
using namespace std;
template <typename ...Args>
auto all(Args... args) {
return (... && args);
}
@agam
agam / doc.lisp
Created June 22, 2017 20:15
Doc-looking up macro
(defmacro doc (f)
"Looks up the docstring for f.
E.g. (doc subseq)
is equivalent to calling
(documentation 'subseq 'function)"
`(documentation ',f 'function))
@agam
agam / jvm_tools.sh
Created September 29, 2016 17:52
Basic JVM introspection
## Reverse history
$ jstat -gcutil -t -h20 26752 1s
$ jstat -printcompilation -t -h20 26752 1s
$ jstat -compiler -t -h20 26752 1s
$ jstat -compiler -t -h20 26752 ls
$ jps -lvm
$ jstat --help
$ man jstat
$ jstack 26752
$ jcmd 26752 Thread.print
@agam
agam / quick-start.lisp
Last active November 2, 2016 22:32
Basic CL quick start in SBCL, using `rutilsx`
;; Step 1: Get the package
(ql:quickload "rutilsx")
;; Step 2: Use it
(use-package :rutilsx)
;; Unfortunately, there is a collision between RUTILS.MISC:VOID and SB-ALIEN:VOID,
;; so select one of the two restarts to continue ...
;; Step 3: Turn on the readtable (for convenient vector/hash literals)
(named-readtables:in-readtable rutilsx-readtable)
@agam
agam / cinnamon_lock.md
Last active September 14, 2016 17:36
Preventing double lock screen on Cinnamon in Ubuntu

Either skip the usual screen locking options, i.e. don't run gnome-screensaver etc.

If you must, disable the Cinnamon lock screen

$ gsettings set org.cinnamon.desktop.lockdown disable-lock-screen true

Otherwise, just skip ahead to using Ctrl-Alt-L for locking, which will only lock Cinnamon, and not Ubuntu

Edit: that doesn't help either, have to disable it explicitly.

@agam
agam / brew_linking.fish
Created September 1, 2016 22:38
Fix for `brew` symlinking on OS X
$ sudo chown -R (whoami):admin /usr/local