git Cheat Sheet

Create new git branch

Create a new git branch and switch to it

git checkout -b <new branch name>

and create it on origin too

git push origin <new branch name>

Remove git branch

Remove git branch locally with

git branch -d <branch name>

and remove on origin too

git branch -d -r origin/
git push origin :

Alternatively remove on origin and then prune locally.

Remove stale git branches

When remote branches disappear clean them from your local repo with

git remote prune origin

Rebasing a branch

To rebase on master

git rebase master <branch name>

Enable git password Caching

To keep passwords for 1h run

git config --global credential.helper 'cache --timeout=3600'

Amending changes

git add <files>
git commit --amend

How to apply patches with git

A detailed description can be found here. You should always run the following commands:

git apply --stat cool_feature.patch    # Check what the patch will do
git apply --check cool_feature.patch   # Check if the patch fails
git am --signoff < cool_feature.patch

Git - Tracking Remote Branches

To follow additional branches in your local repo follow these steps:

# Find out all existing remote branches
git branch -r

# And track one of them locally
git branch --set-upstream-to <branch> <remote/branch>

Git and Stashing Changes

For a detailed explanation check here. This feature is useful to put debugging or experimental changes to the "background". Here are the commands:

git stash "Some test I made"    # Stash some changes away

git stash list                  # List stashes
git stash show stash@{0}        # Show changes file in last stash
git stash show -p stash@{0}     # Show patch for last stash

git stash apply stash@{0}       # Get last stash active again
git stash drop stash@{0}        # Delete last stash

git stash pop                   # Apply and remove last stash

git stash clear                 # Delete all stashes

# Stash just some files by adding all others first 
# and using --keep-index
git add <all files you want to keep>
git stash --keep-index

Remove all repo files from a directory

If you ever need to remove all git related files from a local working repo and make it just a normal directory:

git clean -ffrx

List Commits in One Line Each

git rev-list --all --pretty=oneline

List Git Branch in Bash Prompt PS1

There are several documentations online e.g. this one. In the end it boils down to running "git branch" on each prompt and to use an environment function __git_ps1() that is set up by "git branch" to print the branch if there is one. So if your current $PS1 is

export PS1='\u@\h:\w\$ "

you could extend it to

export PS1='\u@\h:\w$(git branch &>/dev/null; echo $(__git_ps1 "(%s)"))\$ '

to show the branch name in braces after the directory name and before the $ like this:

john@server:~/project/src(master)$ 

Liferea 1.10 Schema Crash on Fedora 18/19

In case you want to self-compile Liferea 1.10 on Fedora and you find it crashing on startup with something like this

(liferea:3798): GLib-GIO-ERROR **: Settings schema 'net.sf.liferea' 
does not contain a key named 'last-node-selected'

please run

/usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas

It seems like the schema installation doesn't work properly on Fedora. This was reported and solved by nmdias in ticket SF #1093.

How to dry-run with chef-client

The answer is simple: do not "dry-run", do "why-run"!

chef-client --why-run
chef-client -W

And the output looks nicer when using "-Fmin"

chef-client -Fmin -W

As with all other automation tools, the dry-run mode is not very predictive. Still it might indicate some of the things that will happen.

CDN Usage by Large Web Sites

This is a list of all top domains scanned for the report What Large Sites Use grouped by CDN detected. Feel free to verify the detected CDNs by checking out the CDN detector provided by cdnplanet.com and report misdetection in the comments.

Measurement Method

For each domain the main page was fetched. All <script> and <img> domains where checked for CDNs behind them. Note that this does not necessarily find the primary CDN due to scripting libraries loaded from other CDNs (e.g. jQuery). Each site might appear multiple times which might hint on a transparent Multi-CDN provider. Additionally in the case of Cedexis it is not clear if it is used just for monitoring or as Multi-CDN.

CDN Usage in 2014-12

CDN Sites
Akamai adobe.com alibaba.com aliexpress.com amazon.co.jp amazon.com amazon.fr amazon.in amazon.it ameblo.jp aol.de apple.com ask.com autobild.de avg.com bbc.com bbc.co.uk bestbuy.com bigpoint.com bild.de bing.com buch.de buzzfeed.com chip.de cnet.com cnn.com computerbild.de conduit.com dailymail.co.uk dailymotion.com deviantart.com diply.com dooyoo.de ebay.com ebay.co.uk ebay.de edarling.de erento.com espn.go.com etsy.com ettoday.net facebook.com finanzen.net flickr.com flipkart.com focus.de forbes.com globo.com gmx.de gmx.net godaddy.com groupon.de huffingtonpost.com imdb.com immonet.de indeed.com indiatimes.com jabong.com java.com last.fm lieferheld.de linkedin.com mashable.com microsoft.com microsoft.de mjam.at morgenpost.de mozilla.org msdn.com mtv.com mytoys.de naver.com netflix.com n-tv.de nytimes.com otto.de paypal.com pizza.de qq.com rakuten.co.jp reference.com rp-online.de rtl.de salesforce.com skype.com skype.de slashdot.org slideshare.net snapdeal.com sourceforge.net spiegel.de sport1.DE stepstone.de stern.de stumbleupon.com sueddeutsche.de superantojo.com.mx taobao.com target.com theguardian.com tudou.com twitch.tv walmart.com weather.com web.de web.mit.edu wellsfargo.com welt.de wetter.com wetteronline.de wikia.com xing.de yelp.com youku.com zalando.de zdf.de zedo.com
amazonaws adobe.com aol.com buzzfeed.com ettoday.net foodarena.ch github.com jabong.com nzz.ch photobucket.com pingdom.com snapdeal.com stern.de themeforest.net tvinfo.de twitch.tv wetter.com wetteronline.de wikia.com zedo.com
cachefly arstechnica.com cdnplanet.com
CDNetworks sina.com.cn
Cedexis autobild.de bild.de computerbild.de deviantart.com finanzen.net linkedin.com morgenpost.de tumblr.com welt.de
cloudapp.net microsoft.com microsoft.de
Cloudflare adf.ly feedly.com foodpanda.in foodpanda.pl foodpanda.ru hungryhouse.co.uk jquery.com life.com.tw pingdom.com reddit.com statcounter.com webpagetest.org yelp.com
CloudFront 360.cn addthis.com amazonaws.com amazon.co.jp amazon.com amazon.co.uk amazon.de amazon.fr amazon.in amazon.it arstechnica.com avg.com bannersdontwork.com berlinonline.de bongacams.com cdnplanet.com chefkoch.de china.com chinadaily.com.cn diply.com douban.com dropbox.com duden.de ettoday.net foodarena.ch gmw.cn hungryhouse.co.uk instagram.com lieferando.de life.com.tw nzz.ch pixnet.net pornotube.com snapdeal.com spotify.com stumbleupon.com superantojo.com.mx theguardian.com themeforest.net tivo.com tvinfo.de web.mit.edu
EdgeCast booking.com buzzfeed.com crunchbase.com dailymotion.com deviantart.com erento.com forbes.com indiatimes.com kicker.de soundcloud.com stackexchange.com sueddeutsche.de twitter.com wordpress.com
fastly crunchbase.com etsy.com github.com kicker.de theguardian.com twitter.com vimeo.com yelp.com
Level3 kicker.de myvideo.de sueddeutsche.de theguardian.com volkswagen.de wetter.com
Limelight arstechnica.com linkedin.com swissre.com xnxx.com xvideos.com zeit.de
lxdns 163.com china.com cntv.cn gmw.cn ifeng.com ku6.com
netdna cdnplanet.com neobux.com stumbleupon.com
phncdn.com pornhub.com redtube.com tube8.com youporn.com
rncdn1.com pornhub.com redtube.com thepiratebay.sx tube8.com webpagetest.org youporn.com
WaveCDN upjers.com

Large Website Technology Changes in November 2013

As in the last two months I performed another a indexing of the information reported by major websites. It covers mostly request header, HTML and DNS based information of the top 200 sites listed by Alexa and the top 100 German websites. All the information is freely available and only extracted from the website responses!

The detailed results can be found here:

What Changed?

DNS-Prefetching The HTML header based DNS prefetching is still there and gained another site: German job portal stepstone.de
IPv6 IPv6 support did not spread in the last month. Several sites have flapping visibility of their AAAA records.
Version Upgrades adf.ly upgrades from PHP 5.3.8 to 5.4.21.
rtl.de upgrades from Apache 2.2.21 to 2.4.6.
Webserver Change German health portal imedo.de switched from Mongrel to Apache
Hiding Server Version Porn site xnxx.com stopped reporting usage of PHP 5.3.6
CDN In 11/2013 conduit.com switched from Cotendo to Akamai CDN.
Hoster German couples portal parship.de seems to have changed hoster and is using BigIP F5 load balancers now.

Note: the website links lead to a history page for the measurements.

Caution!

All the results listed above are based on a simple scanning script. The results present a snapshot of the websites and a single response only. This is of course not necessarily an indicating for what techniques the site uses in daily operations!

GTK Tray StatusIcon Example with PyGI

Here is an example on how to build a GtkStatusIcon using PyGI (Python GObject). The code actually implements a libpeas plugin that could be used with any GTK+ project that allows GI plugins. The tray icon could respond to left clicking by toggling the application window like many instant messengers do. On right clicks it presents a menu with the options to toggle the application window or quit the application.

from gi.repository import GObject, Peas, PeasGtk, Gtk

class TrayiconPlugin (GObject.Object, PeasActivatable):
    __gtype_name__ = 'TrayiconPlugin'

    object = GObject.property (type=GObject.Object)

    def do_activate (self):
        self.staticon = Gtk.StatusIcon ()
	self.staticon.set_from_stock (Gtk.STOCK_ABOUT)
        self.staticon.connect ("activate", self.trayicon_activate)
        self.staticon.connect ("popup_menu", self.trayicon_popup)
        self.staticon.set_visible (True)

    def trayicon_activate (self, widget, data = None):
        print "toggle app window!"

    def trayicon_quit (self, widget, data = None):
        print "quit app!"

    def trayicon_popup (self, widget, button, time, data = None):
        self.menu = Gtk.Menu ()

        menuitem_toggle = Gtk.MenuItem ("Show / Hide")
        menuitem_quit = Gtk.MenuItem ("Quit")

        menuitem_toggle.connect ("activate", self.trayicon_activate)
        menuitem_quit.connect ("activate", self.trayicon_quit)

        self.menu.append (menuitem_toggle)
        self.menu.append (menuitem_quit)

        self.menu.show_all ()
	self.menu.popup(None, None, lambda w,x: self.staticon.position_menu(self.menu, self.staticon), self.staticon, 3, time)

    def do_deactivate (self):
        self.staticon.set_visible (False)
        del self.staticon

Website Technology Crawl 12/2013

I've update the What Large Sites Use page with the results crawled in December 2013. Check it out to see who is using what! New column for HTML DOCTYPE was added. I'll soon post the followup on the changes compared to November.

What Job Offers Tell About Architectures #5

Part 5 of the Unix/Linux system administrator job offer and technologies survey. Here are several new companies. This time watch out for "or's" in the table and the order of the alternative which might give an indication what the employer uses and what knowledge he deems equivalent. Also keep in mind that such "or's" indicate once more that each position might describe only wishes, but not that actual architecture the company uses. It depends on how open they want to be...

If you want to check for yourself click the "[src]" for the original reference, but know that it might be already offline.

Todays List

Company Sector Reference OS Languages Databases Software Hardware Monitoring Virtualization Automation
allesklar meinestadt.de Internet: Web [src] Linux MySQL, Postgres, Cassandra DB HA and Loadbalancing
Xing Social [src] Java, Scala ElasticSearch or (Lucene or Solr) Haadop, HBase, Cassandra
Hanwha Q Cells Industry [src] AIX System P, Storages, Tape
buch.de Online Store: Books [src] Redhat Apache, Tomcat, Redhat Satellite SAN yes
goodgame Studios Gaming [src] Debian, Redhat Shell MySQL Apache, Postfix Nagios, Munin, Icinga
International Algorithmic Trading GmbH Finance [src] Redhat, CentOS, Scientific Linux Bash, Perl yes
Lidl Online Store: Food [src] Redhat Shell MySQL VMWare
EOS UPTRADE GmbH Internet [src] Debian, CentOS PHP MySQL Cisco FW, Watchguard Icinga XenServer, VMWare Cloud Puppet

The Interesting Things

Well this is the first time I see someone using Scientific Linux. As with the previous posts automation doesn't seem to play a big role as only 2 out of 8 mentioned it. Also no startupish devops style offers here as the scripting languages seem to indicate. It seems to be just good old robust Unix administration :-)

And look at Q Cells, no wonder they went bankrupt using IBM hardware...

Note: You can find the complete index of all companies I checked so far here:
What Job Offers Tell About Architectures.

Nagios Plugin for dmesg Monitoring

So far I found no easy solution to monitor for Linux kernel messages. So here is a simple Nagios plugin to scan dmesg output for interesting stuff:

#!/bin/bash

SEVERITIES="err,alert,emerg,crit"
WHITELIST="microcode: |\
Firmware Bug|\
i8042: No controller|\
Odd, counter constraints enabled but no core perfctrs detected|\
Failed to access perfctr msr|\
echo 0 > /proc/sys"

# Check for critical dmesg lines from this day
date=$(date "+%a %b %e")
output=$(dmesg -T -l "$SEVERITIES" | egrep -v "$WHITELIST" | grep "$date" | tail -5)

if [ "$output" == "" ]; then
	echo "All is fine."
	exit 0
fi

echo "$output" | xargs
exit 1

"Features" of the script above:

  • It gives you the 5 most recent messages from today
  • It allows to whitelist common but useless errors in $WHITELIST
  • It uses "dmesg" to work when you already have disk I/O errors and to be faster than syslog parsing

This script helped a lot to early on detect I/O errors, recoverable as well as corruptions. It even worked when entire root partition wasn't readable anymore, because then the Nagios check failed with "NRPE: unable to read output" which indicated that dmesg didn't work anymore. By always showing all errors from the entire day one cannot miss recovered errors that happened in non-office hours.

Another good thing about the check is detecting OOM kills or fast spawning of processes.

Removing newlines with sed

My goal for today: I want to remember the official sed FAQ solution to replace multiple newlines:

sed ':a;N;$!ba;s/\n//g' file

to avoid spending a lot of time on it when I need it again.

Syndicate content Syndicate content