Skip to content

Instantly share code, notes, and snippets.

View pushrax's full-sized avatar
🔬

Justin Li pushrax

🔬
View GitHub Profile
# frozen_string_literal: true
require 'memory_profiler'
def assert_equal(a, b)
puts "#{a} != #{b} at #{caller.last}" if a != b
end
def assert(allocated_memsize: nil, allocated_objects: nil)
report = MemoryProfiler.report { yield }
require 'benchmark_driver'
require 'memory_profiler'
def assert_equal(a, b); raise "#{a} != #{b}" if a != b; end
report = MemoryProfiler.report { [:a, :b].include?(:a) }
assert_equal 1, report.total_allocated
Benchmark.driver do |x|
x.prelude(<<~RUBY)
require 'benchmark_driver'
require 'memory_profiler'
def assert_equal(a, b); raise "#{a} != #{b}" if a != b; end
# Great!
a = 1
report = MemoryProfiler.report { [a, 2].max }
assert_equal 0, report.total_allocated
// gcc -O2 function_call_overhead.c
#include <stdio.h>
#include <inttypes.h>
#define concat_lower_uint32(high, low) (high = (high << 32) | low);
int __attribute__ ((noinline)) foo() {
return 42;
}
void aabbIntersectFast(vec3 P, vec3 R, vec3 invR, vec3 aabb[2], out float tmin, out float tmax)
{
vec3 t1 = (aabb[0] - P) * invR;
vec3 t2 = (aabb[1] - P) * invR;
vec3 tmins = min(t1, t2);
vec3 tmaxs = max(t1, t2);
tmin = max(max(tmins.x, tmins.y), tmins.z);
tmax = min(min(tmaxs.x, tmaxs.y), tmaxs.z);
}
#!/bin/sh
readelf -x .text $1 | sed '1,2d' | cut -d ' ' -f 4,5,6,7 | sed 's/ //g' | sed 's/\(..\)/\\x\1/g' | tr -d '\n'
directories="include src"
revs=$(git rev-list --all | awk '{printf "%s\n%s ", $0, $0}' | sed '1d' | sed '$d')
echo "$revs" \
| xargs -n2 -L1 bash -c "git --no-pager diff \$1 \$0 --shortstat -- $directories" \
| awk '{adds+=$4; dels+=$6} END {print adds " insertions"; print dels " deletions"}'

Keybase proof

I hereby claim:

  • I am pushrax on github.
  • I am pushrax (https://keybase.io/pushrax) on keybase.
  • I have a public key whose fingerprint is E1F4 5158 16CF 7C2A 189B 816C 33B7 1578 9EE9 E9DC

To claim this, I am signing this object:

@pushrax
pushrax / gist:c47efd7b4b704f99bfce
Created February 14, 2015 19:20
Create a MySQL dump to bootstrap a replication slave
#!/bin/bash
DATE=`date +%Y-%m-%d.%H%M%S`
echo "Starting MySQL dump for replication $DATE"
mysqldump -u root -p --single-transaction --master-data --databases my_app --verbose | gzip -c > "mysql.master.$DATE.sql.gz"
echo "Dump complete"
replaceCurrentRoute: (params) ->
params = Batman.extend({}, params)
# ...
currentPageParams = @routableParams(params) # loads some more data (controller and action)
# ...
path = Shopify.get('dispatcher').pathFromParams(currentPageParams)
return unless path