Skip to content

Instantly share code, notes, and snippets.

🌴
On vacation

Brian Goff cpuguy83

🌴
On vacation
Block or report user

Report or block cpuguy83

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@cpuguy83
cpuguy83 / operating_hour.rb
Created Jan 23, 2014
Time zone parsing from local time
View operating_hour.rb
class OperatingHour
class MissingTimeZoneError < StandardError; end
class MissingTimeStringError < StandardError; end
attr_reader :time_string, :time_zone
def initialize(opts={})
@time_string = opts[:time_string]
@time_zone = opts[:time_zone]
end
View gist:8566438
merged_images = left.images.with_index.collect do |image, index|
compare(left.images[index], right.images[index], index)
end
View Dockerfile
FROM ubuntu
# some awesome stuff with mysql
VOLUME /var/lib/mysql
--- End Dockerfile ---
docker build -t my/awesome_mysql_stuff
@cpuguy83
cpuguy83 / buildfile.go
Created Dec 27, 2013
extract functionality for building CMD and ENTRYPOINT
View buildfile.go
func (b *buildFile) BuildCmdFromJson(args string) []string {
var cmd []string
if err := json.Unmarshal([]byte(args), &cmd); err != nil {
utils.Debugf("Error unmarhsalling: %s, setting %s to /bin/sh -c", err)
cmd = []string{"/bin/sh", "-c", args}
}
return cmd
}
func (b *buildFile) CmdCmd(args string) error {
@cpuguy83
cpuguy83 / buildfile.go
Created Dec 27, 2013
Add support for multiple ENV key/values in one line
View buildfile.go
func (b *buildFile) CmdEnv(args string) error {
var env map[string]string
if err := json.Unmarshal([]byte(args), &env); err != nil {
env = []string{args}
}
if err := b.commit("", env, fm.Sprintf("ENV %v", env)); err != nil {
return err
}
@cpuguy83
cpuguy83 / client.rb
Last active Dec 30, 2015
Crude demo of async I/O using Celluloid::IO Actor with external class utilizing Celluoid::IO::TCPSocket. No need for GIL-less Ruby for this to work (except perhaps on the server, which isn't using evented IO for this demo)
View client.rb
require 'celluloid'
require 'celluloid/io'
class MySocket
def go
@sock ||= Celluloid::IO::TCPSocket.open('localhost', 2000)
puts "#{@sock.read}"
end
end
@cpuguy83
cpuguy83 / chef_windows_bootstrap.rb
Last active Dec 30, 2015
Custom Chef bootstrap for Windows
View chef_windows_bootstrap.rb
#!/usr/bin/env ruby
require 'winrm'
IP=ARGV[0]
USER=ARGV[1]
endpoint = "http://#{IP}:5985/wsman"
winrm = WinRM::WinRMWebService.new endpoint, :plaintext, user: USER, pass: 'secret', basic_auth_only: true
winrm.set_timeout 1800
installer_file = "c:\\Users\\#{USER}\\Downloads\\chef_client.msi"
View partial_docekrfile
RUN /bin/echo -e "PassEnv DB_PORT_3306_TCP_ADDR\n\
PassEnv DB_PORT_3306_TCP_DATABASE\n\
PassEnv DB_PORT_3306_TCP_USER\n\
PassEnv DB_PORT_3306_TCP_PASS\n\
PassEnv LDAP_PORT_389_TCP_ADDR\n\
PassEnv LDAP_PORT_689_TCP_ADDR\n\
PassEnv LDAP_BASEDN\n\
PassEnv LDAP_UID\n\
PassEnv LDAP_SEARCH_USER\n\
PassEnv LDAP_SEARCH_PASS\n\
@cpuguy83
cpuguy83 / set_node_name.rb
Created Oct 28, 2013
call ohai from chef directly
View set_node_name.rb
require 'ohai'
o = Ohai::System.new
o.all_plugins
node_name o[:macaddress].split(":").join
@cpuguy83
cpuguy83 / crash1
Created Oct 17, 2013
Rbx 2.0.0 crash with sidekiq
View crash1
Rubinius Crash Report #rbxcrashreport
Error: signal �SIGSEGV
[[Backtrace]]
ruby[0x81bd52a]
[0x4001d400]
/lib/tls/i686/cmov/libc.so.6(index+0x63)[0x40233db3]
/lib/tls/i686/cmov/libnss_dns.so.2(_nss_dns_gethostbyname3_r+0xb6)[0x43ce6b66]
/lib/tls/i686/cmov/libnss_dns.so.2(_nss_dns_gethostbyname2_r+0x4b)[0x43ce6f2b]
You can’t perform that action at this time.