Skip to content

Instantly share code, notes, and snippets.

View maxim's full-sized avatar
🛠️

Max Chernyak maxim

🛠️
View GitHub Profile
@maxim
maxim / mcp.rb
Last active May 25, 2025 18:32
A quick one file stdio MCP server in Ruby
#!/usr/bin/env ruby
require 'json'
require 'shellwords'
module Mcp
Prop = Data.define(:name, :type, :desc, :req) do
def to_h = { type: type, description: desc }
end
class Definition
@maxim
maxim / 1-welcome_page.rb
Last active January 24, 2025 17:28
Page objects example
class WelcomePage
attr_reader :greeting, :recent_activity, :support_email
def self.from_user(user)
new \
greeting: "Good #{user.time_of_day}, #{user.name}",
recent_activity: ActivityItem.from_user(user),
support_email: Rails.configuration.app.support_email
end
@maxim
maxim / msteams-new.lsrules
Last active April 15, 2025 19:11
Little Snitch rules for Microsoft Teams, updated at 2025-03-01 00:21:16+00:00.
{
"description": "Rules based on Microsoft Endpoints at https://endpoints.office.com/endpoints/worldwide?clientrequestid=b794baa0-662f-4592-b4f0-46ab3284b612&ServiceAreas=Skype",
"name": "Microsoft Teams",
"rules": [
{
"action": "allow",
"process": "/Applications/Microsoft Teams.app/Contents/MacOS/MSTeams",
"remote-addresses": "52.112.0.0-52.115.255.255,52.122.0.0-52.123.255.255,2603:1063::-2603:1063:3ff:ffff:ffff:ffff:ffff:ffff",
"ports": "3478-3481",
"protocol": "udp"
require 'minitest/mock'
module StubStrict
module_function
def render_parameters(ruby_parameters)
ruby_parameters.map { |type, name|
case type
when :req; name.to_s
when :opt; "#{name} = 'value'"
#!/usr/bin/env bash
set -e
# Usage:
# ./install-rclone.sh v1.65.0-beta.7390.2a30c417a.fix-b2-upload-url
# Check if the argument is supplied
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <rclone_version>"
exit 1
@maxim
maxim / options.rb
Last active September 17, 2023 04:38
option :foo_a
option :foo_b, value: {type: Integer}
option :bar_x, value: {type: String}
option :bar_y
option :bar_z, value: {type: Integer}
attr_reader :kwargs
def self.from_options(options)
class Severity
include Comparable
attr_reader :value
ORDER = %i[low medium high]
def self.[](value)
new(value)
end
def initialize(value)
@maxim
maxim / bench.rb
Last active May 13, 2023 12:17
Catch throw vs raise rescue vs baseline return (Ruby v3.2.0)
code1 = -> { catch(:foo) { throw(:foo, 'string') } }
code2 = -> { begin; raise RuntimeError; rescue RuntimeError; 'string' end }
code3 = -> { 'string' }
Benchmark.ips do |x|
x.report("catch a throw") {
value = code1.call
}
x.report("rescue and exception") {
@maxim
maxim / skype.lsrules
Last active March 1, 2025 00:21
Little Snitch rules for Skype, updated at 2025-03-01 00:21:16+00:00.
{
"description": "Rules based on Skype FAQ at https://support.skype.com/en/faq/FA148/which-ports-need-to-be-open-to-use-skype-on-desktop",
"name": "Skype",
"rules": [
{
"action": "allow",
"process": "/Applications/Skype.app/Contents/MacOS/Skype",
"ports": "443,1000-10000,50000-65000,16000-26000",
"protocol": "TCP"
},
@maxim
maxim / msteams.lsrules
Last active March 1, 2025 00:21
Little Snitch rules for Microsoft Teams classic, updated at 2025-03-01 00:21:16+00:00.
{
"description": "Rules based on Microsoft Endpoints at https://endpoints.office.com/endpoints/worldwide?clientrequestid=b794baa0-662f-4592-b4f0-46ab3284b612&ServiceAreas=Skype",
"name": "Microsoft Teams classic",
"rules": [
{
"action": "allow",
"process": "/Applications/Microsoft Teams classic.app/Contents/MacOS/Teams",
"remote-addresses": "52.112.0.0-52.115.255.255,52.122.0.0-52.123.255.255,2603:1063::-2603:1063:3ff:ffff:ffff:ffff:ffff:ffff",
"ports": "3478-3481",
"protocol": "udp"