Skip to content

Instantly share code, notes, and snippets.

@drbrain
drbrain / unfuck-vmware-net.sh
Created April 7, 2017 04:19 — forked from fnichol/unfuck-vmware-net.sh
"Fix" VMware Network
#!/usr/bin/env bash
set -e
[ -n "$DEBUG" ] && set -x
banner() { printf -- "-----> $*\n"; }
banner "Restarting VMware networking"
banner "Stopping networking"
sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --stop
require 'rake/tasklib'
require 'rake/clean'
##
# Creates a cross-compiled library that mruby-cli can use to link with
# each cross-built command.
#
# CrossLibrary.new "curl" do |cross|
# cross.release_name = "curl-7.28.0"
# cross.url = "https://curl.example/download/#{cross.release}.tar.gz"
@drbrain
drbrain / include_module.rb
Created July 29, 2016 17:13
Two ways of testing modules with Minitest
class TestMyModule < Minitest::Test
include MyModule
def test_method_from_my_module
actual = method_from_my_module input_data
assert_equal 'something', actual
end
end
#!/usr/bin/env ruby
numbers = (1..100).to_a
numbers.each do |n|
div_5 = n.divmod(5).last.zero?
div_7 = n.divmod(7).last.zero?
message =
if div_5 and div_7 then
@drbrain
drbrain / Rakefile
Created June 9, 2016 20:25
Rake sh capabilities
task default: %w[shellmode shellmode_ENV direct io]
task :shellmode do
sh "echo hello world"
end
task :shellmode_ENV do
env = {
'MESSAGE' => 'hello world',
}
@drbrain
drbrain / README.md
Last active May 11, 2016 17:26
Use rake tasks to check preconditions instead of methods

By using a rake task you allow rake to figure out if the check is needed or not. For example, you may need to check if multiple tasks that are dependencies of each other are running inside Docker

If you use a method to perform the check it will run every time for every task. This reduces performance because you really only need to run this check once.

If you use a task as a precondition instead rake will determine when it needs to run and only run it once.

@drbrain
drbrain / force_loopback_drb.rb
Last active March 22, 2016 21:27
By overriding DRb.here? we force DRb communication
require 'drb'
require 'drb/unix'
shared = []
DRb.start_service 'drbunix:', shared
loopback = DRb.uri
puts loopback
@drbrain
drbrain / rubym.c
Created March 15, 2016 17:12
Marshal testcase runner for afl-fuzz
#include "ruby.h"
int
main(int argc, char **argv) {
char *real_argv[] = {
"--disable-gems",
"-e",
"Marshal.load $stdin.read"
};
@drbrain
drbrain / gist:6f78c87c5a466353edd1
Last active January 26, 2016 01:10
I set my clock back and GPG doesn't care:
$ echo hello | gpg --sign --default-key 59354e36 -a > signed
$ cat signed
-----BEGIN PGP MESSAGE-----
Comment: GPGTools - https://gpgtools.org
owEBPALD/ZANAwAKAUWt78FZNU42AcsMYgBD2CE+aGVsbG8KiQIcBAABCgAGBQJD
2CE+AAoJEEWt78FZNU427+IP/jcAm4ZctrftvFXjr0sAs5r+TmSfGVAfeK5l9/nC
zHAH4Z+udXxW9KjVs5SIo878Kb4GWx5KyHrNw/x6rr0w8wJtCNjMK5xuhMFhN8na
OtwVo+6Rc80zozbiFau8z2iH/G2AS+cYendSLZcEMl910BIcDQI2FgIfepHAp1LT
9K9Y8VR/HVT+9weF9LFwvoBSEiDWkrDjYAACsQLjZCqZJmb+oJ3p70lkL36T+4en
class A
def self.m
puts "it didn't work!!"
end
end
module M
def m
puts "it worked!"
end