Skip to content

Instantly share code, notes, and snippets.

@gdanko
gdanko / pipe.py
Last active September 28, 2024 17:45
Simulating piping one command to another using Python
#!/usr/bin/env python3
import subprocess
# This performs the equivalent of `ps -axm -o rss,comm | sort -rn -k 1 | head -n 20`
number_of_entries = 20
cmd1 = ['/bin/ps', '-axm', '-o', 'rss,comm']
cmd2 = ['sort', '-rn', '-k', '1']
cmd3 = ['head', '-n', str(number_of_entries)]
package main
import (
"archive/tar"
"bytes"
"context"
"encoding/json"
"fmt"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
@gdanko
gdanko / hash2xml.rb
Last active April 3, 2018 21:18
A simple hash > XML converter using REXML
class ::Hash
require "rexml/document"
def to_xml(indent: nil, rootname: nil, output: nil, encoding: nil)
indent = indent ? indent : 2
rootname = rootname ? rootname : "root"
output = output == $stdout ? $stdout : nil
encoding = encoding ? encoding : "UTF-8"
xml = REXML::Document.new
formatter = REXML::Formatters::Pretty.new(indent)
formatter.compact = true
# Inside the chef template erb file we can do this:
<%= "[mindadmin]" %>
<% node[:splunk][:roles][:miniadmin].each do |key, value| %>
<%= "#{key} = #{value}" %>
<% end %>
#!/usr/bin/ruby
require "hipchat"
require "pp"
hc = HipChat.new({
"token" => "MYTOKEN"
})
hc.debug("on")
function status_fn_oor_state(jobId) {
var status_fn_oor_state_cfg = {
method: 'GET',
on: {
success: function(id, o) {
var jsonString = o.responseText;
rec = Y.JSON.parse(jsonString);
rec.data = rec.result.output;
rec.result.output = undefined;
if(rec.result.status !== 'completed' && rec.result.status !== 'completed_with_map_errors'