Skip to content

Instantly share code, notes, and snippets.

View kwilczynski's full-sized avatar
🐧
Have you built a Linux kernel recently?

Krzysztof Wilczyński kwilczynski

🐧
Have you built a Linux kernel recently?
  • Yokohama, Japan
  • 02:12 (UTC +09:00)
View GitHub Profile
@kwilczynski
kwilczynski / gist:920908
Created April 15, 2011 00:45
MCollective's mco bash completion script to put into /etc/bash_completion.d/ directory ...
# -*- mode: shell-script; sh-basic-offset: 8; indent-tabs-mode: t -*-
# ex: ts=8 sw=8 noet filetype=sh
# MCollective's mco completion by Krzysztof Wilczynski <[email protected]>
_mco()
{
local current
COMPREPLY=()
@kwilczynski
kwilczynski / gist:931552
Created April 20, 2011 14:56
Puppet and The Magic of Define
# The following monstrosity ...
class test { }
define test::a($array) {
test::iterator { $name:
array => $array
}
}
@kwilczynski
kwilczynski / gist:937936
Created April 22, 2011 23:27
Accessing fact from Facter within Puppet manifest ...
# The following monstrosity ...
define partitions {
$fact = "partitions_${name}"
$result = split(inline_template("<%= scope.lookupvar(fact) %>"), ',')
notice $result
partition { $result: }
}
@kwilczynski
kwilczynski / gist:938684
Created April 23, 2011 15:09
Testing join function within Puppet manifest file ...
krzysztof@samsung ~/Sandbox $ cat - | LOAD_PATH=. FACTERLIB=. puppet
define iterator {
notice $name
}
$array = ['a', 'b', 'c']
$result = split(join($array, ',', 'letter_'), ',')
@kwilczynski
kwilczynski / gist:938766
Created April 23, 2011 16:42
Testing array indices accessor for use winitn Puppet manifest ...
krzysztof@samsung ~/Sandbox $ cat - | LOAD_PATH=. FACTERLIB=. puppet
define iterator {
notice $name
}
$array = ['a', 'b', 'c', 'd']
$result = collect_indices($array, 1, 3, 2, 10)
notice $result
@kwilczynski
kwilczynski / netstat.rb
Created May 3, 2011 19:36
Simple netstat in Ruby
!#/usr/bin/env ruby
PROC_NET_TCP = '/proc/net/tcp' # This should always be the same ...
TCP_STATES = { '00' => 'UNKNOWN', # Bad state ... Impossible to achieve ...
'FF' => 'UNKNOWN', # Bad state ... Impossible to achieve ...
'01' => 'ESTABLISHED',
'02' => 'SYN_SENT',
'03' => 'SYN_RECV',
'04' => 'FIN_WAIT1',
[krzysztof@development ~]$ cat - | puppet
$a = ['a', 'b']
notice inline_template("<%= a[0] %>")
notice: Scope(Class[main]): a
[krzysztof@development tmp]$ cat test.erb
<%= a[0] %>
[krzysztof@development tmp]$ cat test.pp
class test {
$a = ['a', 'b']
file { "/tmp/test":
content => template("/tmp/test.erb"),
ensure => present,
}
@kwilczynski
kwilczynski / gist:975609
Created May 16, 2011 23:45
Puppet DSL iterator via define ...
matti@acrux ~ $ cat - | puppet
$a = [ 'a', 'b', 'c' ]
define iterator { notice $name }
iterator { $a:; }
notice: Scope(Iterator[a]): a
notice: Scope(Iterator[b]): b
notice: Scope(Iterator[c]): c
matti@acrux ~ $
@kwilczynski
kwilczynski / gist:999369
Created May 30, 2011 19:41
Example PHP ...
<?php
$customers = array('hennie' => 100, 'krzysztof' => 10);
$customer = $_GET['customer'];
if (! $customer)
{
echo 'You have to specify a customer name in order to access its balance details';
exit(1);