Skip to content

Instantly share code, notes, and snippets.

Maciej Pasternacki mpasternacki

Block or report user

Report or block mpasternacki

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
@mpasternacki
mpasternacki / override_print.py
Created Jun 8, 2012
Track down Python print statements that clutter your output.
View override_print.py
# Trace 'print' statement calls cluttering your test suite output.
#
# It is not that simple to track 'print' statement in Python 2.x - it
# cannot be monkey-patched itself, because it's not a function. So we
# override sys.stdout and check the backtrace when stdout is written
# to.
#
# The overload happens only if TRACE_PRINT environment variable is
# set. By default, only the offending file name and line number is
# printed; if TRACE_PRINT environment variable is set to 'traceback',
@mpasternacki
mpasternacki / 00-packages_builder.rb
Created May 29, 2012
Debian packaging continuous integration
View 00-packages_builder.rb
# Chef resources describing how to set up package repository server,
# simplified fromactual cookbook (not open sourced yet). Sets up apt
# repository in /srv/apt directory, with system user "apt-repo". Packages
# are GPG-signed to prevent apt-get from complaining on every install.
#
# Directory /srv/apt should be reachable to clients via http or other
# means. This is left as an exercise for the reader.
#
# For extra explanations, see:
# http://joseph.ruscio.org/blog/2010/08/19/setting-up-an-apt-repository/
@mpasternacki
mpasternacki / google-multilogin.scpt
Created Apr 28, 2012
AppleScript to consistently log into multiple Google Apps account in Safari
View google-multilogin.scpt
on js(jscpt)
set jscpt to "(function _l () {" & jscpt & "}());"
tell application "Safari" to do JavaScript jscpt in document 1
end js
on log_into_google(method, username, password)
tell application "Safari" to set URL of document 1 to "https://accounts.google.com/" & method
delay 2
js("var f = document.getElementById('gaia_loginform');
f.Email.value = '" & username & "';
@mpasternacki
mpasternacki / rename-node.rb
Created Mar 1, 2012
A knife exec script to change Chef node's name.
View rename-node.rb
#!./bin/knife exec
# A knife exec script to change chef node's name, preserving all the attributes.
#
# Usage: knife exec rename-node.rb old-name new-name
#
# Script retrieves the Node object, changes its 'name' attribute,
# creates new Node object with updated name and rest of attributes
# untouched. Then it deletes old Node and Client objects from
# database, and logs into the server to update it:
@mpasternacki
mpasternacki / perl_module_build.rb
Created Dec 29, 2011
Opscode Chef definition to upgrade Module::Build using perl cookbook's cpan_install script
View perl_module_build.rb
# Example usage:
# perl_module_build "0.3601"
define :perl_module_build do
execute "/usr/local/bin/cpan_install Module::Build" do
cwd "/root"
path [ "/usr/local/bin", "/usr/bin", "/bin" ]
not_if { `perl -mModule::Build -e 'print $Module::Build::VERSION'`.to_f >= params[:name].to_f }
end
end
@mpasternacki
mpasternacki / check_with_hysteresis.pl
Created Dec 23, 2011
Hysteresis support for nagios service checks' limit
View check_with_hysteresis.pl
#!/usr/bin/perl -w
#
# check_with_hysteresis.pl - hysteresis for nagios service checks' limits
#
# Usage: check_with_hysteresis.pl $LASTSERVICESTATE$ default check --- STATE1 check for state1 --- STATE2 check for state2 ...
#
# If $LASTSERVICESTATE$ is STATE1, "check for state1" will be
# executed, if it's STATE2, "check for state2" will be executed, and
# so on; if state is undefined, "default check" wil be executed.
#
@mpasternacki
mpasternacki / knife.rb
Created Oct 21, 2011
Make Chef's `knife ssh` use your actual login name
View knife.rb
# knife.rb config snippet to make knife ssh command use your own login
# instead of hard-coded `root', `ubuntu' or other name. Tries to get
# login for your domain from ~/.ssh/config and if it's not found
# there, uses your local login.
require 'net/ssh'
require 'etc'
knife[:ssh_user] =
Net::SSH::Config.for('some.host.inside.your.domain')[:user] ||
@mpasternacki
mpasternacki / metadata.rb
Created Sep 1, 2011
Opscode Chef cookbook's metadata.rb fragment to pull cookbook dependencies out of data bag files.
View metadata.rb
# Data bag items in 'projects' can declare 'include_recipes' property
# (list or string); these recipes will be included in the
# projects::default recipe, but - if they're not already loaded - need
# to be declared in 'depends'. This code loads the data bag JSON from
# files, and declares all needed dependencies.
require 'json'
soft_deps = []
Dir[File.join( File.dirname(__FILE__),
'../../data_bags/projects/*.json' )].each do |p|
soft_deps |= File::open(p) { |f| JSON::load(f) }["include_recipes"].to_a.
@mpasternacki
mpasternacki / data_bag_from_yaml.rb
Created Aug 19, 2011
Knife plugin to create data bags from YAML files
View data_bag_from_yaml.rb
#
# Author:: Maciej Pasternacki (<maciej@pasternacki.net>)
# Copyright:: Copyright (c) 2010 Maciej Pasternacki
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
@mpasternacki
mpasternacki / chef_fileedit_g.rb
Created Apr 15, 2011
Add g method (named after (s)ed's g//) to Chef::Util::FileEdit for more flexible text manipulation
View chef_fileedit_g.rb
class Chef
class Util
class FileEdit
public
# Run block for matching lines, passing it matching line.
# Replaces matching lines with value returned by the block.
def g(regex)
exp = Regexp.new(regex)
new_contents = []
contents.each do |line|
You can’t perform that action at this time.