Archive

Author Archive

Converting media for your PS3

August 26th, 2010 Wytze No comments

According to the PS3 site the following media can be played:

The following types of files can be played under (Video).

    * Memory Stick Video Format
    - MPEG-4 SP (AAC LC)
    - H.264/MPEG-4 AVC High Profile (AAC LC)
    - MPEG-2 TS(H.264/MPEG-4 AVC, AAC LC)
    * MP4 file format
    - H.264/MPEG-4 AVC High Profile (AAC LC)
    * MPEG-1 (MPEG Audio Layer 2)
    * MPEG-2 PS (MPEG2 Audio Layer 2, AAC LC, AC3(Dolby Digital), LPCM)
    * MPEG-2 TS(MPEG2 Audio Layer 2, AC3(Dolby Digital), AAC LC)
    * MPEG-2 TS(H.264/MPEG-4 AVC, AAC LC)
    * AVI
    - Motion JPEG (Linear PCM)
    - Motion JPEG (μ-Law)
    * AVCHD (.m2ts / .mts)
    * DivX
    * WMV
    - VC-1(WMA Standard V2)

Supported audio formats:

    * Memory Stick Audio Format(ATRAC)
    * MP3
    * - MPEG-1/2 Audio Layer3
    * - MP3 Surround
    * MP4(MPEG-4 AAC)
    * WAVE(Linear PCM)
    * WMA

I tested several encodings on my Quad-core Intel (Q6600). I got the best results encoding with the MP4 format as all four cores were used at 100%. This also resulted in smaller file sizes.
I am using VLC to do the conversion although other programs (ffmpeg, mencoder) might also work mighty fine.

The goal I had was to transcode movies add subtitles and keep file sizes as small as possible so we can put them on an external usb storage device for playback.

We will use VLC from the command-line. The following commands are useful. Have a look at the man pages for more information. VLC command-line pages

This is the command I ended up with:

vlc "movie.avi" --sub-file="movie.srt" --sout=#transcode{vcodec=h264,acodec=mp4a,vb=0,ab=192,channels=2,soverlay,audio-sync}:standard{access=file,mux=mp4,dst="outputfile.mp4"} vlc://quit

You can add “-I dummy” if you don’t want/need a window to pop up. I like it because it shows where you are in the transcoding process.
The soverlay is used for the subtitles. I limit the audio channels to 2 because I don’t have any surround sound setup. Change it to whatever you need.

Greasemonkey + jQuery = 1337

July 30th, 2010 Wytze No comments

Got some inspiration from this site for the base script: click

I wanted a site to always show the answer ‘Ja’ (Dutch for yes). Which was normally only shown at a specific time. (The question was if you could start drinking beer. ;) )

Here is the full script:

// ==UserScript==
// @name           ishetalbiertijd.user.js
// @namespace      http://famvdploeg.com/greasemonkey
// @include        http://www.ishetalbiertijd.nl/*
// ==/UserScript==
 
var $;
 
// Add jQuery
(function(){
	if (typeof unsafeWindow.jQuery == 'undefined') {
		var GM_Head = document.getElementsByTagName('head')[0] || document.documentElement,
			GM_JQ = document.createElement('script');
 
		GM_JQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js';
		GM_JQ.type = 'text/javascript';
		GM_JQ.async = true;
 
		GM_Head.insertBefore(GM_JQ, GM_Head.firstChild);
	}
	GM_wait();
})();
 
// Check if jQuery's loaded
function GM_wait() {
	if (typeof unsafeWindow.jQuery == 'undefined') {
		window.setTimeout(GM_wait, 100);
	} else {
		$ = unsafeWindow.jQuery.noConflict(true);
		letsJQuery();
	}
}
 
// All your GM code must be inside this function
function letsJQuery() {
	//@require does not work for us...
 
	$('span#answer').text('Jaaa!');
	$('#datum').replaceWith('<span style="font-size: 200%; font-weight:bold; color:white">Het kan nu!</span>');
}
Categories: Coding Tags: ,

Deserializing XML twitter feeds.

July 2nd, 2010 Wytze No comments

1. Use xsd.exe to extract an xsd file from an xml feed.
Download a private xml feed for example from “http://api.twitter.com/1/statuses/user_timeline.xml” and store it to local disk. Use xsd.exe to generate the xsd.
2. Generate the classes from the xsd file you just generated.

xsd.exe yourxsd.xsd /c

3. Add the generated classes to your C# project.
4. Time for some fetching here is a short example:

// encode the username/password
string user = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password));
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://api.twitter.com/1/statuses/user_timeline.xml");
// set the method to GET
request.Method = "GET";
request.ServicePoint.Expect100Continue = false;
// set the authorisation levels
request.Headers.Add("Authorization", "Basic " + user);
request.ContentType = "application/x-www-form-urlencoded";
 
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
	XmlSerializer serializer = new XmlSerializer(typeof(statuses));
	statuses s = serializer.Deserialize(response.GetResponseStream()) as statuses;
 
	listBox1.Items.Clear();
	foreach (statusesStatus status in s.status)
	{
		listBox1.Items.Add(status.text);
	}
}

Getting user GUID from Active Directory.

June 29th, 2010 Wytze No comments

Sometimes you need to get a GUID for an entry in Active Directory. There are several tools available to do this. This is just one example how you could approach this.

To go the network where you can search/browse AD.

Perform a search and modify the columns you want to view. Look for a Distinguished Name property and add it. We will use it to retrieve the GUID.

Create a simple vbs script to retrieve the GUID and write it to a text file.

Set objFSO = CreateObject("Scripting.FileSystemObject")
ForWriting = 2
Set file = objFSO.OpenTextFile("C:\Windows\Temp\guid.txt", ForWriting, true)
 
Set sampleUser = GetObject("LDAP://CN=Wytze van der Ploeg,OU=kantoor,DC=vincis,DC=nl")
file.WriteLine("User: " & sampleUser.Name & " " & sampleUser.Guid)
 
file.Close

Done.

Jackrabbit configuration

April 16th, 2010 Wytze No comments
1. Download the jackrabbit jca from http://jackrabbit.apache.org/downloads.html
2. Deploy it on glassfish
3. Create a new Resource Adapter Configuration (Create a new Thread-pool first if you want)
4. Create a new Connector Connection Pool with the new Resource Adapter Configuration
Add the following properties:
homeDir <full path to where your repository is located>
configFile <full path to where your repository config (repository.xml) is located>
5. Create the connector resource and name it 'jcr/repository' for example.

You can now access your repository in the code. Below is a sample.

package com.famvdploeg.jackrabbit;
 
import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
 
/**
 *
 * @author wytze
 */
@Stateless
public class JackrabbitManager {
 
	@Resource(mappedName="jcr/repository", type=javax.jcr.Repository.class)
	private Repository repository;
 
	public String getFromRepo() {
		try {
			Session session = repository.login(new SimpleCredentials("username", "password".toCharArray()));
			Node root = session.getRootNode();
			Node hello = root.addNode("hello");
			hello.setProperty("message", "Hello, World!");
			session.save();
 
			// Retrieve content
            		Node node = root.getNode("hello");
            		System.out.println(node.getPath());
            		System.out.println(node.getProperty("message").getString());
 
			root.getNode("hello").remove();
 
			return "Created and removed!";
		} catch (Exception ex) {
			return ex.getMessage();
		}
	}
}

A possible Java EE 6 Servlet which you can use for WebDAV support. You will need jackrabbit-jcr-server for the base servlet. You can get it by building the source package with maven.

package com.famvdploeg.jackrabbit;
 
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.jcr.Repository;
import javax.servlet.annotation.WebServlet;
import javax.servlet.annotation.WebInitParam;
 
/**
 *
 * @author wytze
 */
@WebServlet(
	name = "webdav",
	urlPatterns = "/repository/*",
	initParams = {
		@WebInitParam(name = "resource-path-prefix", value = "/repository"),
		@WebInitParam(name = "missing-auth-mapping", value = "admin:admin"),
		@WebInitParam(name = "resource-config", value = "/WEB-INF/config.xml")
	}
)
public class SimpleWebdavServlet extends org.apache.jackrabbit.webdav.simple.SimpleWebdavServlet {
 
	@EJB
	private RepositoryFactory repositoryFactory;
 
	private Repository repository;
 
	@PostConstruct
	public void postConstruct() {
		repository = repositoryFactory.getRepository();
	}
 
	@Override
	public Repository getRepository() {
		return repository;
	}
}

Possible extended configuration of the repository:

<!-- Store all items larger than 256 bytes in the FileDataStore -->
<DataStore class="org.apache.jackrabbit.core.data.FileDataStore">
        <param name="path" value="${rep.home}/repository/datastore"/>
        <param name="minRecordLength" value="256"/>
</DataStore>
Categories: Uncategorized Tags:

Visual Studio copy selection macro

April 15th, 2010 Wytze No comments

I use the copy line / copy selection under cursor in NetBeans a lot. So I created this macro for use in Visual Studio that provides this functionality. If no line is selected the current line where the cursor is placed will be copied.
When a selection is made the selection will be copied and pasted below the selection. Afterwards the selection will be remade so you can repeat the action immediately.

Below is the VB snippet.

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
 
Public Module Famvdploeg
    ' Copy the current line or selection
    Sub CopySelection()
        Dim selection As String
        Dim lines As Array
 
        ' Select current line if nothing is selected
        If String.IsNullOrEmpty(DTE.ActiveDocument.Selection.Text) Then
            DTE.ActiveDocument.Selection.StartOfLine(0)
            DTE.ActiveDocument.Selection.EndOfLine(True)
        End If
 
        ' Store some variables
        selection = DTE.ActiveDocument.Selection.Text
        lines = Split(selection, vbCrLf)
 
        ' Perform the copy+paste action depending on how selection is made
        If String.IsNullOrEmpty(lines(lines.Length - 1)) Then
            DTE.ActiveDocument.Selection.Copy()
            DTE.ActiveDocument.Selection.EndOfLine(0)
            DTE.ActiveDocument.Selection.StartOfLine(0)
            DTE.ActiveDocument.Selection.Paste()
        Else            
            DTE.ActiveDocument.Selection.Copy()
            DTE.ActiveDocument.Selection.EndOfLine()
            DTE.ActiveDocument.Selection.NewLine()
            DTE.ActiveDocument.Selection.StartOfLine(0)
            DTE.ActiveDocument.Selection.Paste()
        End If
 
        If lines.Length > 1 Then
            ' ReSelect the text so we can repeat the action immediately
            DTE.ActiveDocument.Selection.LineUp(False, lines.Length - 1)
            DTE.ActiveDocument.Selection.StartOfLine(0)
            DTE.ActiveDocument.Selection.LineDown(True, lines.Length - 1)
            If Not String.IsNullOrEmpty(lines(lines.Length - 1)) Then
                DTE.ActiveDocument.Selection.EndOfLine(True)
            End If
        Else
            DTE.ActiveDocument.Selection.StartOfLine(0)
        End If
    End Sub
End Module

Some basic Glassfish commands

April 14th, 2010 Wytze No comments

I ran out of brain capacity. So here is a list of commands to do some basic glassfish stuff.

Updating: pkg image-update
Start domain: asadmin start-domain
Stop domain: asadmin stop-domain
Deploy item: asadmin deploy <path to file>
List JNDI entries: asadmin list-jndi-entries
Categories: Uncategorized Tags:

Basic iptables configuration

January 20th, 2010 Wytze 1 comment

Here is a small basic example allowing you to setup your iptables.

First we reset everything. See the man page for exact details on the parameters we use.

iptables -F
iptables -Z
iptables -X

Create some chains that will provide us with some logging.

iptables -N logdrop
iptables -N logreject
iptables -N logaccept

Add some rules to these chains.

iptables -A logdrop -j LOG --log-prefix 'DROP: ' --log-level warning
iptables -A logdrop -j DROP
iptables -A logreject -j LOG --log-prefix 'REJECT: ' --log-level warning
iptables -A logreject -j REJECT
iptables -A logaccept -j LOG --log-prefix 'ACCEPT: ' --log-level warning
iptables -A logaccept -j ACCEPT

Now you have a basic setup with some logging.
The next step will be to apply your rules and jump to the corresponding chain on a positive match.
You could set the default policies for the INPUT, FORWARD and OUTPUT chains to ACCEPT and add a jump to logdrop at the end of each chain so that any non-matching rules will be automatically dropped.

Small example:

iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 22 -m state --state NEW -j logaccept
iptables -A INPUT -p tcp -m tcp --dport 443 -m state --state NEW -j logaccept
iptables -A INPUT -p tcp -m tcp --dport 80 -m state --state NEW -j logaccept
iptables -A INPUT -j logdrop
 
iptables -A FORWARD -j logreject
Categories: Linux Tags:

Some bash stuff

August 18th, 2009 Wytze No comments

I just need a cheat sheet because I keep forgetting all these bash things.

Number of parameters: $#
All parameters: $@
String length: ${#foo}
Remove trailing slash: ${foo%/}
Check return value from last command: $?
Categories: Linux Tags:

lm-sensors on the VIA EPIA SN10000EG and SN18000g

July 1st, 2009 Wytze 7 comments

1. Edit /etc/modprobe.d/options.conf
2. Add the following line:

options dme1737 probe_all_addr=1

3. Save and exit
4. Load the module

modprobe dme1737

5. Check that it loaded succesfully:

lsmod

6. Edit the /etc/sysconfig/lm_sensors file

HWMON_MODULES="dme1737"
MODULE_0=dme1737

7. Run sensors to check the output

sensors

8. I also compiled the c7temp module because the in0 didn’t show and loaded it.

mkdir -p /usr/src/c7temp
(I extracted the c7temp.c file from the patch which is placed here:
http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20080619/0dccdaf0/attachment.bin)
touch /usr/src/c7temp/c7temp.c
filled the contents of c7temp.c with those of the patch

Created a makefile in the c7temp dir.

obj-m    := c7temp.o
 
KDIR    := /lib/modules/$(shell uname -r)/build
PWD    := $(shell pwd)
 
default:
	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

And ran make in the c7temp dir. This will get you a .ko file. Install it.

install -m 644 c7temp.ko /lib/modules/`uname -r`/kernel/drivers/hwmon/c7temp.ko

Generate the modules.dep and map files

depmod -a

And load the module

modprobe c7temp

And check that the module loaded with lsmod

lsmod

Modified the /etc/sysconfig/lm_sensors file a bit again

# Generated by sensors-detect on Wed Jul  1 08:43:13 2009
# This file is sourced by /etc/init.d/lm_sensors and defines the modules to
# be loaded/unloaded.
#
# The format of this file is a shell script that simply defines variables:
# HWMON_MODULES for hardware monitoring driver modules, and optionally
# BUS_MODULES for any required bus driver module (for example for I2C or SPI).
 
HWMON_MODULES="dme1737 c7temp"
 
# For compatibility reasons, modules are also listed individually as variables
#    MODULE_0, MODULE_1, MODULE_2, etc.
# You should use BUS_MODULES and HWMON_MODULES instead if possible.
 
MODULE_0=dme1737
MODULE_1=c7temp

Done.
9. I edited the /etc/sensors3.conf file on my machine

chip "sch311x-*"
    ignore in0
 
    label in1 "Vcore"
    label in2 "+3.3V"
    label in3 "+5V"
    label in4 "+12V"
    label in5 "3VSB"
    label in6 "Vbat"
 
    label temp1 "CPU"
    label temp2 "SIO Temp"
    label temp3 "M/B Temp"
 
    set in2_min  3.3 * 0.90
    set in2_max  3.3 * 1.10
    set in3_min  5.0 * 0.90
    set in3_max  5.0 * 1.10
    set in4_min 12.0 * 0.90
    set in4_max 12.0 * 1.10
    set in5_min  3.3 * 0.90
    set in5_max  3.3 * 1.10
    set in6_min  3.0 * 0.90
    set in6_max  3.0 * 1.10
 
chip "c7temp-*"
    ignore temp1
Categories: Debian Tags: