Skip to content

Instantly share code, notes, and snippets.

View slhck's full-sized avatar

Werner Robitza slhck

View GitHub Profile
@slhck
slhck / open-with-google-docs.sh
Created June 15, 2011 20:38
Google Docs Upload
#!/bin/sh
#
# Opens a local document, using Google Docs.
#
# If the document does not exist on Google Docs, it is uploaded and opened. If
# the document already exists (filename matches exactly) then the existing
# document is opened.
#
# Requires googlecl. Written for Mac OS X.
#
@slhck
slhck / recursive-file-hash.rb
Created November 10, 2011 15:14
Recursively build a hash for directory listing
#!/usr/bin/env ruby
# Recursively build a hash for directory listing
def create_hash(path, name = nil)
data = {:parent => (name || path)}
data[:children] = children = []
Dir.foreach(@path) do |entry|
next if entry == '..' or entry == '.'
full_path = File.join(path, entry)
if File.directory?(full_path)
@slhck
slhck / xml-directory.rb
Created November 10, 2011 15:15
Create an XML representation of a directory tree
#!/usr/bin/env ruby
# xml-directory.rb
# Author: Werner Robitza
# Synopsis: A basic XML writer that parses the current directory and files
# Usage: xml-reader.rb <path> <output> [-a]
# <path> the directory path that should be analyzed
# <output> the output file
# -a output with XML attributes too instead of just using XML elements
require 'nokogiri'
@slhck
slhck / rss-reader.rb
Created November 10, 2011 15:16
A simple RSS/Atom reader for Ruby
#!/usr/bin/env ruby
# rss-reader.rb
# Author: Werner Robitza
# Synopsis: A basic console RSS News Feed reader
# Usage: rss-reader.rb <url> <granularity>
# <url> being the URL of the RSS news feed
# <granularity> is one of: short | medium | full
require 'open-uri'
require 'nokogiri'
@slhck
slhck / rss-to-pdf.rb
Last active December 3, 2017 14:48
Parses an online RSS feed and creates a PDF from it, using the Ruby Prawn library
#!/usr/bin/env ruby
# rss-to-pdf.rb
# Author: Werner Robitza
# Synopsis: A basic console RSS to PDF writer using the prawn library
# Usage: rss-to-pdf.rb <url>
# <url> being the URL of the RSS news feed
require 'open-uri'
require 'nokogiri'
require 'pp'
@slhck
slhck / time-diff.rb
Last active February 17, 2021 18:59
Calculates calculates the difference between time as HH:MM:SS.msec
#!/usr/bin/env ruby
# calculates the difference between time as
# "HH:MM:SS.msec" and "HH:MM:SS.msec"
# into a file called diffs.txt
require "Time"
def time_diff(time1_str, time2_str)
t = Time.at( Time.parse(time2_str) - Time.parse(time1_str) )
(t - t.gmt_offset).strftime("%H:%M:%S.%L")
@slhck
slhck / video-extract.rb
Created May 2, 2012 07:06
Video Extraction for Ruby/FFmpeg
#!/usr/bin/env ruby
# Batch encodes videos from a list of editing points
# Author: Werner Robitza <[email protected]>
FFMPEG = "ffmpeg" # => path to the FFmpeg executable
COPY = false # => if set to true, just does a bitstream copy
# => if set to false, encoding options below are used
OVERWRITE = "-n" # => set to "-n" if you just want to keep files that exist
@slhck
slhck / copy.user.js
Last active December 15, 2015 09:09
Copy User Links
// ==UserScript==
// @name Copy User Links
// @author Werner Robitza
// @namespace
// @description Adds a button for copying superping-ready user names of close voters
// @include http://stackoverflow.com/*
// @include http://meta.stackoverflow.com/*
// @include http://superuser.com/*
// @include http://serverfault.com/*
// @include http://meta.superuser.com/*
@slhck
slhck / analyze.r
Last active December 19, 2015 09:39
Converts raw NappingPlayer output to a summary data frame.
#!/usr/bin/env Rscript
#
# Synopsis: Converts raw NappingPlayer output to a summary data frame for
# input in FactoMineR or SensoMineR. This also contains a few examples.
# Comment out the lines you don't need, or browse through the source.
# Author: Werner Robitza, <[email protected]>
# Known issues: At the moment there might be a problem with non-alphanumeric names being used.
# Report bugs here, please: https://github.com/slhck/napping-player/issues
# Change the working directory that contains your raw tablet data files
#!/bin/bash -x
CALLERS_UID="$1"
REFCOUNT_PATH="$2"
DCALL_PATH="$3"
if [ $UID -ne 0 ]; then
# Test that the script is run as root.
echo "Script must run as root"
exit 1