Skip to content

Instantly share code, notes, and snippets.

View glennpratt's full-sized avatar

Glenn Pratt glennpratt

View GitHub Profile
#!/bin/bash
set -ex
# Reproduce bundler issue:
# https://github.com/bundler/bundler/issues/4373
rm -rf /tmp/bundler-GH-4373
mkdir -p /tmp/bundler-GH-4373
cd /tmp/bundler-GH-4373
#!/bin/bash
set -ex
# Reproduce bundler bug:
# https://github.com/bundler/bundler/issues/4144
rm -rf /tmp/bundler-GH-4144
mkdir -p /tmp/bundler-GH-4144
cd /tmp/bundler-GH-4144
require 'json-schema'
require 'json-schema/validator'
require 'thread'
require 'thwait'
schema = {
"$schema" => "http://json-schema.org/draft-03/schema#",
"properties" => {
"a" => {"type" => "string", "required" => true},
"b" => {"type" => "string"}
@glennpratt
glennpratt / no_require_thread.rb
Created May 13, 2015 21:48
no require in threads
module Kernel
alias_method :_aq_original_require, :require
def require(name)
fail 'No loading in threads!' if Thread.main != Thread.current
_aq_original_require(name)
end
end
@glennpratt
glennpratt / filter_reduce.rb
Last active August 29, 2015 14:15
filter git repo to only files interested in by regex
#!/usr/bin/env ruby
# filter git repo to only files interested in by regex
#
# Get all files ever in the repo.
# git log --pretty=format: --name-only --diff-filter=A | sort -u > list.txt
# ruby filter_reduce.rb | tr '\r\n' ' ' > reduced_list.txt
# git filter-branch --index-filter "git rm -rfq --cached --ignore-unmatch $(cat reduced_list.txt)" --prune-empty
list = []
@glennpratt
glennpratt / flamegraph.sh
Created January 21, 2015 22:43
Puppet with stackprof
stackprof --stackcollapse stackprof.dump | ~/Code/FlameGraph/flamegraph.pl > blah.html; open blah.html
[1] pry(main)> class Foo
[1] pry(main)* private def bar; end
[1] pry(main)* def baz; end
[1] pry(main)* end
=> :baz
[2] pry(main)> Foo.new.baz
=> nil
[3] pry(main)> Foo.new.bar
NoMethodError: private method `bar' called for #<Foo:0x007fc34419c6c0>
from (pry):6:in `__pry__'
[1] boris> $things = ['foo' => 'bar', 'baz' => 'qux'];
→ array(
'foo' => 'bar',
'baz' => 'qux'
)
[2] boris> array_map(function($thing) { return "{$thing}s";}, $things);
→ array(
'foo' => 'bars',
'baz' => 'quxs'
)
Thread::spawn(move|| {
let mut eviction_lifo: Vec<(Vec<u8>, Timespec)> = vec![];
let mut timer = Timer::new().unwrap();
let validity = Duration::seconds(5);
loop {
let timeout = if eviction_lifo.len() > 1 {
let (_, arrival) = eviction_lifo[0];
let eviction_time = arrival + validity;
timer.oneshot(eviction_time - get_time())
<?php
function testThrows() {
$this->assertThrows(function() {
// throw new \Exception('BAH!');
}, 'Exception', "/BAH/");
}
function testThrowsA() {
$this->assertThrows(function() {
throw new \RuntimeException('BAH!');
}, 'InvalidArgumentException');