Skip to content

Instantly share code, notes, and snippets.

View tarcieri's full-sized avatar

Tony Arcieri tarcieri

View GitHub Profile
use std::marker::PhantomData;
pub trait MyTrait<'a> {
fn new() -> Self;
fn derpity(&'a self);
}
struct Derp;
impl<'a> MyTrait<'a> for Derp {
@tarcieri
tarcieri / lifetime_hell.rs
Created October 31, 2016 02:11
Generics, traits, and lifetimes, oh my!
pub trait MyTrait<'a> {
fn foo(n: &'a i32);
}
struct Derp;
impl<'a> MyTrait<'a> for Derp {
fn foo(n: &'a i32) {
}
}
@tarcieri
tarcieri / example.fling
Created June 14, 2015 21:15
Example fling configuration
-----BEGIN ENCRYPTED FLING CONFIGURATION-----
FTTKvMlxv0rs0ACBydlXFHZHYmKQtRUN6PlwI4ZW5gYXV57u/zO90KRD0Nn2
Buj3/CsJGgbWx5fM2X8eGJKRryuZ7eNSm9C0doq2lRikrqV+gsBNqa0e/lkc
P4b8q7GfZyralBwvMTBnoOhmUtNPM1orafFIhSYI6wN2ZKpnZgAar9NQRkxZ
LJWTvqzlWVdZ6ranCzmRJhAClr7822GylXIIeOycpm8EC8ESRRmiaYMJMPxe
3BBlk1KuTTnU4WVDbJVW/9f9+zcZViZDUTyNt5LougR8LLC8FbN1p+UiLSWx
CZA940Mo/DVWN29uJL8FitY8mJDZEJ8/OJr/5zptzAFaj0zhs+uLafjvI96D
------END ENCRYPTED FLING CONFIGURATION------
@tarcieri
tarcieri / gist:95f41af8751e765f5ac2
Created April 29, 2015 00:45
rails-assets.org's 4096-bit DH breaks JRuby :(
Using /Users/tonyarcieri/.rvm/gems/jruby-1.7.19
$ gem install rails-assets-jruby --source "https://rails-assets.org"
ERROR: While executing gem ... (Java::JavaLang::RuntimeException)
Could not generate DH keypair
$ gem install irust
Successfully installed irust-1.2.0
Parsing documentation for irust-1.2.0
Done installing documentation for irust after 0 seconds
1 gem installed
$ irust
Using rustc 1.0.0-nightly (083b8a404 2015-04-05) (built 2015-04-04)
irust> let mut nums = [1,2,3,4,5,6];
()
irust> nums
@tarcieri
tarcieri / gist:6bf23d9b69b499b3a313
Created March 26, 2015 22:23
Ruby HTTP client benchmark
+--------------------------+-----------+
| tach | total |
+--------------------------+-----------+
| curb (persistent) | 2.519088 |
+--------------------------+-----------+
| em-http-request | 2.731645 |
+--------------------------+-----------+
| Typhoeus | 2.851911 |
+--------------------------+-----------+
| StreamlyFFI (persistent) | 2.853786 |
@tarcieri
tarcieri / hostname_verifier.rb
Last active August 29, 2015 14:17
Strawman hostname verifier that doesn't rely on regular expressions
def verify_domain_component(san_component, domain_component)
parts = san_component.split("*", -1)
return false if parts.size > 2
return san_component == domain_component if parts.size == 1
domain_component.start_with?(parts[0]) && domain_component.end_with?(parts[1])
end
fail unless verify_domain_component("foo", "foo")
fail unless verify_domain_component("f*", "foo")
@tarcieri
tarcieri / bytestring_problem.rs
Created March 20, 2015 22:28
Can't figure out how to do this with a bytestring...
const THING: [u8; 4] = [0x61, 0x62, 0x63, 0x64];
// replace ^^^ with a bytestring
// const THING: [u8; 4] = b"abcd"[..4];
fn main() {
// NO COPYING ALLOWED HERE PLZTKS
i_need_a_four_byte_array(THING)
}
@tarcieri
tarcieri / redis_interleave_bug.rb
Last active August 29, 2015 14:13
Redis request interleaving repro (Ruby 2.1+)
require 'redis'
require 'timeout'
redis = Redis.new
redis.set('chunky', 'bacon')
res_a = nil
res_b = nil
count = 0
outer_count = 0
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2
mQENBFS2LA0BCACy/N3h9D5bK5Q5Ym4qOLoYc/qD4ttJ/icXtrvy3K5Kp2x8rwTm
fum6R4yaia2yeSeMvR0UZAIkOz2Pf5gyBc1x0A1UIyAxnkWTndL7GjxNP/bMoumY
otG3wCqf+QQPAqj5/X0k6jhVARRjRJaRaNQrj7mdboD2SJSxrIr0pw1JpBCWaAc+
ySuLwhaV1BjIxnS3sPztaWEgKth0ipjwlcOHskSJ1kAbjrnjicnw/D18EY9JBzJ4
yxj7i0JcTvK4F0we4l3MJ2kFjPLhk6pV4t3oTHZV7yUApTUnugPmDDiLH5YRjlEw
nxvHtOzGDM2CODn5PqX2nQ3T10srLMHNM8ErABEBAAG0IFRvbnkgQXJjaWVyaSA8
YmFzY3VsZUBnbWFpbC5jb20+iQE/BBMBAgApBQJUtiwNAhsDBQkSzAMABwsJCAcD