Skip to content

Instantly share code, notes, and snippets.

View fxn's full-sized avatar

Xavier Noria fxn

View GitHub Profile
module ForkedSpecs
def forked_specs(*specs)
ActiveRecord::Base.clear_all_connections!
pids = []
specs.each do |spec|
pids << fork do
ActiveRecord::Base.establish_connection
spec.call
end
@fxn
fxn / back.html
Last active March 16, 2020 09:02
<div class="card"><div class="content">{{Back}}</div></div>
require 'test_helper'
class UserTest < ActiveSupport::TestCase
test "class names" do
uid = User.object_id
print "please modify the file and press ENTER "; gets
assert_equal uid, User.object_id
end
end
#!/bin/bash
docker container ls -a -q | xargs docker container rm
docker image ls -a -q | xargs docker image rm
docker volume ls -q | xargs docker volume rm
docker network ls -q --filter type=custom | xargs docker network rm
require "benchmark/ips"
Benchmark.ips do |x|
x.report("without TZ") do |n|
ENV["TZ"] = nil
i = 0
while i < n
Time.now
i += 1
@fxn
fxn / wdrift.c
Last active February 13, 2020 12:49
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
int main(void)
{
struct timeval now;
double seconds;
gettimeofday(&now, NULL);
@fxn
fxn / m.ex
Created October 17, 2017 06:56
defmodule M do
@x N.f()
end
find . -name '*.ex' -or -name '*.exs' | xargs perl -ni -le 'print unless /^\s*(\@doc|\@moduledoc) """/ ... /^\s*"""/'

Four solutions

I have worked first with the file downloaded to make sure I got the result right. Those drafts are not here.

After that we have four solutions:

  1. A simple one that fetches the entire payload in one request.
  2. An streamed one, same idea, but processing by chunks.
  3. A parallel approach that speeds up the download using HTTP range requests.
  4. A variant of the previous one that parallelizes the computation as well.