Skip to content

Instantly share code, notes, and snippets.

@zetashift
zetashift / toy_robot.ex
Created November 26, 2018 02:11
ToyRobot - A snipper
defmodule ToyRobot do
@directions [:north, :east, :south, :west]
@directions_to_the_right %{north: :east, east: :south, south: :west, west: :north}
@directions_to_the_left Enum.map(@directions_to_the_right, fn {from, to} -> {to, from} end)
@table_top_x 4
@table_top_y 4
def place do
{:ok, %ToyRobot.Position{}}
@zetashift
zetashift / quicksort.scala
Created December 7, 2018 02:53
QuickSort in Scala
object QS {
def quickSort(xs: Array[Int]): Array[Int] = {
if (xs.length < 2) xs
else {
val pivot = xs(xs.length/2)
val less = xs.filter(n => n < pivot)
val greater = xs.filter(n => n > pivot)
quickSort(less) ++ Array(pivot) ++ quickSort(greater)
}
}
@zetashift
zetashift / genmap.nim
Last active December 31, 2018 00:08
Bare dungeon map generation
proc generateMap*(map: GameMap, maxRooms, roomMinSize, roomMaxSize: int,
mapWidth, mapHeight: int, player: Entity,
entities: seq[Entity], maxMonsterPerRoom: int): GameMap =
var
rooms: seq[Rect] = @[]
numRooms = 0
result = map
randomize()
@zetashift
zetashift / shoddygenerator.nim
Last active March 7, 2019 02:21
Implementation of the business card generator in Nim
# A quick Nim translation of https://gist.github.com/munificent/b1bcd969063da3e6c298be070a22b604
# With some help of the JS version
import random
const
HEIGHT = 40
WIDTH = 80
PLAYER = '@'
TREASURE = '$'
@zetashift
zetashift / bencode.nim
Created November 20, 2020 15:46
Bencode from day #2 of Nim days
# A simple Bencode parser following Nim Days by xmonader
import strformat, tables, json, strutils, hashes
type
BencodeKind* = enum
btString, btInt, btList, btDict
BencodeType* = ref object
case kind*: BencodeKind
of BencodeKind.btString: s* : string
of BencodeKind.btInt: i* : int
@zetashift
zetashift / immutable_setup.nim
Created February 24, 2021 20:39
Nim - variable immutable after setup
let vao = block:
var res: GLuint
glGenVertextArrays(1, addr res)
res
glBindVertextArray(vao)
@zetashift
zetashift / shell.nix
Last active March 16, 2021 17:31
Bare minimum Gleam shell.nix
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
let inputs = [
gleam
erlang
rebar3
];
@zetashift
zetashift / shell.nix
Last active March 16, 2021 20:14
Elixir minimum shell.nix
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
let
erlang = erlangR23;
elixir = elixir_1_11;
nodejs = nodejs-14_x;
inputs = [
@zetashift
zetashift / init.lua
Created March 25, 2021 00:32
My WIP neovim init
-- :version
-- NVIM v0.5.0-dev
-- Build type: RelWithDebInfo
-- LuaJIT 2.1.0-beta3
local execute = vim.api.nvim_command
local fn = vim.fn
local cmd = vim.cmd
local g = vim.g
@zetashift
zetashift / ltex_ls.lua
Created May 11, 2021 19:41
Ltex-ls and NeoVim
local lspconfig = require'lspconfig'
local configs = require'lspconfig/configs'
local M = {}
M.setup = function()
-- Check if it's already defined for when reloading this file
if not lspconfig.ltex_ls then
configs.ltex_ls = {
default_config = {