This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fiddle/import' | |
include Fiddle::Importer | |
# Fiddle v:1.0.1 | |
dlload | |
typealias 'VALUE', 'unsigned long long' | |
RBasic = struct [ | |
'VALUE flags', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fdf(n) | |
return 1 if n <= 2 | |
k = n >> 1 | |
a = fdf(k + 1) | |
b = fdf(k) | |
n % 2 == 1 ? (a * a + b * b) : (b * (2 * a - b)) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def circle(radius: 10) | |
0.step(to: radius << 1, by: 1) do |x| | |
0.step(to: radius << 1, by: 1) do |y| | |
dist = ((x - radius).abs2 + (y - radius).abs2) ** 0.5 | |
dist.between?(radius - 0.5, radius + 0.5) ? $> << ?. : $> << ' ' | |
end | |
$> << $/ | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> puts RubyVM::InstructionSequence.compile('-2 ** 2').disasm | |
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(1,7)> (catch: FALSE) | |
0000 putobject 2 ( 1)[Li] | |
0002 putobject 2 | |
0004 opt_send_without_block <calldata!mid:**, argc:1, ARGS_SIMPLE> | |
0006 opt_send_without_block <calldata!mid:-@, argc:0, ARGS_SIMPLE> | |
0008 leave | |
=> nil | |
>> puts RubyVM::InstructionSequence.compile('-2.itself ** 2').disasm | |
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(1,14)> (catch: FALSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'socket' | |
TCP_STATES = { | |
1 => :established, | |
2 => :syn_sent, | |
3 => :syn_recv, | |
4 => :fin_wait1, | |
5 => :fin_wait2, | |
6 => :time_wait, | |
7 => :close, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
uri = URI("https://i.imgur.com/NYPjmMN.jpg") | |
File.open('/path/you/want/to/save/image/blah.jpeg', 'wb') do |dest| | |
URI.open(uri) do |source| | |
IO.copy_stream(source, dest) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create 10-monitor.conf in /etc/X11/xorg.conf.d/ | |
# add these lines; | |
Section "Monitor" | |
Identifier "VGA1" | |
Modeline "1440x900_75.00" 136.49 1440 1536 1688 1936 900 901 904 940 -HSync +Vsync | |
Option "PreferredMode" "1440x900_75.00" | |
EndSection | |
Section "Screen" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
fizzbuzz = -> (n) { | |
case [n % 3, n % 5, n] | |
in 0, 0, _; "FizzBuzz" | |
in 0, _, _; "Fizz" | |
in _, 0, _; "Buzz" | |
else n | |
end | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'open3' | |
TracePoint.trace(:call) do |tp| | |
if tp.method_id == :capture3 | |
m = tp.self.method(tp.method_id) | |
m.parameters.each do |_, param| | |
puts "#{tp.method_id} called with #{tp.binding.local_variable_get(param)}" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fiddle/import' | |
class Object | |
extend Fiddle::Importer | |
RUBY_FL_SINGLETON = 1 << 12 | |
RBasic = struct ['uintptr_t flags', 'uintptr_t klass'] | |
private_constant :RUBY_FL_SINGLETON, :RBasic |