Skip to content

Instantly share code, notes, and snippets.

View mpasternacki's full-sized avatar

Maciej Pasternacki mpasternacki

View GitHub Profile
@mpasternacki
mpasternacki / chef_fileedit_g.rb
Created April 15, 2011 17:55
Add g method (named after (s)ed's g//) to Chef::Util::FileEdit for more flexible text manipulation
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|
@mpasternacki
mpasternacki / backports_apt_package.rb
Created February 9, 2011 17:53
Debian backports package resource for Opscode Chef
# backports_apt_package.rb
#
# Resource and provider to correctly install packages from Debian's
# backports, which are a non-default apt source. Creates
# backports_apt_package resource which does the Right Thing.
#
# Drop this file into cookbook's libraries/ dir.
require 'chef/provider/package/apt'
require 'chef/resource/package'
@mpasternacki
mpasternacki / shef.rb
Created February 3, 2011 12:50
Make shef try to load current knife config by default
# ~/.chef/shef.rb
begin
# Load configuration from knife.rb
require 'chef/knife'
Chef::Knife.new.configure_chef
rescue
puts <<-EOF
Can't load knife config: #{$!}
This is probably nothing serious.
EOF
@mpasternacki
mpasternacki / update_dns.rake
Created February 1, 2011 13:36
Rake task to update Amazon Route53 DNS from by Chef node search
# -*- ruby -*-
# Needs following parameters configured in rake.rb:
# DNS_DOMAIN: domain for which to set entries, including trailing dot
# (e.g. "example.com.")
# DNS_ATTRIBUTE: attribute containing hostname to CNAME to, defaults
# to 'fqdn'; for EC2, use "ec2.public_hostname"
# DNS_ENTRIES: hash mapping hostname to node search query,
# e.g. {'buildbot' => 'recipes:buildbot', 'monitoring' =>
# 'roles:monitoring'}
@mpasternacki
mpasternacki / reap_instances.rake
Created January 16, 2011 20:03
Reap Node and Client instances for dead EC2 instances on a chef server.
# -*- mode: ruby; coding: utf-8 -*-
# Requires fog gem.
# Configure AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY in config/rake.rb
desc <<EOF
Delete nodes and clients for nonexistent EC2 instances from chef server
YES=1 variable makes task skip confirmation questions.
EOF
@mpasternacki
mpasternacki / git-diffstat.sh
Created November 23, 2010 13:53
Full-width diffstat "porcelain" for git
#!/bin/bash
COLUMNS=`stty size | cut -d' ' -f2`
exec git diff --stat=$COLUMNS,$(($COLUMNS - 20)) "${@}"
@mpasternacki
mpasternacki / flakes.py
Created May 25, 2010 12:41
Django management command to run pyflakes against Django project
from django.conf import settings
from django.core.management.base import BaseCommand
#### pyflakes.scripts.pyflakes, modified:
## - return array of warnings instead of printing them
## - honour pyflakes:ignore comments
import compiler, sys
import os
import pyflakes.checker
@mpasternacki
mpasternacki / htmlize-fragments.el
Created January 24, 2010 17:49
Replace fragment of current buffer with htmlized file.
(require 'htmlize)
(defun jph/strip-htmlized-buffer ()
"Strip htmlized buffer to <pre> tag, copying style attribute from <body> to <pre>."
(interactive)
(goto-char (point-min))
(re-search-forward "<body\\( style=[^>]*\\)>")
(let ((style (match-string 1)))
(search-forward "<pre")
(insert style)
@mpasternacki
mpasternacki / tail-n-mail.rb
Created January 8, 2010 21:45
Periodically send new lines in log file to specified email address.
# Script to periodically send new lines in log file to specified mail address.
#
# Similar to http://bucardo.org/wiki/Tail_n_mail - but I needed
# substitution to handle newlines in Python-generated messages, and it
# was faster to homebrew my own script than to add features to an
# already overfeatured Perl script. And I want to practice Ruby - seems
# to be fine for small, one-off scripts.
#
# License: WTFPL or MIT, whichever you prefer.
@mpasternacki
mpasternacki / README.md
Created November 23, 2009 12:43
Local ASDF-Install Sandbox

Local ASDF-Install Sandbox

I needed an installation of ADSF-Install that wouldn’t interfere with system-wide, user-wide or even project-wide settings but that would allow me to fetch, e.g., Tinaa and document my project. So, I want to create ASDF-install sandbox that would be completely self-contained. And I did. Here’s how:

First, download ASDF-Install using darcs:

darcs get http://common-lisp.net/project/asdf-install/darcs/asdf-install

Downloaded ASDF-install directory will be our sandox (yes, the self-contained sandbox is this self-contained it uses own local copy of ASDF-Install itself). Now, let’s create place for downloaded systems in sandbox and, to avoid overpopulating ASDF:*CENTRAL-REGISTRY*, symlink asdf-install itself there: