Skip to content

Instantly share code, notes, and snippets.

@maruks
maruks / my-hash-table.lisp
Created December 7, 2022 21:13
Hash table
(defpackage #:my-hash-table
(:use #:cl #:arrows)
(:export #:new-hash #:put-hash #:get-hash #:hash-keys #:hash-values #:rem-hash))
(in-package #:my-hash-table)
(defun ->hash-code (key)
(-<> (format nil "~A" key)
(coerce <> 'list)
(reduce (lambda (hash elem) (+ (* 31 hash) (char-code elem))) <> :initial-value 0)))
@maruks
maruks / aws_lambda.py
Created July 21, 2015 11:23
AWS gateway / lambda function invocation
# AWS Version 4 signing example
# This version makes a POST request and passes request parameters
# in the body (payload) of the request. Auth information is passed in
# an Authorization header.
import sys, os, base64, datetime, hashlib, hmac
import requests # pip install requests
method = 'POST'
service = 'execute-api'
@maruks
maruks / erl.el
Created September 22, 2016 22:09
use rebar3 erlang shell in emacs
(setq inferior-erlang-machine "rebar3")
(setq inferior-erlang-machine-options '("shell"))
(setq inferior-erlang-shell-type nil)
(defpackage :transposition
(:use :cl))
(in-package :transposition)
(defparameter *text* "WEAREDISCOVEREDFLEEATONCE------")
(defun range (max &key (min 0) (step 1))
(loop for n from min below max by step
collect n))
@maruks
maruks / matrices.lisp
Last active February 9, 2020 19:24
matrix multiplication
(defpackage :matrices
(:use :cl :iterate)
(:export multiply))
(in-package :matrices)
(defun multiply (m1 m2)
(flet ((multiply-row (row column size)
(iter
(for i :below size)
@maruks
maruks / cloudy.clj
Created October 2, 2019 13:55
cloudy day
(defn queue []
(java.util.PriorityQueue.))
(defn peek [pqueue]
(.peek pqueue))
(defn poll [pqueue]
(.poll pqueue)
pqueue)
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#ifdef _MSC_VER
#include <intrin.h> /* for rdtscp and clflush */
#pragma optimize("gt",on)
#else
#include <x86intrin.h> /* for rdtscp and clflush */
#endif
(ns prison.core
(:require [gniazdo.core :as ws]
[clojure.data.json :as json]
[clojure.string :as str]))
(defn parse [str]
(json/read-str str :key-fn keyword))
(def score (atom {}))
(def last-round (atom nil))
(ns prison.core
(:require [gniazdo.core :as ws]
[clojure.data.json :as json]))
(defn parse [str]
(json/read-str str :key-fn keyword))
(def msg-atom (atom nil))
(defn handle [msg]
@maruks
maruks / Plumber.ex
Created December 18, 2017 13:26
refactored
defmodule Plumber do
def input(file) do
file
|> File.stream!()
|> Enum.map(&(Regex.split(~r/\D+/, String.trim(&1))))
|> Enum.reduce(%{}, fn([first | rest],acc) -> Map.put(acc,first,rest) end )
end
def count([], acc, input) do
case Map.keys(input) do