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
[Trigger] | |
Operation = Upgrade | |
Type = Package | |
Target = pacman-mirrorlist | |
[Action] | |
Description = Updating pacman-mirrorlist with reflector and removing pacnew... | |
When = PostTransaction | |
Depends = reflector | |
Exec = /bin/sh -c "reflector --protocol https --country 'United Kingdom' --score 10 --sort rate --save /etc/pacman.d/mirrorlist; rm -f /etc/pacman.d/mirrorlist.pacnew" |
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
#!/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
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 |
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 'yaml' | |
t = %i(name address tel fax email website).freeze | |
c = [] | |
File.read('data.txt').split("\n\n").each do |line| | |
c << t.zip(line.split("\n")).to_h | |
end | |
puts c.to_yaml |
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 luajit | |
local ffi = require 'ffi' | |
local cast = ffi.cast | |
local cdef = ffi.cdef | |
local load = ffi.load | |
local libruby = load '/usr/lib/libruby.so' | |
cdef[[ |
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
#include <stdio.h> | |
// compile: gcc -g -fPIC -Wall -Werror -Wextra -pedantic callback.c -shared -o libtest.so | |
void | |
message(void) | |
{ | |
puts("wassupppp!"); | |
} |