Skip to content

Instantly share code, notes, and snippets.

@deryni
deryni / worddiff.awk
Last active August 29, 2015 14:06
Line+word diff for git changes. Created for http://stackoverflow.com/a/25620599/258523
BEGIN {
RS="\n?~\n"
FS="\n"
}
# Special case the diff header/chunk header lines.
/^diff --git/ {
print
next
}
@deryni
deryni / silent_rules.mk
Created September 3, 2014 16:08
Automake-style Silent Rules support for GNU Make.
SR_PREFIX ?= SR
# Manual automake silent rule stuff
$(SR_PREFIX)_DEFAULT_VERBOSITY = 0
$(SR_PREFIX)_SILENT_VERBOSITY = -1
V ?= $($(SR_PREFIX)_DEFAULT_VERBOSITY)
SILENT := $(and $(filter $($(SR_PREFIX)_SILENT_VERBOSITY),$(V)),silent)
DEFAULT := $(and $(filter $($(SR_PREFIX)_DEFAULT_VERBOSITY),$(V)),default)
import sys, os, rpm
def readRpmHeader(ts, filename):
""" Read an rpm header. """
fd = os.open(filename, os.O_RDONLY)
h = None
try:
h = ts.hdrFromFdno(fd)
finally:
os.close(fd)
$ set -x
+ set -x
$ k=foo
+ k=foo
$ v='bar baz'
+ v='bar baz'
$ export foo=$v
+ export 'foo=bar baz'
+ foo='bar baz'
$ echo $foo
@deryni
deryni / Makefile
Last active August 29, 2015 14:10
make -j2 test
CC=gcc
l.a : l.a(a.o)
ranlib l.a
echo done
l.a(a.o) : a.c
clean::
rm -f l.a a.o
@deryni
deryni / Makefile
Last active August 29, 2015 14:11
SO 27365859 repro
ver.%: Makefile
touch ver.h
sleep 1
touch ver.cpp
.PHONY: clean all
all: ver.h ver.cpp
clean:
@deryni
deryni / dirname.sh
Last active October 16, 2015 21:02
POSIX-ly correct shell-only implementation of `dirname` (http://pubs.opengroup.org/onlinepubs/9699919799/utilities/dirname.html).
#!/bin/sh
p=$1
alt=$2
skip78=
stripslashes() {
i=$1
while [ "$i" != "$o" ]; do
o=$i
@deryni
deryni / helpsystem.mk
Created March 31, 2013 22:43
My version of the self-documenting makefile trick. Haven't used this too thoroughly yet so I'm not sure what I think of it but it seems ok so far. It was built for use in a project that doesn't have a meaningful 'all' target. It would probably want the filter changed back to something more like in the original for use in a more normal project.
# Modified version of http://www.cmcrossroads.com/article/self-documenting-makefiles
all:
@printf -- "$(HELPTGT)\n$(ETCTGT)\n" | column -t -s :
HELPTGT := --- Primary Targets ---
helptgt = $1$(eval $(if $(filter-out $(.DEFAULT_GOAL),$(MAKECMDGOALS)),,HELPTGT+=\n$(subst %,<name>,$1): - $2))
ETCTGT := --- Extra Targets ---
etctgt = $1$(eval $(if $(filter-out $(.DEFAULT_GOAL),$(MAKECMDGOALS)),,ETCTGT+=\n$1: - $2))
@deryni
deryni / Explanation
Last active December 19, 2015 01:39
Kickstart scripts and related install.log files illustrating CentOS 6 kickstart update problem.
Attempting to kickstart CentOS 6 works correctly. Attempting to include post-DVD updates during kickstart causes lots of scriptlet failures. Can someone tell me why this happens?
Specifically, I know why the failures happen (look at the order of package installation between the two outputs). I also know why rpm doesn't get the transaction order right (the scriplets are missing appropriate requires entries). What I don't understand is why pulling in update packages triggers this issue or why a regular install seems to always work.
I believe there are couple of bugs involved here:
- the sudo package does not contain a Requires(post): /bin/chmod
- the anaconda transaction order solver doesn't take scriplet requires ordering considerations into account beyond one dependency level (so the Requires(pre): /usr/sbin/useradd requirement is fulfilled by the time openssh is installed but anaconda doesn't extend that to ensuring that regular Requires: entries for shadow-utils are ordered correctly)
- that for some r
@deryni
deryni / gist:7328699
Created November 6, 2013 00:15
'git describe --contains --abbrev=0' doesn't seem to work.
$ git --version
git version 1.8.2.1
$ git lol
* f09682e (HEAD, tag: second-tag, master) add c
* 86db014 add b
* b8c7c3e (tag: initial-tag) initial
$ git describe 86db014
initial-tag-1-g86db014
$ git describe --abbrev=0 86db014
initial-tag