Skip to content

Instantly share code, notes, and snippets.

@dseeni
dseeni / json_pretty_print.lua
Created September 9, 2023 13:54 — forked from smjonas/json_pretty_print.lua
Utility function that turns a Lua table into a nicely formatted JSON string (pretty-printing).
--[[
MIT License
Copyright (c) 2022 Jonas Strittmatter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@dseeni
dseeni / multimethods.lua
Created August 29, 2023 14:34 — forked from gordonbrander/multimethods.lua
Lua multimethods
--[[
Lua multimethods. Inspired by Clojure's multimethods.
How to use it:
local Multi = require('multimethods')
-- Create a new multimethod and use isa as dispatch function.
-- This will dispatch on first argument by type.
local foo = Multi.create(isa)
@dseeni
dseeni / dsl-print
Created August 18, 2023 22:50 — forked from sam-github/dsl-print
Example of a lua DSL language
#!/usr/bin/env lua
--[[
dsl-print [some.dsl]
Example of a lua DSL language, that can use function call or assignment to define
keys, and uses call sequence to implicitly define nesting.
]]
function dsl(code, file)
local loaded, estr = loadstring(code, file)
local filterm_gen
local filterm_gen_shrink
-- A helper for case 2
filterm_gen_shrink = function(fun, gen_x, param_x, state_x)
return filterm_gen(fun, gen_x, param_x, gen_x(param_x, state_x))
end
filterm_gen = function(fun, gen_x, param_x, state_x, ...)
if state_x == nil then return nil end
@dseeni
dseeni / contrast.c
Created August 17, 2023 21:30 — forked from oantolin/contrast.c
Find most luminous contrasting color
#include <math.h>
#include <stdio.h>
double f(int c) {
double x = c / 255.0;
return x<=0.03928 ? x/12.92 : pow((x + 0.055)/1.055, 2.4);
}
double rellum(int r, int g, int b) {
return 0.2126*f(r) + 0.7152*f(g) + 0.0722*f(b);
@dseeni
dseeni / dot-repeating.md
Created August 2, 2023 00:27 — forked from kylechui/dot-repeating.md
A basic overview of how to manage dot-repeating in your Neovim plugin, as well as manipulate it to "force" what action is repeated.

Adding dot-repeat to your Neovim plugin

In Neovim, the . character repeats "the most recent action"; however, this is not always respected by plugin actions. Here we will explore how to build dot-repeat support directly into your plugin, bypassing the requirement of dependencies like repeat.vim.

The Basics

When some buffer-modifying action is performed, Neovim implicitly remembers the operator (e.g. d), motion (e.g. iw), and some other miscellaneous information. When the dot-repeat command is called, Neovim repeats that operator-motion combination. For example, if we type ci"text<Esc>, then we replace the inner contents of some double quotes with text, i.e. "hello world""text". Dot-repeating from here will do the same, i.e. "more samples""text".

Using operatorfunc

@dseeni
dseeni / orthodoxc++.md
Created July 3, 2023 23:53 — forked from bkaradzic/orthodoxc++.md
Orthodox C++

Orthodox C++

What is Orthodox C++?

Orthodox C++ (sometimes referred as C+) is minimal subset of C++ that improves C, but avoids all unnecessary things from so called Modern C++. It's exactly opposite of what Modern C++ suppose to be.

Why not Modern C++?

@dseeni
dseeni / Style_Table.md
Created July 3, 2023 11:04 — forked from gingerBill/Style_Table.md
Procedure Signature Styles and Ambiguities
Prefix/Odin Require Return Type Return Named Inputs
Empty Procedure proc() () -> void ()
1 input, unnamed proc(int) (int) -> void
1 input, named proc(x: int) (x: int) -> void (x: int)
1 input, 1 output proc(int) -> int (x: int) -> int (x: int) -> int
2 inputs, 2 unnamed outputs proc(int, int) -> (int, int) (int, int) -> (int, int) (x: int, y: int) -> (int, int)
0 inputs, 2 named outputs proc() -> (a: int, b: int) () -> (a: int, b: int)
2 in
@dseeni
dseeni / forkAllGitHubRepos.js
Last active July 3, 2023 01:47 — forked from techpavan/forkAllGitHubRepos.js
Fork all repositories from a user on GitHub
var totalForkCount;
var curForkCount=0;
var errorForkArray = new Array();
function initProcess(){
var user = window.location.pathname.split('/')[1];
var pageNo = 1;
var hrefArray = new Array();
while(hrefArray.length % 30 == 0){
var resp = sendSyncAjax("https://github.com/"+user+"?tab=repositories&page="+pageNo);
@dseeni
dseeni / test.md
Created July 2, 2023 06:49 — forked from ityonemo/test.md
Zig in 30 minutes

A half-hour to learn Zig

This is inspired by https://fasterthanli.me/blog/2020/a-half-hour-to-learn-rust/

Basics

the command zig run my_code.zig will compile and immediately run your Zig program. Each of these cells contains a zig program that you can try to run (some of them contain compile-time errors that you can comment out to play with)