Skip to content

Instantly share code, notes, and snippets.

View wsgac's full-sized avatar

Wojciech S. Gac wsgac

  • Keepit
  • Warszawa, Poland
View GitHub Profile
@wsgac
wsgac / dmenu.l
Last active June 24, 2019 15:30
PicoLisp wrapper around dmenu
(de dmenu (Prompt . @)
# Run a 'dmenu' selector on arguments. Display Prompt.
(pipe (out (if Prompt
(list 'dmenu "-l" "10" "-p" Prompt)
(list 'dmenu "-l" "10"))
(mapcar prinl (rest)))
(line T)))
@wsgac
wsgac / poor-mans-credentials.el
Created April 11, 2019 13:21
A silly and insecure way to store usernames and passwords in Org-mode documents
;;;;;;;;;;;;;;
;; Org-mode ;;
;;;;;;;;;;;;;;
(defun get-user-or-password-from-node (type)
"Extract username or password from the current"
(assert (member type '(user pass USER PASS)))
;; Probably superfluous, given the mode-specific bindings below
(assert (eq (with-current-buffer (current-buffer) major-mode) 'org-mode))
(let ((item (org-entry-get nil "ITEM")))
@wsgac
wsgac / wc.l
Last active April 25, 2019 15:13
Implementation of wc in Flex
/* -*-bison-*- */
/* Simple wc implementation in Flex */
%option noyywrap
int rows = 0, words = 0, chars = 0;
%%
\n rows++;
[A-Za-z0-9]+ words++; chars += strlen(yytext);
. chars++;
@wsgac
wsgac / expeditor.ss
Created April 30, 2019 16:00
First attempts at FFI for Gerbil expeditor
;; -*- scheme -*-
(import :std/foreign)
(export get-screen-size)
(begin-ffi (get-screen-size)
(c-declare "#include <sys/ioctl.h>")
(c-declare "#include <stdio.h>")
(c-declare "#include <unistd.h>")
@wsgac
wsgac / channels.lisp
Last active May 8, 2019 14:45
Go-like channel in Common Lisp (courtesy of ChanL)
;; Rob Pike's examples with Common Lisp ChanL
;; Based on "Go Concurrency Patterns" (https://talks.golang.org/2012/concurrency.slide)
(ql:quickload :chanl)
;; Background call example
;; (chanl::pcall #'(lambda () (boring "Yello")))
;; Running function in the background (p.16)
(defun boring (msg)
@wsgac
wsgac / csp.go
Created May 7, 2019 14:52
Use Go channels to demonstrate how to parallelize work-intensive tasks
package csp
type KVPair struct {
k int
v int
}
func Min(x, y int) int {
if x < y {
return x
@wsgac
wsgac / Dockerfile
Created May 14, 2019 15:47
Basic setup for VSCode debugging of a Dockerized Go application with Delve
FROM golang:1.11.10-alpine3.8
ENV CGO_ENABLED 0
ENV GOPATH /opt/go:$GOPATH
ENV PATH /opt/go/bin:$PATH
ADD . /opt/go/src/tutorial
WORKDIR /opt/go/src/tutorial
RUN apk add --no-cache git
RUN go get github.com/derekparker/delve/cmd/dlv
RUN go build -o tutorial tutorial.go
@wsgac
wsgac / stack.cpp
Last active May 16, 2019 13:17
Simple stack implementation in C++ (with templates)
#include <iostream>
// #define BUF_GROW_FACTOR 2
using namespace std;
template <class T>
class stack {
T *buffer;
int buf_size;
@wsgac
wsgac / queue.cpp
Created May 17, 2019 10:15
Simple queue implementation in C++ using templates
template <class T>
class queue {
T *buffer;
int buf_size;
int front_index;
int back_index;
int buf_grow_factor;
void realloc() {
T *tmp = new T[buf_size*buf_grow_factor];
int size = 0;
@wsgac
wsgac / stack.go
Created May 17, 2019 14:10
Simple stack implementation in Go
package stack
type StackIF interface {
Push(el interface{})
Pop() interface{}
Current() interface{}
Size() int64
Empty() bool
}