Archive for March, 2014

Convert all .mkv files in a directory to .mp4 for ipad

Sunday, March 30th, 2014

Here’s a bash “one-liner” to convert all movie files in the current directory to a format that works with the ipad. It renames the files from .mkv to .mp4.

for f in *.mkv; do ffmpeg -i $f -acodec aac -ac 2 -strict experimental -ab 160k -s 1920x1080 -vcodec copy -f mp4 -threads 0 ${f%.*}.mp4; done

Bounded biharmonic weights in Communications of the ACM

Wednesday, March 26th, 2014

bbw in cacm

Our 2011 SIGGRAPH paper, “Bounded Biharmonic Weights for Real-Time Deformation”, is featured in the Research Highlights section of the April 2014 edition of the computer science magazine Communications of the ACM. This version of the paper has some updates that would have been anachronistic in the original paper and a more accessible introduction (at least we think so). The paper is prefaced by a technical perspective letter by Joe Warren.

Sort movies by existence in list of movie titles

Monday, March 24th, 2014

Using the bash script from my previous post I can generate a list of all movie titles on tehconnection.eu and store them as lines in a text file called tehconnection.eu. I wanted this to sift through a giant list of movies I had on an old external hard drive. This ruby script (save in sort_by_tehconnection.rb) to check my directories list of movies against the list from tehconnection and move the files that exist in that list into a separate directory (which I’ll then double check and delete).

Using the bash script from my previous post I can generate a list of all movie titles on tehconnection.eu and store them as lines in a text file called tehconnection.eu. I wanted this to sift through a giant list of movies I had on an old external hard drive. This ruby script (save in sort_by_tehconnection.rb) to check my directories list of movies against the list from tehconnection and move the files that exist in that list into a separate directory (which I’ll then double check and delete).

#!/opt/local/bin/ruby

require "levenshtein_distance.rb"
require 'fileutils'

look_dir='/Volumes/Senorita/DOCUMENTARIES/Feature Documentaries/'
found_dir='/Volumes/Senorita/DOCUMENTARIES/Feature Documentaries/tehconnection/'

#files_array=File.readlines('files.txt');
files_array=Dir.entries(look_dir).reject{|entry| entry == "." || entry == ".." || entry == ".DS_Store"};
teh_array=File.readlines('tehconnection.txt').collect {|l| l.gsub(/[.!?:';"]/,"").downcase.sub(/^the /,"").chomp};
teh_array = teh_array.inject([]) do |res,e|
  if e =~/([^\(]*) \(aka ([^\)]*)\)/
    res.concat([$1,$2]);
  else
    res.concat([e]);
  end
end
teh_map = [];
teh_array.each do |e| 
  i = e.length-1;
  if teh_map[i].nil?
    teh_map[i] = [];
  end
  teh_map[i] << e
end
acceptable_dist=2
min_dist=10000
min_teh=""
files_array.each do |orig_title|
  title=orig_title.sub(/ *\([^\(]*\)/,"")
  title.downcase!
  title.sub!(/\.[^\.]*$/,"")
  title.sub!(/^the /,"")
  title.gsub!("\"","")
  title.sub!(/^marx brothers - /,"")
  len = title.length;
  max_len = [len+acceptable_dist,teh_map.length-1].min;
  min_len = [len-acceptable_dist,0].max;
  puts "#{title}..."
  (min_len..max_len).each do |l|
    l_array = teh_map[l];
    found = false;
    if not l_array.nil?
      l_array.each do |teh_title|
        dist=levenshtein_distance(title,teh_title)
        if dist<acceptable_dist
          # found
          puts "  FOUND (#{orig_title}): #{teh_title} --> #{title}, #{dist}"
          FileUtils.mv(look_dir+"/"+orig_title,found_dir+"/"+orig_title);
          found = true;
          break;
        end
      end
    end
    if found
      break;
    end
  end
end

Scrape all torrent titles from tehconnection.eu

Monday, March 24th, 2014

Here’s a bash script to log into <tehconnection.eu> then scrape all movie titles from their list of available torrents, doing minor cleanup on the symbols.

#!/bin/bash

LOGIN_URL="https://tehconnection.eu/login.php"
USERNAME=myusername
PASSWORD=mypassword
# log in to website and save cookies
wget --post-data \
  "username=$USERNAME&password=$PASSWORD" \
  --save-cookies=cookies.txt --keep-session-cookies \
  -O /dev/null \
  -q \
  $LOGIN_URL \
  &>/dev/null

FILMS_URL="https://tehconnection.eu/torrents.php?order_by=s1&order_way=ASC"
## download first page determine last page
RES=`wget --load-cookies=cookies.txt $FILMS_URL -q -O -`
LAST=`echo "$RES" | grep -m 1 -o "page[^\/]* Last" | \
  sed -e "s/page=\([0-9][0-9]*\).*/\1/g"`
#LAST=363

for p in $(seq 1 $LAST);
do 
  URL="$FILMS_URL&page=$p"
  RES=`wget --load-cookies=cookies.txt $URL -q -O -`
  echo "$RES"| grep "torrent_title\"" | \
    sed -e "s/.*View Torrent\">\([^<]*\).*/\1/g" | ./html_entity_decode.php
  sleep 3
done

# get rid of cookies
rm cookies.txt

Move/Copy many files in bash

Monday, March 17th, 2014

I tried to move a bunch (>30,000) of files starting with the same prefix to a new directory:

mv color-*.png ../some-other-dir/

But I got the error:

-bash: /bin/mv: Argument list too long

Instead, I used:

find . -name "color-*.png" -exec mv {} ../some-other-dir/ \;

Note that the {} will get replaced with the individual file names and the mv command is executed separately for each.

source

Block/remove upworthy posts on facebook

Thursday, March 13th, 2014

The click-bait site, upworthy, really got to me today so I wrote a quick userscript that removes upworthy.com posts from facebook.

// ==UserScript==
// @name       My Fancy New Userscript
// @namespace  http://use.i.E.your.homepage/
// @version    0.1
// @description  enter something useful
// @match      https://www.facebook.com/
// @copyright  2012+, You
// ==/UserScript==
window.setInterval(function(){kill_upworthy();},5*1000);
function kill_upworthy()
{
    var divs = document.getElementsByClassName('_5jmm _5pat _5uch');
    for(var d=0;d<divs.length;d++)
    {
        if(divs[d].innerHTML.indexOf("upworthy")!=-1)
        {
            divs[d].innerHTML = divs[d].getElementsByClassName("_5pbw")[0].innerHTML+"<hr>Upworthy link removed.";
        }
    }
};
kill_upworthy();

block upworthy from facebook

On Chrome I use the tampermonkey extension.

Compute shortest paths for multiple sources using MATLAB’s `graphshortestpath`

Monday, March 10th, 2014

Annoyingly MATLAB’s graphshortestpath function implementing Dijkstra’s algorithm only computes shortest path to a single source. Given an n-by-n adjacency weight matrix G and a list of m sources S you can compute the shortest path distances in a n-by-m matrix D with:

D = cell2mat(arrayfun(@(s) graphshortestpath(G,s)',S,'UniformOutput',false));