Skip to content

Instantly share code, notes, and snippets.

View gr33n7007h's full-sized avatar
🌴
On vacation

Li gr33n7007h

🌴
On vacation
View GitHub Profile
@tenderlove
tenderlove / mdns.rb
Created November 19, 2023 20:02
Sample mDNS client in Ruby
# mDNS client
#
# Usage: ruby script.rb "_http._tcp.local."
require "socket"
require "ipaddr"
require "fcntl"
require "resolv"
module DNSSD
@tenderlove
tenderlove / ruby_jit.rb
Last active January 12, 2022 00:17
Use fisk and fiddle to patch a Ruby method at runtime
require "fisk"
require "fisk/helpers"
require "fiddle/import"
module Ruby
extend Fiddle::Importer
dlload
typealias "VALUE", "uintptr_t"
# Have you ever wanted lldb to break in a certain place, but you weren't
# sure where to set the breakpoint? Look no further than this script!
#
# This script creates a chunk of executable code that uses the int3 x86
# instruction. This instruction is defined for use by debuggers, and you can
# read more about it here: https://en.wikipedia.org/wiki/INT_%28x86_instruction%29#INT3
#
# When that instruction is executed, the debugger will halt and you can do
# what you need!
#
def ractor_bitonic_sort array
size = array.size
level = size.bit_length - 1
raise 'size is not power of 2' unless size == 1 << level
pipe = Ractor.new { loop { Ractor.yield Ractor.recv } }
ractors = array.map.with_index do |v, i|
Ractor.new pipe, v, i, size, level do |pipe, v, index, size, level|
received = {}
conditional_recv = -> key {
return received.delete key if received.key? key
@gr33n7007h
gr33n7007h / bluetooth_socket_example.rb
Last active October 7, 2018 03:05
How to connect to a rfcomm/l2cap server in Ruby
#/usr/bin/env ruby
require 'socket'
addr = "00:11:22:33:44:55"
rf_chan = 23
l2_psm = 15
# rfcomm client
s = Socket.new 31, 1, 3 # (31 = AF_BLUETOOTH, 1 = SOCK_STREAM, 3 = BTPROTO_RCOMM)
@drbig
drbig / gist:4446871
Last active April 24, 2017 18:24
Pry session over telnet. Minimal and forking (plus a thread for the TCPServer).
drbig@swordfish:pts/16 ~/P/pry-tcprepl> cat pry-tcprepl.rb
require 'pry'
require 'pty'
class PryTcpRepl
attr_reader :thread
def initialize(where, host = '127.0.0.1', port = '9123')
@where = where
@host = host