Skip to content

Instantly share code, notes, and snippets.

@dskecse
dskecse / example.rb
Created December 26, 2025 14:28
Ruby 4.0 Ractor push type (send/receive) communication with Ractor::Port
# frozen_string_literal: true
p RACTOR_COUNT: Ractor.count # => 1
p IS_MAIN_RACTOR: Ractor.main? # => true
p Ractor.main # => #<Ractor:#1 running>
port = Ractor::Port.new
p port # => #<Ractor::Port to:#1 id:1>
Ractor.new(port) do |port|
p RACTOR_COUNT: Ractor.count # => 2
@dskecse
dskecse / rubybox.rb
Created December 26, 2025 13:18
Ruby 4.0 Box
# frozen_string_literal: true
X = 1
class Rubybox
def self.x = X
def x = ::X
end
# Usage:
@dskecse
dskecse / backup-analyze-redis.sh
Created February 20, 2025 15:35 — forked from hartleybrody/backup-analyze-redis.sh
backup a production redis URL to your local redis server (and analyze key usage)
# 1. download a copy of prod db to localhost
# connect to remote redis database and
# download a snapshot of the entire database
# to a local file on your filesystem
# via https://stackoverflow.com/a/61365048/625840
# docs https://redis.io/docs/manual/cli/#remote-backups-of-rdb-files
redis-cli -u $PROD_REDIS_URL --rdb dump.rdb
@dskecse
dskecse / hls.sh
Created November 12, 2024 07:34 — forked from stenuto/hls.sh
HLS ffmpeg script
#!/bin/bash
# Function to display usage information
usage() {
echo "Usage: $0 /path/to/input.mp4 [ /path/to/output_directory ]"
exit 1
}
# Check if at least one argument (input file) is provided
if [ $# -lt 1 ]; then
@dskecse
dskecse / bespoke.rb
Created December 21, 2023 09:53
Primality test in Ruby
def prime?(n)
return false if n <= 1
i = 2
while i * i <= n
return false if n % i == 0
i += 1
end
true
end
@dskecse
dskecse / default.py
Created December 3, 2023 21:19
Hash (Dict) with a default value in Ruby vs Python
from collections import defaultdict
dict = defaultdict(lambda : 0)
dict["a"]
# => 0
dict.keys()
# => dict_keys(['a'])
print(dict.get("b"))
# => None
dict.keys()
@dskecse
dskecse / brackets.py
Last active November 25, 2023 10:16
Python dict magic to Ruby
matches = dict(['()', '[]', '{}'])
print(matches)
# {'(': ')', '[': ']', '{': '}'}
@dskecse
dskecse / positionable.rb
Created January 18, 2021 10:31
Positionable module/concern
module Positionable
extend ActiveSupport::Concern
included do
scope :by_position, -> { order("#{table_name}.position ASC") }
# or default_scope
end
end
@dskecse
dskecse / launch.json
Last active January 27, 2019 16:48
Configuration for debugging Vue.js in VS Code
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "vuejs: chrome",
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
# Activate the gem you are reporting the issue against.