Schnippets

Python

#
#http://codeblog.dhananjaynene.com/2011/06/10-python-one-liners-to-impress-your-friends/
#
print map(lambda x: x * 2, range(1,11))

# Sieve of Eratosthenes
n = 50 # We want to find prime numbers between 2 and 50
print sorted(set(range(2,n+1)).difference(set((p * f) for p in range(2,int(n**0.5) + 2) for f in range(2,(n/p)+1))))

Bash

# convert to mp4
mkdir -p mp4
mkdir -p completed
for file in $@; do
    extension="${file##*.}"
    filename="${file%.*}"
    avconv -i ${file} -c:v libx264 -c:a copy mp4/${filename}.mp4
    mv ${file} completed/
done

# fix dangling symlinks
cd ~/bin; find . -xtype l | sed 's/\.\///' | xargs -i find /path/to/files/in/revisioncontrol -name {} | xargs -i ln -fs {} .

# sort files by last modified date
find . -type f -printf '%T@' -ls | sort | tail -n

LibreOffice Macro

Sub highlight
    Dim oActiveCell
    oActiveCell = ThisComponent.CurrentSelection
    oActiveCell.CellBackColor = 16777113
End Sub

CouchDB to Elasticsearch

input {
  couchdb_changes {
      db => "media"
      host => "192.168.0.70"
      port => 5984
      codec => "json"
      username => "rdd"
      password => "rdd1qaz2wsx"
      initial_sequence => 0 #this is only required for the an initial indexing
      #keep_revision=>true
  }
}

output {
  elasticsearch{
      #action => "%{[@metadata][action]}"
      action =>"index"
      document_id => "%{[@metadata][_id]}"
      hosts => "192.168.0.70:9200"
      #index => "monitor-%{+YYYY.MM.dd}"
      index => "media"
      document_type => "doc"
    }

  if [@metadata][action] == "delete" {
    elasticsearch{
      action => "%{[@metadata][action]}"
      #action =>"index"
      document_id => "%{[@metadata][_id]}"
      hosts => "192.168.0.70:9200"
      #index => "monitor-%{+YYYY.MM.dd}"
      index => "media"
      document_type => "doc"
    }
  }

    #stdout {} #enable this option for debugging purpose
}