Skip to content

Instantly share code, notes, and snippets.

View takase1121's full-sized avatar

Takase takase1121

View GitHub Profile
@takase1121
takase1121 / await.lua
Created March 13, 2023 12:25
Simple callback to coroutine function.
---Converts a function with callback into coroutine-style wait.
---This function accepts a function which a "resolver" function
---is passed as the only argument.
---When this "resolver" function is called, control is yielded
---back to the user.
---@param fn fun(...: any): ...any
---@returns ...any
local function await(fn)
local co = coroutine.running()
local ret
@takase1121
takase1121 / SAMBA.md
Last active April 2, 2022 04:17
Accessing Ubuntu files from Windows easily

Here is a brief tutorial on how to open your Ubuntu files like any other Windows folder. The way we'll achieve this is by adding a Host-Only network adapter.

Some networking 101

I'm not an expert.

I am not an expert in networking and can barely fix anything. Don't quote me on this.

A computer network is just like a dorm. Each computer has an address (how to find them).

@takase1121
takase1121 / xterm
Created February 21, 2022 06:37
My XTerm settings
! Sensible defaults (https://aduros.com/blog/xterm-its-better-than-you-thought)
XTerm*locale: false
XTerm*utf8: true
XTerm*scrollTtyOutput: false
XTerm*scrollKey: true
XTerm*bellIsUrgent: true
XTerm*metaSendsEscape: true
! Styling
@takase1121
takase1121 / README.md
Created February 1, 2022 12:21
Comic Mono Nerd Font Mono

This is Comic Mono patched with -s flag so it'll be picked up by programs that only want monospace fonts.

Check comment for download.

@takase1121
takase1121 / README.md
Last active February 6, 2022 03:59
My VirtualBox setup for Windows interop

Setup

  • Fedora XFCE (seamless mode only works on X11 currently)
  • Setup shared folder (for Guest->Host communication):
    • C:\ -> /mnt/c
    • %USERPROFILE%\Documents -> ~/winhome
  • Use NAT and a Host-Only Adapter (Or bridged on vmware. Trust me, it'll save a lot of time)
  • Setup sshfs-win for Host->Guest access (or see below for smb configuration)
@takase1121
takase1121 / init.vim
Last active February 2, 2022 12:16
my nvim config lol
set mouse=a
set number
set hidden
set clipboard+=unnamedplus
" install vimplug if not available
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
@takase1121
takase1121 / arglol.lua
Created July 1, 2021 11:25
arg parser
-- Very simple arg parser
local function resolve(tbl, key)
if type(tbl[key]) == "string" then return resolve(tbl, tbl[key]) else return key end
end
local function consume_long(optlist, stack, opt)
local key, value = string.match(opt, "^([%w-_]+)=?(.*)$")
local cast = assert(optlist[key], "invalid parameter --" .. key)
if cast == true then
@takase1121
takase1121 / trie.lua
Created March 21, 2021 09:11
A radix trie
local Trie = {}
Trie.__index = Trie
function Trie:__tostring()
return "Trie"
end
function Trie:__call(...)
local obj = setmetatable({}, self)
obj:new(...)
@takase1121
takase1121 / promise.lua
Last active February 14, 2021 13:43
Minimal-ish JS Promise implementation in lua
--[[
Promises fully contained in a function.
This function returns a promise where you can resolve/reject just like in JS.
Example use case:
---
local promise = make_promise()
http.get(url, function(data) promise:resolve(data) end)
promise
:next(function(data) return json.parse(data) end)
:catch(function(err) print(err) end)
@takase1121
takase1121 / README.md
Created February 9, 2021 05:15
Better stack trace for setInterval/setTimeout/event-loop invoked callbacks.

This is something that I do sometimes:

function a() {
  let i = 0
  function self() {
    if (i >= 5) {
      throw new Error("Oh no!")
    }
    console.log("tick!")
 i++