- A
secret
byte you want to read is stored at inaccessible memory locationpriv_mem
. - The sender triggers an access exception by attempting to read
priv_mem
. - Due to CPU optimization (out-of-order execution), the load of
secret
frompriv_mem
and the use of its value in (4) and (5) below may execute before the exception is triggered. - Calculate an
offset
into a known arrayprobe
by multiplyingsecret
by the width of a cache line (or whatever block size the CPU typically fetches, like a 4096-byte page). This guarantees each of those 256 possible offsets will cache separately. - Load
probe[offset]
, which causes the CPU to cache exactly one chunk of of our array, populating one cache line. - The exception finally triggers, clearing the modified registers...but cached data is not excised.
- Iterate over all 256 offsets into
probe
to find out which one loads fast. You've determined the value ofsecret
.
This file contains hidden or 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
gem install rails | |
rails new foo | |
cd foo | |
rails generate controller welcome | |
cat <<EOT >> app/views/welcome/index.html.erb | |
<h2>Hello World</h2> | |
<p> | |
The time is now: <%= Time.now %> | |
</p> |
This file contains hidden or 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
git clone https://github.com/codetriage/codetriage | |
cd codetriage | |
bundle install | |
cp config/database.example.yml config/database.yml | |
NO_BOOTSNAP=1 bin/rake db:create db:schema:load db:seed | |
NO_BOOTSNAP=1 RAILS_ENV=production RAILS_SERVE_STATIC_FILES=1 RAILS_LOG_TO_STDOUT=1 bundle exec derailed exec perf:test | |
# Runs 5,000 requests against homepage | |
# output is in the form of Benchmark.benchmark | |
13.233374 0.872513 14.143397 ( 19.059944) |
This file contains hidden or 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
class FBGroupMemberRemover { | |
constructor() { | |
this.adminText = 'Admin'; | |
this.removeMemberModalHeadingText = 'Remove Member'; | |
this.memberElementSelector = '[data-name="GroupProfileGridItem"]'; | |
this.memberContextMenuSelector = 'button[aria-label="Member Settings"]'; | |
this.removeMemberButtonSelector = 'a[data-testid="leave_group"]' | |
this.removalOptions = { |
This file contains hidden or 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 "active_support" | |
require "active_support/core_ext/string/output_safety" | |
require "objspace" | |
def assert_same_object(x, y) | |
raise unless x.object_id == y.object_id | |
end | |
def assert_not_same_object(x, y) | |
raise unless x.object_id != y.object_id |
This file contains hidden or 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
module IncDec | |
# Mostly copied from RSpec::Matchers::BuiltIn | |
class ChangeDetails | |
attr_reader :actual_before, :actual_after | |
def initialize(matcher_name, receiver=nil, message=nil, &block) | |
if receiver && !message | |
raise( | |
ArgumentError, | |
"`#{matcher_name}` requires either an object and message " \ |
This file contains hidden or 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/python | |
# to try this you'll need to edit in the name of your ruby binary and install bcc-tools | |
# bcc installation instructions are at https://github.com/iovisor/bcc/blob/master/INSTALL.md | |
from __future__ import print_function | |
from bcc import BPF | |
from time import sleep | |
import os | |
# load BPF program |
This file contains hidden or 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 'minitest/autorun' | |
class X < Minitest::Test | |
def make_lambda b | |
->(z) { b[:finalize] = true } | |
end | |
def test_finalizer | |
hash = {} | |
make_finalizer = ->() { |
Enter this in the search box along with your search terms:
Get all gists from the user santisbon.
user:santisbon
Find all gists with a .yml extension.
extension:yml
Find all gists with HTML files.
language:html
This file contains hidden or 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
module TreyTyping | |
def method_added(name) | |
m = instance_method(name) | |
file, line = m.source_location | |
types = RubyVM::InstructionSequence.disasm(m).lines.slice_before { |l| l['checkkeyword'] }.to_a.drop(1).map { |lines| Object.const_get lines[3].split.last[1..-1] } | |
return if file == __FILE__ && line == 1+__LINE__ | |
define_method name do |*args, **kws| | |
kws.zip(types).each do |(name, value), type| | |
next if type === value | |
raise TypeError, "#{name} should be a #{type}" |