Skip to content

Instantly share code, notes, and snippets.

View will's full-sized avatar
🆒
ه҈ͣفͤ҈ͥ҉ͦ҈ͧ҉ͨ҈ͩ҉ͪ҈ͫ҉ͬ҈ͭ҉ͮ҈ͯ҉ͨ҈ͬ҉ͧ҈ͣ҉ͨ҈ͧ҉ͯ҈ͮ҉ͭ҈ͤ҉ͦ҈ͥ҉ͧ҈ͩ҉ͭ҈ͨ҉ͣ҈ͪ҉ͧ҈ͭ҉ͩ҈ͤ҉ͮ҈ͯ҉ͬ҈

Will Leinweber will

🆒
ه҈ͣفͤ҈ͥ҉ͦ҈ͧ҉ͨ҈ͩ҉ͪ҈ͫ҉ͬ҈ͭ҉ͮ҈ͯ҉ͨ҈ͬ҉ͧ҈ͣ҉ͨ҈ͧ҉ͯ҈ͮ҉ͭ҈ͤ҉ͦ҈ͥ҉ͧ҈ͩ҉ͭ҈ͨ҉ͣ҈ͪ҉ͧ҈ͭ҉ͩ҈ͤ҉ͮ҈ͯ҉ͬ҈
View GitHub Profile
# Now
irb(main):020:0> Benchmark.measure { User.all.group_by { |u| u.org }; nil }
=> #<Benchmark::Tms:0x005609082d33b0 @label="", @real=3.7103141639381647, @cstime=0.0, @cutime=0.0, @stime=0.18999999999999995, @utime=1.5, @total=1.69>
# eager loading orgs
irb(main):022:0> Benchmark.measure { User.eager(:org).all.group_by { |u| u.org }; nil }
=> #<Benchmark::Tms:0x0056090a1ccfa0 @label="", @real=1.3611143808811903, @cstime=0.0, @cutime=0.0, @stime=0.040000000000000036, @utime=1.1799999999999997, @total=1.2199999999999998>
# eager loading orgs, not finding deleted users, and only getting needed columns
@will
will / metldown.c
Last active September 5, 2023 16:39
// copied from https://github.com/gkaindl/meltdown-poc/blob/master/meltdown.c
// flush_reload from https://github.com/defuse/flush-reload-attacks
// TSX from https://github.com/andikleen/tsx-tools
// dump_hex from https://gist.github.com/ccbrown/9722406
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
@will
will / spectre.c
Last active January 5, 2018 22:58 — forked from ErikAugust/spectre.c
Spectre example code
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <pthread.h>
#ifdef _MSC_VER
#include <intrin.h> /* for rdtscp and clflush */
#pragma optimize("gt",on)
#else
#include <x86intrin.h> /* for rdtscp and clflush */
@will
will / text_vs_binary.rb
Last active June 30, 2017 08:59
using binary result type for timestamptz and ruby pg
require "pg"
require "time"
PG_EPOCH = Time.gm(2000,1,1).to_i
conn = PG.connect
tm = PG::TypeMapByOid.new
tm.add_coder PG::BinaryDecoder::Integer.new(oid: 1184)
conn.type_map_for_results = tm
def parse_text(r)
@will
will / a.md
Created November 17, 2016 21:04
SameSite strict cookies in rails and pliny/sinatra

SameSite=strict cookies is another layer to help prevent CSRF attacts in newer browsers

Rails

(at least 5, no clue about earlier versions)

--- a/config/initializers/session_store.rb
+++ b/config/initializers/session_store.rb
@@ -1,3 +1,3 @@
@will
will / insecurerandom.rb
Created August 31, 2016 00:19
InsecureRandom benchmarks
# I wanted to make InsecureRandom.uuid to speed up specs, but
require 'securerandom'
require 'benchmark/ips'
Benchmark.ips do |x|
x.report("sec") { SecureRandom.random_bytes(16) }
x.report("rand") { Random::DEFAULT.bytes(16) }
end if ARGV[0] == '1'

Make it real

Ideas are cheap. Make a prototype, sketch a CLI session, draw a wireframe. Discuss around concrete examples, not hand-waving abstractions. Don't say you did something, provide a URL that proves it.

Ship it

Nothing is real until it's being used by a real user. This doesn't mean you make a prototype in the morning and blog about it in the evening. It means you find one person you believe your product will help and try to get them to use it.

Do it with style

@will
will / whatever.md
Last active May 22, 2016 18:36
swapping ps4 hdd protips
@will
will / bigq.cr
Last active April 16, 2016 06:54
# https://github.com/wbhart/mpir/blob/master/gmp-h.in#L262-L266
# https://gmplib.org/manual/Rational-Arithmetic.html#Rational-Arithmetic
require "spec"
require "big_int"
lib LibGMP
struct MPQ
_mp_num : MPZ
_mp_den : MPZ
require "./src/pg"
# require "../hexdump/hex.cr"
require "big_int"
struct Numeric
property ndigits
property weight
property sign
property dscale