Skip to content

Instantly share code, notes, and snippets.

View benoittgt's full-sized avatar
🏴

Benoit Tigeot benoittgt

🏴
View GitHub Profile
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>
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)
@poteto
poteto / FBGroupMemberRemover.js
Last active September 11, 2019 17:49
Delete everyone from your Facebook group! Thanks for the dark UX, FB
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 = {
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
@tcopeland
tcopeland / gist:22040ee4230bc531c04718aefdc64abe
Created February 12, 2018 05:25
increment decrement matcher
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 " \
#!/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
require 'minitest/autorun'
class X < Minitest::Test
def make_lambda b
->(z) { b[:finalize] = true }
end
def test_finalizer
hash = {}
make_finalizer = ->() {
@headius
headius / meltdown_in_a_nutshell.md
Last active July 27, 2018 13:43
How Meltdown Works

Algorithm

  1. A secret byte you want to read is stored at inaccessible memory location priv_mem.
  2. The sender triggers an access exception by attempting to read priv_mem.
  3. Due to CPU optimization (out-of-order execution), the load of secret from priv_mem and the use of its value in (4) and (5) below may execute before the exception is triggered.
  4. Calculate an offset into a known array probe by multiplying secret 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.
  5. Load probe[offset], which causes the CPU to cache exactly one chunk of of our array, populating one cache line.
  6. The exception finally triggers, clearing the modified registers...but cached data is not excised.
  7. Iterate over all 256 offsets into probe to find out which one loads fast. You've determined the value of secret.
@santisbon
santisbon / Search my gists.md
Last active July 19, 2025 15:46
How to search gists.

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

@JoshCheek
JoshCheek / trey_typing.rb
Created October 26, 2017 18:22
Trey Typing
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}"