Skip to content

Instantly share code, notes, and snippets.


Matt Connolly mattconnolly

View GitHub Profile
mattconnolly / main.m
Created Jun 10, 2016
Dispatch_get_specific sees only the top queue
View main.m
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
dispatch_queue_t qa = dispatch_queue_create("a", DISPATCH_QUEUE_SERIAL);
dispatch_queue_t qb = dispatch_queue_create("b", DISPATCH_QUEUE_SERIAL);
static void* key = &key;
dispatch_queue_set_specific(qa, key, (void*)1, NULL);
mattconnolly / gist:deda874b2f7259db830d
Created Aug 26, 2014
Connecting another ZFS pool to do a sync
View gist:deda874b2f7259db830d
# The si3124 card doesn't seem to like drives being hot plugged, so manually deactivate the ports
cfgadm -x sata_port_deactivate sata1/0 sata1/1 sata1/2 sata1/3
# enable hot plug service
svcadm enable hotplug
# connect the drives, and:
cfgadm -x sata_port_activate sata1/0 sata1/1 sata1/2 sata1/3
# they should connect and configure automatically now, if not:
cfgadm -c configure sata1/0
cfgadm -c configure sata1/1
cfgadm -c configure sata1/2
mattconnolly / gist:e188fdb1049872ec428d
Created May 19, 2014
setup iscsi share on smartos
View gist:e188fdb1049872ec428d
#!/bin/bash -x
# based on:
svcadm enable stmf
svcadm enable -r svc:/network/iscsi/target:default
mattconnolly / spec_helper.rb
Last active Aug 29, 2015
spec_helper - clear the test log before each test run.
View spec_helper.rb
# near the top of spec_helper.rb
# clear the test log file before we start.
log_file = Rails.root.join("log/test.log")
File.truncate(log_file, 0) if File.exist?(log_file)
mattconnolly / gist:11166138
Created Apr 22, 2014
passing blocks to a block - rspec fun.
View gist:11166138
context "deep copy some record" do
it do
duplicate = call_the_copy_method(original)
check_same = lambda { |&block| expect( eq( } { |x| } { |x| x.list_of_shared_items } { |x| { |item| } }
mattconnolly / gist:9907062
Created Apr 1, 2014
A let method to memoize values that could be nil.
View gist:9907062
module Let
def let(name, &block)
ivar = "@#{name}".to_sym
if instance_variable_defined?(ivar)
instance_variable_set(ivar, instance_eval(&block))
mattconnolly / gist:9905829
Created Apr 1, 2014
vmadm get for windows zone.
View gist:9905829
"zonename": "17a296aa-012c-49bb-a10a-e6d48a06093d",
"autoboot": true,
"brand": "kvm",
"limit_priv": "default,-file_link_any,-net_access,-proc_fork,-proc_info,-proc_session",
"v": 1,
"create_timestamp": "2013-08-09T04:26:57.316Z",
"cpu_shares": 100,
"zfs_io_priority": 100,
"max_lwps": 2000,
mattconnolly / nested_load_and_authorize.rb
Last active Aug 29, 2015
A module with code to hierarchically load and authorise resources in a before_filter.
View nested_load_and_authorize.rb
module NestedLoadAndAuthorize
def load_and_authorize(name, options={})
@_through_stack ||= []
# only touch can can if the instance variable is nil
resource = instance_variable_get("@#{name}")
if resource.nil?
# apply if, only and except behaviours just is if this was done by before_filter
proceed = true
View best_model.rb
class Model < ParentModel
include Foo::Bar
extend Bar::Baz
module InternalModule
mattconnolly / gist:8213718
Last active Jan 1, 2016
sshkit errors running rake..
View gist:8213718
MattbookPro:sshkit matt$ ruby -v
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-darwin13.0.0]
MattbookPro:sshkit matt$ rake --version
rake, version 10.1.1
MattbookPro:sshkit matt$ vagrant --version
Vagrant 1.4.2
MattbookPro:sshkit matt$ uname -a
Darwin MattbookPro.local 13.0.2 Darwin Kernel Version 13.0.2: Sun Sep 29 19:38:57 PDT 2013; root:xnu-2422.75.4~1/RELEASE_X86_64 x86_64
MattbookPro:sshkit matt$ vagrant status
WARN: Unresolved specs during Gem::Specification.reset: