Skip to content

Instantly share code, notes, and snippets.

View Earu's full-sized avatar
🤸‍♂️
Training a linear regression classification model...

Ryan Earu

🤸‍♂️
Training a linear regression classification model...
  • France
View GitHub Profile
@Earu
Earu / [hackerrank]_Jesse_and_cookies.cs
Last active October 10, 2024 13:11
Code for the "Jesse and cookies" challenge on hackerrank.com
/*
Jesse loves cookies and wants the sweetness of some cookies to be greater than value K.
To do this, two cookies with the least sweetness are repeatedly mixed. This creates a special combined cookie with:
(least sweet cookie) + (2 * (second least sweet cookie))
This occurs until all the cookies have a sweetness >= K.
Given the sweetness of a number of cookies, determine the minimum number of operations required. If it is not possible, return -1.
*/
using System.CodeDom.Compiler;
@Earu
Earu / [hackerrank]_Simple_Text_Editor.cs
Last active May 17, 2022 22:48
Code for the "Simple Text Editor" challenge on hackerrank.com
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
class Operation
{
protected readonly Stack<Operation> operationStack;
protected readonly string context;
@Earu
Earu / advanced_server_search_query.lua
Last active April 16, 2022 14:08
An advanced Garry's Mod server search query processor.
local function parse_host_name_tags(host_name)
local tags = {}
local function add_tag(tag)
tag = tag:Trim()
if #tag > 1 and #tag < 15 then
table.insert(tags, tag)
end
end
local start_index, _ = host_name:find("[%|%,%-]")
@Earu
Earu / fs_hider.lua
Last active January 23, 2022 12:55
Naughty script that allows you to hide files in Garry's Mod. Lua replacement for gm_fshook.
-- if you don't trust the hook library at this point you might wanna
-- replace this with a local callback of sorts
hook.Add("ShouldHideFile", "", function(_, path)
if path:match("custom_file.lua") then return true end
end)
-- hide our detours
local debug_info_cache = {}
local old_debug_getinfo = debug.getinfo
function debug.getinfo(fn, ...)
@Earu
Earu / hook_async.lua
Last active August 22, 2021 10:34
POC for a Garry's Mod asynchronous event library.
--[[
MAIN DIFFERENCES WITH THE SYNCHRONOUS HOOK LIBRARY
- You cannot add a hook callback to an event that is being executed
example:
hook.Add("Think", "example", function()
hook.Add("Think", "example2", function() end)
end)
In this case the hook would be added from the next call of the Think event
and not in the callback.
@Earu
Earu / server_screenshot.lua
Last active August 22, 2021 09:39
POC for taking a screenshot of a client's playermodel from a random angle from the server.
local TAG = "SCREENSHOT_SV"
if SERVER then
util.AddNetworkString(TAG)
local token_base = "1234567890_@#$abcdefghijklmnopqrstuvwxyz"
local function generate_token()
local ret = ""
for _ = 1, math.random(10, 32) do
local char = token_base[math.random(#token_base)]
@Earu
Earu / easychat_native_playersay_calls.lua
Created July 25, 2021 13:33
POC for detecting native PlayerSay calls and fowarding them to EasyChat's own networking (only works in sandbox derived gamemodes).
--[[
---------------------------------------------------------------------
THIS ONLY WORKS IN SANDBOX, DARKRP DOES WEIRD STUFF WITH ITS
GAMEMODE PLAYERSAY HOOK SO IT WONT WORK (SAME WITH MURDER)
---------------------------------------------------------------------
--]]
hook.Add("PostGamemodeLoaded", TAG, function()
local existing_callbacks = hook.GetTable().PlayerSay or {}
for identifier, callback in pairs(existing_callbacks) do
@Earu
Earu / easychat_os_mentions.lua
Last active September 4, 2020 22:31
EasyChat mentions sent directly to you via your os notifications.
require("win_toast") -- you need https://github.com/Earu/gm_win_toast
local base_dir = "windows_mentions"
local function get_avatar(id64, success_callback, err_callback)
http.Fetch("http://steamcommunity.com/profiles/" .. id64 .. "?xml=1", function(content, size)
local ret = content:match("<avatarIcon><!%[CDATA%[(.-)%]%]></avatarIcon>")
success_callback(ret)
end, err_callback)
end
@Earu
Earu / easychat_local_tab.lua
Last active April 18, 2020 01:05
A simple EasyChat tab module that allows you to outsource your local Garry's Mod chat.
local tag = "local_tab"
local EC_LEGACY_ENTRY = GetConVar("easychat_legacy_entry")
local EC_LEGACY_TEXT = GetConVar("easychat_legacy_text")
local HAS_CHROMIUM = jit.arch == "x64"
local use_new_text_entry = (EC_LEGACY_ENTRY and not EC_LEGACY_ENTRY:GetBool()) or not EC_LEGACY_ENTRY
local use_new_richtext = (EC_LEGACY_TEXT and not EC_LEGACY_TEXT:GetBool()) or not EC_LEGACY_TEXT
local tab = vgui.Create("DPanel")
@Earu
Earu / websocket.lua
Last active September 27, 2020 11:13
Garry's Mod client-side websockets.
local function init_listener_type(obj, browser, name)
local listeners_key = ("%sListeners"):format(name)
local callback_key = ("On%s"):format(name)
local add_listener_key = ("Add%sListener"):format(name)
obj[listeners_key] = {}
obj[callback_key] = function(...)
for _, listener in ipairs(obj[listeners_key]) do
listener(...)
end