Skip to content

Instantly share code, notes, and snippets.

@anton0xf
anton0xf / gist:825659
Created February 14, 2011 09:29
emacs:rename-buffer-file
(defun rename-buffer-file (newname &optional ok-if-already-exists)
"rename visited file (buffer-file-name) to NEWNAME
and appropriately change buffer name (set-visited-file-name NEWNAME).
NEWNAME must be string.
Signals a `file-already-exists' error if a file NEWNAME already exists
unless optional third argument OK-IF-ALREADY-EXISTS is non-nil.
A number as third arg means request confirmation if NEWNAME already exists.
This is what happens in interactive use with M-x."
(interactive "FRename to: \np")
@anton0xf
anton0xf / TestList.java
Created June 19, 2012 18:09
Java Generics example.
import java.util.*;
class A{ public int i; }
class B extends A { public int j; }
public class TestList{
public static void main(String[] args){
A a = new A(); a.i = 1;
B b = new B(); b.i = 2; b.j = 3;
(progn (load "/usr/share/emacs/site-lisp/slime-archimag/swank-loader.lisp" :verbose t) (funcall (read-from-string "swank:start-server") "/tmp/slime.2380" :coding-system "utf-8-unix"))
This is SBCL 1.0.55, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
STYLE-WARNING: redefining ASDF::LISP-VERSION-STRING in DEFUN
#!/bin/sh
if [ -z "$2" ]; then
echo "usage: git-cp-in-history FILE DIR"
exit 1
fi
FNAME="$1"
DNAME="$2"
git filter-branch --tree-filter \
'if [ ! -d "'"$DNAME"'" ]; then mkdir "'"$DNAME"'"; fi; '\
'if [ -f "'"$FNAME"'" -a ! -h "'"$FNAME"'" ]; then cp "'"$FNAME"'" "'"$DNAME"'"; fi' -- --all
CL-USER> (defun filtered (hash &optional (filter-condition t))
(let ((res '()))
(maphash #'(lambda (k v)
(if (funcall filter-condition k v)
(push v res)))
hash)
res))
CL-USER> (defparameter *hash* (make-hash-table))
CL-USER> (dotimes (i 10) (setf (gethash i table) i))
CL-USER> (filtered *hash*
@anton0xf
anton0xf / stdin.txt
Created July 4, 2012 08:18 — forked from anonymous/stdin.txt
stdin
sed -n 's/[^<>]*<[ \t\n]*set[ \t\n]\+value='\''\([^'\'']*\)'\''[ \t\n]\+name='\''\([^'\'']*\)'\''[ \t\n]*\/>[^<>]*/\n\$\$"\1","\2"\n/pg' test | sed -n 's/^\$\$\(.*\)$/\1/p;'
abstract class Registry<H extends Handler>{
//абстрактный метод
void register(String s, H h);
//наш обобщенный код
void registerList(String s, List<H> hs){
for(H h: hs)
register(s,h);
}
}
<!-- =================================
target: load-ivy
this target is not necessary if you put ivy.jar in your ant lib directory
if you already have ivy 1.4 in your ant lib, you can simply remove this
target
================================= -->
<target name="load-ivy">
<!-- try to load ivy here from home ivy dir, in case the user has not already dropped
it into ant's lib dir (note that the latter copy will always take precedence).
We will not fail as long as ivy home lib dir exists (it may be empty) and
@anton0xf
anton0xf / inv-opt
Created November 13, 2012 13:01
inverted optional
(defun test(&rest ab)
(let ((len (length ab))
(a 2) b)
(cond ((< 2 len) (error "Too many args"))
((= 2 len)
(setf a (first ab)
b (second ab)))
((= 1 len) (setf b (first ab)))
(t (error "B arg is mandatory")))
(format t "a: ~W, b: ~W~%" a b)))
CL-USER> (ql:quickload "cl-json")
To load "cl-json":
Load 1 ASDF system:
cl-json
; Loading "cl-json"
("cl-json")
CL-USER> (use-package :json)
T
CL-USER> (encode-json-to-string '((:a (:b . "test"))))