Last active
August 29, 2015 14:21
-
-
Save eddieantonio/1dcbcc8f6ed53e1a4b63 to your computer and use it in GitHub Desktop.
I don't know why.
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 | |
# The Xcode prefix for C stuff. | |
PREFIX = `xcrun --show-sdk-path`.chomp | |
# Ze masterpiece. | |
def have_a_nap | |
puts "Le 💤 " | |
pause | |
end | |
def fire_ze_missiles | |
puts "🔥 ze 🚀" | |
end | |
# wtf...? | |
def pause | |
# See: man 2 sigsuspend | |
num = find_syscall :sigsuspend | |
sigmask = 0 | |
syscall(num, sigmask) | |
end | |
def find_syscall(name) | |
filename = File.join PREFIX, '/usr/include/sys/syscall.h' | |
line = File.open filename do | file | | |
file.grep(/#{name}/).first | |
end | |
# Don't use #to_i so that conversion can fail instead of returning 0. | |
Integer(line[/\s\d+/]) | |
end | |
begin | |
have_a_nap | |
ensure | |
fire_ze_missiles | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment