Skip to content

Instantly share code, notes, and snippets.

import itertools
class Cons:
def __init__(self, head, tail_fn):
self.head = head
self._tail_fn = tail_fn
self._tail = None
def tail(self):
@anton0xf
anton0xf / fib-memo.rkt
Created September 25, 2022 13:03
memoized fibonacci example on Racket
#lang racket
(define (fib n)
(if (< n 2) n
(+ (fib (- n 1))
(fib (- n 2)))))
(time (fib 35))
; cpu time: 5219 real time: 5138 gc time: 747
; => 9227465
(require memo)
@anton0xf
anton0xf / InsertBeforeTest.java
Created January 31, 2022 10:57
Insert value into LinkedList before other value. And set iterator to point on iserted value
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
public class InsertBeforeTest {
private void insertBefore(int before, int val, ListIterator<Integer> iter) {
while(iter.hasNext()) {
;; run it by command
;; $ emacs -Q --script test2.el
(setq line "asdf qwer")
(add-face-text-property 0 4 'a t line)
(add-face-text-property 0 5 'b t line)
(print line)
;; #("asdf qwer" 0 4 (face (a b)) 4 5 (face b))
(setq word (substring line 0 4))
;; run it by command
;; $ emacs -Q --script test-add-face-text-property.el
(setq line "asdf qwer")
(add-face-text-property 0 4 'a t line)
(add-face-text-property 0 4 'a t line)
(print line)
;; #("asdf qwer" 0 4 (face a))
(add-face-text-property 0 5 'b t line)
(add-face-text-property 0 5 'b t line)
(defun company--begin-new ()
(let (prefix c)
(cl-dolist (backend (if company-backend
;; prefer manual override
(list company-backend)
company-backends))
(setq prefix
(if (or (symbolp backend)
(functionp backend))
(when (company--maybe-init-backend backend)
@anton0xf
anton0xf / evince-bookmarks-to-pdftk-outline.md
Last active January 10, 2022 09:05
Convert evince bookmarks to PDF outline

extract bookmarks:

$ gio info -a "metadata::evince::bookmarks" coq-art.pdf \
    | sed -n '/metadata::/ s/^.*: //p' > coq-art.bookmarks

and restore its by:

gio set coq-art.pdf 'metadata::evince::bookmarks' "$(cat coq-art.bookmarks)"
@anton0xf
anton0xf / Main.java
Created November 26, 2020 11:46
мой пример к "кружку про ООП"
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@anton0xf
anton0xf / FibTest.java
Last active October 16, 2020 06:54
OK task 1
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FibTest {
@anton0xf
anton0xf / OffMap.java
Created October 16, 2020 06:44
OK task 2
interface OffMap {
long get();
void close();
}
class Wrap implements OffMap {