Skip to content

Instantly share code, notes, and snippets.

@pkulchenko
pkulchenko / redis.lua
Created December 19, 2023 14:12 — forked from solisoft/redis.lua
Redbean Redis Client
local redis = {
_VERSION = 'redis-lua 2.0.5-dev',
_DESCRIPTION = 'A Lua client library for the redis key value storage system.',
_COPYRIGHT = 'Copyright (C) 2009-2012 Daniele Alessandri',
}
-- The following line is used for backwards compatibility in order to keep the `Redis`
-- global module name. Using `Redis` is now deprecated so you should explicitly assign
-- the module to a local variable when requiring it: `local redis = require('redis')`.
Redis = redis
@pkulchenko
pkulchenko / .init.lua
Last active May 19, 2023 00:07
CGI example for redbean web server
local MAXTIME = 5 -- sec
local function cgi(cmd, opts)
if not cmd or not cmd[1] then error('missing command') end
if not opts then opts = {} end
local nph = opts.nph
local maxtime = opts.maxtime or MAXTIME
local env = {}
local envu = opts.env or {}
local envd = #envu > 0 and envu or {
SERVER_ADDR = FormatIp(GetServerAddr()),
@pkulchenko
pkulchenko / lazylists.lua
Created April 29, 2021 05:14 — forked from marcoonroad/lazylists.lua
Lazy evaluation on lists (a la Perl6) with Lua... [ FIXED ]
#!/usr/bin/lua
-- Perl6 example --
--[[
my @xs := gather {
my $x = 0;
my $y = 1;
while True {
take $x;
require "wx"
-- this is a minimal example
local frame = wx.wxFrame(wx.NULL, wx.wxID_ANY, "Demo",
  wx.wxDefaultPosition, wx.wxSize(450, 450), wx.wxDEFAULT_FRAME_STYLE )
local e = wxstc.wxStyledTextCtrl(frame, wx.wxID_ANY,
  wx.wxDefaultPosition, wx.wxSize(0, 0), wx.wxBORDER_STATIC)
e:SetText("if true then\n  print '1'\nend\n\nfoo(1,\n  2)\n")
local margin = { LINENUMBER = 0, MARKER = 1, FOLD = 2 }
@pkulchenko
pkulchenko / webview-build-w3.diff
Created October 11, 2018 15:49
Patch to enable webview in win32 build of ZeroBrane Studio
diff --git a/build/build-win32.sh b/build/build-win32.sh
index 2a6c87ac..4949d199 100644
--- a/build/build-win32.sh
+++ b/build/build-win32.sh
@@ -316,8 +316,8 @@ if [ $BUILD_WXLUA ]; then
cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" -DCMAKE_BUILD_TYPE=$WXLUABUILD -DBUILD_SHARED_LIBS=FALSE \
-DCMAKE_CXX_FLAGS="-DLUA_COMPAT_MODULE" \
-DwxWidgets_CONFIG_EXECUTABLE="$INSTALL_DIR/bin/wx-config" \
- -DwxWidgets_COMPONENTS="stc;gl;html;aui;adv;core;net;base" \
- -DwxLuaBind_COMPONENTS="stc;gl;html;aui;adv;core;net;base" -DwxLua_LUA_LIBRARY_USE_BUILTIN=FALSE \
diff --git a/src/editor/markup.lua b/src/editor/markup.lua
index ddb3e208..d137899f 100644
--- a/src/editor/markup.lua
+++ b/src/editor/markup.lua
@@ -194,6 +194,10 @@ function MarkupStyle(editor, lines, linee)
local lsep = w:find(q(MD_MARK_LINZ)..q(MD_MARK_LINA))
if lsep then emark = #w-lsep+#MD_MARK_LINT end
end
+ local sp = bit.band(editor:GetStyleAt(p-1), ide.STYLEMASK) -- previous position style
+ if mark == MD_MARK_HEAD and not iscomment[sp] then
local https = require "ssl.https"
local ltn12 = require "ltn12"
local response = {}
local r, c, h, s = https.request {
url = "https://api.github.com/repos/akbooer/openLuup/contents?ref=master",
sink = ltn12.sink.table(response),
protocol = "tlsv1_2"
}
@pkulchenko
pkulchenko / linecomment.diff
Created January 15, 2018 00:21
ZeroBrane Studio Editor patch to capture linecomment value
diff --git a/src/editor/editor.lua b/src/editor/editor.lua
index f92e7f1..5a90fa1 100644
--- a/src/editor/editor.lua
+++ b/src/editor/editor.lua
@@ -1624,7 +1624,8 @@ local function cleanup(paths)
if not FileRemove(path) then wx.wxRmdir(path) end
end
end
-local function setLexLPegLexer(editor, lexername)
+local function setLexLPegLexer(editor, spec)
@pkulchenko
pkulchenko / highlightselected.diff
Created January 6, 2018 20:18
Update for highlightselected to work with Output window
diff --git a/highlightselected.lua b/highlightselected.lua
index 14ee4a1..43fa281 100644
--- a/highlightselected.lua
+++ b/highlightselected.lua
@@ -2,23 +2,30 @@
local updateneeded, cfg
local indicname = "highlightselected.selected"
+local function onUpdate(event, editor)
+ if bit.band(event:GetUpdated(), wxstc.wxSTC_UPDATE_SELECTION) > 0 then updateneeded = editor end
@pkulchenko
pkulchenko / console.diff
Last active October 8, 2017 00:09
Add `reset` to clear console environment
diff --git a/src/editor/shellbox.lua b/src/editor/shellbox.lua
index 6a9a776..70a29cb 100644
--- a/src/editor/shellbox.lua
+++ b/src/editor/shellbox.lua
@@ -400,9 +400,10 @@ end
local function displayShellIntro()
DisplayShellMsg(TR("Welcome to the interactive Lua interpreter.").." "
- ..TR("Enter Lua code and press Enter to run it.").."\n"
- ..TR("Use Shift-Enter for multiline code.").." "