Skip to content

Instantly share code, notes, and snippets.

@stevendanna
stevendanna / pipe.c
Created March 30, 2014 18:18
Basic pipe implementation
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <strings.h>
int main(int argc, char *argv[]) {
int pipefd[2];
pid_t cpid1;
pid_t cpid2;
@stevendanna
stevendanna / daemon.rb
Last active October 18, 2018 13:48
"Old School" Ruby Daemon Example Code
#!/usr/bin/env ruby
# What does getrlimit tell us?
# What are we doing here and why?
# If we are on linux, is there a better alternative?
(3).upto(Process.getrlimit(Process::RLIMIT_NOFILE)[0]) do |n|
begin
if(fd = File.for_fd(n))
puts "Closing FD #{n}"
fd.close
> cat providers/default.rb
action :start do
ruby_block "foo" do
true
true
true
true
true
true
true
@stevendanna
stevendanna / gist:5582647
Last active December 17, 2015 08:49
Foodcritic Exceptions Explanation

Explanation of Foodcritic Exceptions

The following are brief justifications of the foodcritic exceptions being used in the first pass of foodcritic bug-bashing. In most cases we are excluding rules to make the amount of work more manageable for this first pass. In a few cases, the core cookbook team doesn't think that a rule is appropriate for the Opscode community cookbooks.

FC003 Check whether you are running with chef server before using server-specific features

Ensuring that a cookbook works without a Chef Server is often more work than a simple if statement around a call to search. The READMEs for these cookbooks should clearly state that they currently require a Chef Server and adding conditionals throughout a recipe to also account for this limitation often only serves to clutter the recipe.

In the long run, we welcome better support for chef-solo-style use cases.

@stevendanna
stevendanna / gist:5552324
Last active November 30, 2022 07:02
A small chef-solo example

An example cookbook directory

sdanna@gaius ~/tmp/example > tree
.
├── cookbooks
│   └── foobar
│       ├── CHANGELOG.md
│       ├── README.md
│       ├── attributes
│       ├── definitions

This is a test

bash -c '
<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>
exists() {
if command -v $1 &>/dev/null
then
return 0
else
return 1
fi
@stevendanna
stevendanna / gist:4191403
Created December 2, 2012 22:48
Large, distracting error message produced by minitest-handler-cookbook
[ubuntu-10.04] [2012-11-27T21:16:49+00:00] INFO: Processing directory[/var/chef/minitest/test-kitchen] action create (minitest-handler::default line 50)
[ubuntu-10.04] [2012-11-27T21:16:49+00:00] INFO: directory[/var/chef/minitest/test-kitchen] created directory /var/chef/minitest/test-kitchen
[ubuntu-10.04] [2012-11-27T21:16:49+00:00] INFO: Processing cookbook_file[tests-test-kitchen-default] action create (minitest-handler::default line 53)
[ubuntu-10.04] [2012-11-27T21:16:49+00:00] ERROR: cookbook_file[tests-test-kitchen-default] (minitest-handler::default line 53) had an error: Cookbook 'test-kitchen' (1.0.0) does not contain a file at any of these locations:
[ubuntu-10.04] files/ubuntu-10.04/tests/minitest/default_test.rb
[ubuntu-10.04] files/ubuntu/tests/minitest/default_test.rb
[ubuntu-10.04] files/default/tests/minitest/default_test.rb; ignore_failure is set, continuing
[ubuntu-10.04]
[ubuntu-10.04] ================================================================================
runit_action = env["runit_enable"]["couchdb"] ? :enable : :disable
runit_service "couchdb" do
action runit_action
end
template "#{couch_etc}/local.ini" do
source "local.ini.erb"
group "root"
owner "root"
variables(:couchdb_listen_port => node[:couchdb][:listen_port],
<% unless @chef_requires.empty? %>
<%= @chef_requires.inspect %>.each do |lib|
begin
require lib
rescue LoadError
Chef::Log.warn "Failed to load #{lib}. This should be resolved after a chef run."
end
end
<% end %>