Skip to content

Instantly share code, notes, and snippets.

View mattconnolly's full-sized avatar

Matt Connolly mattconnolly

View GitHub Profile
@mattconnolly
mattconnolly / gist:7804176
Created December 5, 2013 12:01
Upgrading pkgin repository for a SmartOS zone.

Upgrading SmartOS zone

Make a snapshot first! Upgrading from 2013Q1 to 2013Q3 because I needed newer nginx.

Update pkgin repository

edit the files at:

/opt/local/etc/pkg_install.conf

/opt/local/etc/pkgin/repositories.conf

@mattconnolly
mattconnolly / gist:8212674
Created January 1, 2014 23:16
sshkit within not applied to non-mapped commands
require 'sshkit'
require 'sshkit/dsl'
on 'example.com', user: 'matt' do
within('current') do
puts "this works as expected:"
puts capture :ls
puts "this does not get executed in the 'current' directory:"
puts capture 'ls -l'
end
@mattconnolly
mattconnolly / gist:8213718
Last active January 1, 2016 22:59
sshkit errors running rake..
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:
class Model < ParentModel
include Foo::Bar
extend Bar::Baz
acts_as_authentic
dsl_specific_flags
module InternalModule
...
end
@mattconnolly
mattconnolly / nested_load_and_authorize.rb
Last active August 29, 2015 13:56
A module with code to hierarchically load and authorise resources in a before_filter.
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
@mattconnolly
mattconnolly / gist:9905829
Created April 1, 2014 01:09
vmadm get for windows zone.
{
"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
mattconnolly / gist:9907062
Created April 1, 2014 03:17
A let method to memoize values that could be nil.
module Let
def let(name, &block)
ivar = "@#{name}".to_sym
if instance_variable_defined?(ivar)
instance_variable_get(ivar)
else
instance_variable_set(ivar, instance_eval(&block))
end
@mattconnolly
mattconnolly / gist:11166138
Created April 22, 2014 05:23
passing blocks to a block - rspec fun.
context "deep copy some record" do
it do
duplicate = call_the_copy_method(original)
check_same = lambda { |&block| expect(block.call(duplicate)).to eq(block.call(original)) }
check_same.call { |x| x.name }
check_same.call { |x| x.list_of_shared_items }
check_same.call { |x| x.list_of_copied_items.map { |item| item.name } }
@mattconnolly
mattconnolly / spec_helper.rb
Last active August 29, 2015 14:00
spec_helper - clear the test log before each test run.
# 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
mattconnolly / gist:e188fdb1049872ec428d
Created May 19, 2014 12:10
setup iscsi share on smartos
#!/bin/bash -x
# based on: http://superuser.com/questions/386506/hosting-iscsi-on-smartos
GROUPNAME=iscsi-1
TARGETNAME=iqn.2010-08.org.illumos:02:$GROUPNAME
LOCAL_ADDRESS=192.168.1.2
svcadm enable stmf
svcadm enable -r svc:/network/iscsi/target:default