Skip to content

Instantly share code, notes, and snippets.

View Buy-One's full-sized avatar
🎯
Focusing

Buy-One

🎯
Focusing
View GitHub Profile
@Buy-One
Buy-One / replace_capture_by_capture_number2.lua
Last active April 19, 2024 10:55
Replace capture instances by their ordinal number in a string (2)
function replace_capture_by_capture_number2(str, what, with, ...)
-- the elipsis (vararg) represents a list of integers denoting the number of the what instance in the str
-- if the what instance number is out of scope or it isn't found, returns the original str
local t = {...}
local i = 0
local function repl()
i=i+1
for _, v in ipairs(t) do
if v == i then return with end
end
@Buy-One
Buy-One / VKeys.cs
Created April 14, 2024 13:46 — forked from pushrbx/VKeys.cs
[Serializable]
public enum VKeys
{
KEY_0 = 0x30, //0 key
KEY_1 = 0x31, //1 key
KEY_2 = 0x32, //2 key
KEY_3 = 0x33, //3 key
KEY_4 = 0x34, //4 key
KEY_5 = 0x35, //5 key
KEY_6 = 0x36, //6 key
--[[
* ReaScript Name: Save_FX_Preset
* Lua script for Cockos REAPER
* Author: EUGEN27771
* Author URI: http://forum.cockos.com/member.php?u=50462
* Licence: GPL v3
* Version: 1.04
* Mod by X-Raym
https://gist.github.com/X-Raym/448e8afea7d91bce96b520ca12ddc698#file-gen_save-preset-for-last-touched-fx-x-raym-mod-lua
https://forum.cockos.com/showthread.php?t=178127
@Buy-One
Buy-One / Insert string at specific position.lua
Created February 12, 2024 08:47
Insert string at specific position
function Esc(str)
if not str then return end -- prevents error
-- isolating the 1st return value so that if vars are initialized in a row outside of the function the next var isn't assigned the 2nd return value
local str = str:gsub('[%(%)%+%-%[%]%.%^%$%*%?%%]','%%%0')
return str
end
function insert_string_at_specific_position1(src_str, insert_str, pos_idx, move)
-- relies on Esc() function
-- returns nil if pos_idx is greater than src_str length
@Buy-One
Buy-One / Remove all characters bar some.lua
Created December 10, 2023 21:56
Remove all characters bar some
function remove_all_bar_some(str, ...)
-- the elipsis represents both literals and char classes
-- mind special characters which must be escaped as arguments
local keep = {...}
-- the table doesn't have to be passed as argument
-- because gsub doesn't seem to support functions with more than 1 argument
local function thin_out(c)
return function(c)
for _, char in ipairs(keep) do
if c == char or c:match(char)
@Buy-One
Buy-One / replace_capture_by_capture_number.lua
Last active April 19, 2024 10:53
Replace capture instances by their ordinal number in a string
function replace_capture_by_capture_number(str, what, with, ...)
-- the elipsis represents a list of integers denoting the number of the what instance in the str
-- if the what instance number is out of scope or it isn't found, returns the original str
-- refer to https://gist.github.com/Buy-One/eb033b716e7692e0d856779257cb3a96
-- for alternatives using string.gsub()
local inst_t = {...}
local t = {}
local i = 1
while i < #str do -- collect indices at which the what instances start
local s, e = str:find(what, i)
@Buy-One
Buy-One / sort_notes_by_name.lua
Last active April 10, 2023 15:06
Sort notes by name
function sort_notes_by_name(t, wantReverse) -- t is an array containing note names, wantReverse is boolean
-- the notes must use # and b for sharps and flats
-- the notes must be capitalized to distinguish between B and flat sign b
local pat = '[%-%d]+'
table.sort(t, function(a,b) return a:match(pat) < b:match(pat) end) -- sort by octave
local oct = -10 -- a value lower than the lowest octave number to be able to detect the 1st lowest and so forth
local table_len = #t -- to be used in removing all separate note fields
@Buy-One
Buy-One / shuffle_array.lua
Created April 8, 2023 14:31
Shuffle array forward or backward
function shuffle_array(t, places, backward) -- places integer, backward boolean
-- number of places backward = #t - places forward and vice versa, the results will be identical
if places == #t then return end -- because the order will end up being the same
local i = 0
if not backward then
local last = t[#t] -- store to assign to the 1st field
repeat
for i = #t,1,-1 do
if i < #t then t[i+1] = t[i] end
end
@Buy-One
Buy-One / gist:dd5835675e05c69ce80b2b789385de85
Created March 13, 2023 22:09 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
@Buy-One
Buy-One / REAPERControl.ahk
Created October 6, 2022 13:30 — forked from pannal/REAPERControl.ahk
REAPER Control v0.12b AutoHotkey Script
; ----------------------------------------------------------------------------------------------------------
; _____ _____ _____ _____ _____ _____ _____ _ _
; | __ || __|| _ || _ || __|| __ | | | ___ ___ | |_ ___ ___ | |
; | -|| __|| || __|| __|| -| | --|| . || || _|| _|| . || |
; |__|__||_____||__|__||__| |_____||__|__| |_____||___||_|_||_| |_| |___||_|
;
; ----------------------------------------------------------------------------------------------------------
; REAPER Control
; panni
; 2018