Skip to content

Instantly share code, notes, and snippets.

View wsgac's full-sized avatar

Wojciech S. Gac wsgac

  • Iagon
  • Warszawa, Poland
View GitHub Profile
@wsgac
wsgac / maze.hs
Created February 23, 2024 09:27
Some snippets from the IOHK Haskell course (https://github.com/input-output-hk/haskell-course)
{-
**************************** IMPORTANT ****************************
This week is a two-step homework. First, you have to solve the
"Maze" challenge, and then the "Forest" challenge. The challenges
are in two separate files in both the homework and solution, so
you can check the solution for the first "Maze" challenge without
spoilers of the "Forest" one. Make sure to check the solution for
"Maze" (and only "Maze," I see you 🥸👀) before starting with the
@wsgac
wsgac / requests_debugging.py
Last active November 30, 2023 12:38
How to enable request debugging in Python `requests` library
# Add debugging outputs to requests
try:
import http.client as http_client
except ImportError:
# Python 2
import httplib as http_client
http_client.HTTPConnection.debuglevel = 1
# You must initialize logging, otherwise you'll not see debug output.
@wsgac
wsgac / lem-improvements.lisp
Created November 29, 2023 23:47
Lem editor - ideas for improvement
(in-package :lem-core)
(defun undefine-key (keymap keyspec)
"Remove binding for KEYSPEC from KEYMAP. Two cases for KEYSPEC are
considered. If it's a symbol, try to remove the corresponding binding
from KEYMAP's FUNCTION-TABLE. If it's a string, parse the string into
chained components, try to extract the innermost chained hash table
from KEYMAP's TABLE and remove the relevant entry."
(check-type keyspec (or symbol string))
(typecase keyspec
@wsgac
wsgac / modify-x509-cert.py
Last active November 23, 2023 15:54
Parse, modify and write an x509 certificate with Python (WIP)
from cryptography import x509
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives import serialization
import os
# Read cert from file
with open("cert.pem", "rb") as f:
cert= x509.load_pem_x509_certificate(f.read(), default_backend())
@wsgac
wsgac / .zshrc
Created November 23, 2023 14:16
Configure a rudimentary `dabbrev-expand`-like contextual completion inside ZSH
# Completion functionality a'la Emacs' dabbrev-expand
zstyle ':completion:history-words:*' list no
zstyle ':completion:history-words:*' remove_all_dups yes
zstyle ':completion:history-words:*' stop yes
zstyle ':completion:history-words:*' menu yes
bindkey "^[/" _history-complete-older
@wsgac
wsgac / y-combinator-common-lisp.lisp
Created November 21, 2023 13:43
Y combinator in various Lisps
(defun factorial-y-combinator (n)
(funcall
(Y (lambda (f n)
(if (zerop n)
1
(* n (funcall f f (1- n))))))
n))
(defun tail-factorial-y-combinator (n)
(funcall
@wsgac
wsgac / .sbclrc
Created November 21, 2023 13:34
A self-updating SBCL config for propagating the same version of Lisp files across multiple systems
;; -*-lisp-*-
(ql:quickload :legit)
(defun sync-utils ()
(let* ((repo (make-instance 'legit:repository
:location "/home/wsg/hack/lisp/util-gist/"))
(remote "git@gist.github.com:9323a1b03108d4ff10570c26a21425c1.git"))
(legit:init repo :if-does-not-exist :clone :remote remote)
(legit:pull repo)
@wsgac
wsgac / util.lisp
Last active November 15, 2023 17:52
Common utilities in Common Lisp
;; -*-lisp-*-
(defmacro accum (accfn &body body)
(let ((ghead (gensym "head"))
(gtail (gensym "tail"))
(garg (gensym "arg")))
`(let* ((,ghead (list nil))
(,gtail ,ghead))
(macrolet ((,accfn (,garg)
`(setf ,',gtail
@wsgac
wsgac / TelegramMessage.hs
Created October 18, 2022 17:06
Send bot message to Telegram chat
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
module TelegramMessage where
import Data.Aeson
import Data.Proxy
@wsgac
wsgac / 32bit-to-ip.lisp
Created October 3, 2022 11:33
Various ways to convert a 32-bit number to IP in Common Lisp
(defun decimal-to-ip (decimal)
"Retrieve IP address by first obtaining a binary representation,
grouping it into 4 octets and finally reassembling them as 4 decimal
numbers."
(apply #'format nil "~a.~a.~a.~a"
(mapcar #'(lambda (s) (parse-integer s :radix 2))
(cl-ppcre:all-matches-as-strings "[01]{8}" (format nil "~2r" decimal)))))
(defun decimal-to-ip-bitwise (decimal)
"Convert numerical representation to octet-based IP via the byte