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
# parse lspci output | |
require 'shellwords' | |
def parse_lspci_output | |
IO.popen('lspci -m') do |io| | |
io.readlines.filter_map do |line| | |
if line.match?(/3D|VGA|Display/) | |
pci_vendor, pci_device = line.shellsplit[2..4] | |
"#{pci_vendor} #{pci_device}" |
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
# https://github.com/atemerev/skynet | |
module Skynet | |
module_function | |
def make_fiber(num, size, div) | |
Fiber.new do | |
Fiber.yield(num) if size == 1 | |
fibers = (0...div).map do |i| | |
sub = num + i * (size / div) |
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
# save this peice of code in your ~/.irbrc | |
module Reline | |
DUMMY = ->() { | |
# autocomplete | |
return nil unless config.autocompletion | |
if just_cursor_moving and completion_journey_data.nil? | |
# Auto complete starts only when edited | |
return nil | |
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
# frozen_string_literal: true | |
abort 'MJIT needs to be enabled' unless RubyVM::MJIT.enabled? | |
# make private constants available at top-level | |
# | |
constants = | |
Symbol.all_symbols.select do | |
RubyVM::MJIT.private_constant _1 rescue next | |
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' | |
module Kernel | |
fname = 'rb_gv_get' | |
if Fiddle::Handle::DEFAULT.sym_defined?(fname) | |
sym = Fiddle::Handle::DEFAULT.sym(fname) | |
fun = Fiddle::Function.new(sym, [:const_string], :voidp, name: fname) | |
define_method(fname, &fun) | |
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 'optparse' | |
Arguments = Struct.new(:copies, :filename) | |
arguments = Arguments.new | |
options = ARGV.options do |opt| | |
opt.banner = "usage: #{opt.program_name} [options] <input file>" | |
opt.on '--copies=n', 'Number of copies', &:to_i | |
opt.on '-h', '--help', 'Displays this usage screen' do | |
puts opt |
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 lua | |
local std = require'posix.unistd' | |
local sio = require'posix.stdio' | |
local rd, wr = std.pipe() | |
std.write(wr, "foo\nbar\nbaz\nfood") | |
std.close(wr) | |
local file = sio.fdopen(rd, 'r') |
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' | |
include Fiddle | |
# Fiddle v:1.0.1 | |
setlocale = Function.new( | |
Handle['setlocale'], | |
[ | |
:int, | |
:const_string |
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 |
NewerOlder