Skip to content

Instantly share code, notes, and snippets.

View cpuguy83's full-sized avatar
🐶

Brian Goff cpuguy83

🐶
View GitHub Profile
@cpuguy83
cpuguy83 / buildfile.go
Created December 27, 2013 16:53
Add support for multiple ENV key/values in one line
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 December 30, 2015 16:09
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)
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 December 30, 2015 03:48
Custom Chef bootstrap for Windows
#!/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"
@cpuguy83
cpuguy83 / partial_docekrfile
Created November 21, 2013 19:51
Docker long string
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 October 28, 2013 16:35
call ohai from chef directly
require 'ohai'
o = Ohai::System.new
o.all_plugins
node_name o[:macaddress].split(":").join
@cpuguy83
cpuguy83 / crash1
Created October 17, 2013 14:05
Rbx 2.0.0 crash with sidekiq
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]
@cpuguy83
cpuguy83 / sidekiqer.rb
Created October 10, 2013 20:33
Run Sidekiq in your main process
require 'sidekiq/cli'
require 'sidekiq/launcher'
module Sidekiqer
Sidekiq = ::Sidekiq.dup
module Sidekiq
CLI = ::Sidekiq::CLI.dup
Launcher = ::Sidekiq::Launcher.dup
::Sidekiq.send(:remove_const, :CLI)
@cpuguy83
cpuguy83 / poller.coffee
Last active December 24, 2015 23:59
Poll returns immediately after the page is loaded for some reason... any ideas?
@Poller =
delay: (ms, func) -> setTimeout func, ms
poll: (url,time)->
@schedulePoll(url, time)
$.getScript(url)
schedulePoll: (url, time=30000) ->
poller = @delay(time, =>@poll(url, time))
$(document).on 'page:fetch', =>
clearTimeout(poller)
@cpuguy83
cpuguy83 / clock.rb
Last active December 24, 2015 10:18
Running clockwork in a separate process is for suckers...
module MyApp
class Clock
include Celluloid
include Clockwork
require_relative '../clockwork'
end
end
@cpuguy83
cpuguy83 / gist:6518667
Created September 11, 2013 02:26
actor crash on terminate
Celluloid::DeadActorError: attempted to call a dead actor
/Users/bgoff/.gem/ruby/2.0.0/bundler/gems/celluloid-02e3882c1e55/lib/celluloid/proxies/sync_proxy.rb:23:in `method_missing'
/Users/bgoff/dev/monitor/agent/lib/agent/worker.rb:20:in `post_run'
/Users/bgoff/dev/monitor/agent/lib/agent/worker.rb:12:in `perform'
/Users/bgoff/.gem/ruby/2.0.0/bundler/gems/celluloid-02e3882c1e55/lib/celluloid/calls.rb:25:in `public_send'
/Users/bgoff/.gem/ruby/2.0.0/bundler/gems/celluloid-02e3882c1e55/lib/celluloid/calls.rb:25:in `dispatch'
/Users/bgoff/.gem/ruby/2.0.0/bundler/gems/celluloid-02e3882c1e55/lib/celluloid/calls.rb:67:in `dispatch'
/Users/bgoff/.gem/ruby/2.0.0/bundler/gems/celluloid-02e3882c1e55/lib/celluloid/actor.rb:322:in `block in handle_message'
/Users/bgoff/.gem/ruby/2.0.0/bundler/gems/celluloid-02e3882c1e55/lib/celluloid/actor.rb:416:in `block in task'
/Users/bgoff/.gem/ruby/2.0.0/bundler/gems/celluloid-02e3882c1e55/lib/celluloid/tasks.rb:55:in `block in initialize'