Skip to content

Instantly share code, notes, and snippets.

@vseloved
vseloved / tcp-blackhole.lisp
Created January 27, 2012 13:37
Simplest tcp blackhole
(ql:quickload :usocket)
(defun start-blackhole (&optional (port 80))
(let ((sock (usocket:socket-listen "0.0.0.0" port :reuse-address t)))
(loop (let ((conn (usocket:socket-accept sock)))
(format t "Connected ~A~%" (slot-value conn 'usocket::stream))))))
@vseloved
vseloved / find-words.lisp
Last active September 2, 2019 16:39
splitting text w/o spaces into words
(ql:quickload :cl-ppcre)
(ql:quickload :rutils)
(use-package :rutil)
(named-readtables:in-readtable rutils-readtable)
(defpar *orig*
#/I joined Hacker News around 5 years ago. I used to wake up and do the grim commute each morning to London from my home and the only thing that made it vaguely ok was Hacker News. It was a great place to go and find interesting articles from genuinely passionate people. It also used to be a really safe place to launch a startup that you'd spent days, weeks, years on - your project. It was a place where you could launch your startup and know you'd get great constructive feedback. People may not necessarily like your site but they'd admire you for having the balls to launch it, for spending time developing something that you hoped could benefit people in some way. They'd want you to succeed and they'd try and help you succeed with feedback that would ultimately help you. Unfortunately, today's Hacker News audience is no longer the same. Today's Hacker News is a place where us
@vseloved
vseloved / pdf-img-url.lisp
Created October 21, 2012 19:44
Making CL-PDF and CL-TYPESETTING work with images and URLs
(cl:in-package #:cl-pdf)
(defun draw-image (image x y dx dy rotation &optional keep-aspect-ratio)
(when keep-aspect-ratio
(unless (zerop dx)
(let ((r1 (/ dy dx))
(r2 (/ (height image) (width image))))
(if (> r1 r2)
(setf dy (* dx r2))
(setf dx (/ dy r2))))))
@vseloved
vseloved / graylog2.lisp
Created December 11, 2012 21:45
Send Lisp errors to Graylog2 server
(ql:quickload "usocket")
(ql:quickload "cl-json")
(ql:quickload "salza2")
(ql:quickload "babel")
(ql:quickload "local-time")
(ql:quickload "rutils")
(named-readtables:in-readtable rutil:rutils-readtable)
(defvar *hostname* nil)
@vseloved
vseloved / listcomp.lisp
Last active May 30, 2020 04:27
List comprehensions with a syntax very close to set-theoretic notation
(defun read-listcomp (stream char)
(declare (ignore char))
(let (rezs srcs conds state)
(dolist (item (read-delimited-list #\} stream))
(if (eql '|| item)
(setf state (if state :cond :src))
(case state
(:src (push item srcs))
(:cond (push item conds))
(otherwise (push item rezs)))))
(defun am->br (am br amf)
(flet ((str->arr (str)
(make-array (length str) :initial-contents (coerce str 'list))))
(with-accessors ((as diff:original-start) (al diff:original-length)
(bs diff:modified-start) (al diff:modified-length))
(find (find-class 'diff:modified-diff-region)
(diff:compute-raw-diff (str->arr am)
(str->arr br))
:key 'class-of)
(strcat (slice amf 0 as)
@vseloved
vseloved / generator-send.lisp
Last active May 19, 2016 07:36
Implement generator send with restarts
(define-condition generated ()
((item :initarg :item :reader generated-item)))
(defun yield (&optional item)
(restart-case (signal 'generated :item item)
(resume (&optional item) item)))
(defun send (item generator)
(let (already-triggered)
(handler-bind ((generated (lambda (e)
@vseloved
vseloved / algorithms-glossary-ru-uk.md
Last active July 1, 2016 22:45
Глоссарий алгоритмических терминов

Глоссарий алгоритмических терминов

Общепринятые

English Русский Українська
queue очередь черга
heap куча купа
tree дерево дерево
graph граф граф
@vseloved
vseloved / stage1.lisp
Last active January 27, 2017 13:59
Filter Cyrillic texts with Ukrainian letters from CC WET files
(let (cur)
(with-output-to-string (out)
(loop :for line := (read-line *standard-input* nil) :while line :do
(cond
((string= #.(format nil "WARC/1.0~C" #\Return) line)
(setf cur :header)
(let* ((outstr (string-trim '(#\Newline #\Return #\Linefeed)
(get-output-stream-string out)))
(count-i (count-if (lambda (char)
(member char '(#\і #\ї #\є #\І #\Ї #\Є #\Ґ #\ґ)))
@vseloved
vseloved / nnse.lisp
Created April 19, 2017 14:41
Unfinished code for NNSE calculation
(in-package #:nlp.embeddings)
(named-readtables:in-readtable rutilsx-readtable)
(eval-always
(rename-package "BKNR.SKIP-LIST" "BKNR.SKIP-LIST" '("SKLIST")))
(defun gather-freq-dict (vecs dir &key (cutoff 0) (dump-file "/tmp/dict.txt"))
(let ((dict #h(equal))
(idxs #h(equal))