Hex Addition function

Posted in Uncategorized by Julian Kessel - May 02, 2010

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
def add_hex(arr):
    result = 0x0
    index = 0
    while True:
        print index
        try:
            result = result + int(arr[index], 16) + int(arr[index+1], 16)
        except IndexError:
            try:
                result = result + int(arr[index], 16)
            except IndexError:
                pass
            result = hex(result)
            break
        index+=2
    return result
 
print add_hex2(['0x01', '0x05', '0x04', '0x09', '0x17'])
Tags: COMMENTS

Date subtraction SQL snippet for OpenOffice base

Posted in Programming by Julian Kessel - Oct 23, 2009

With this simple line condition in OpenOffice base’s hsqldb it is possible to subtract a date fragment, and in order to this, select the matching entries. My example is a query on a column containing birthdates in the german format DD-MM-YY.

It selects the entries (persons) who are under the age of 20.

SELECT “birthdate” AS “Birthdate” FROM “under20″ AS “under20″ WHERE (datediff(‘yy’, “BIRTHDATE”, CURRENT_DATE)) <= 20

Instead of  ‘yy’ it’s possible to take the following other values:

‘ms’=millisecond

‘ss’=second

‘mi’=minute

‘hh’=hour

‘dd’=day

‘mm’=month

Tags: , COMMENTS

Install additional packages on pfSense 1.2.3-RC1

Posted in Uncategorized by Julian Kessel - Oct 14, 2009

There is no package manager in pfSense 1.2.3-RC1, though you can install FreeBSD ports via “Diagnostics > Command”.

Type

pkg_add URLofthePackage.tbz

in the field and press return.

the packages can be found at ftp://ftp.freebsd.org/pub/FreeBSD/ports/packages/category (BTW. there’s a complete list at the parent directory)

In most cases you will have to use a SSH or serial connection to configure the programs. Please also keep in mind that more daemons slow down the boot process significantly, especially on embedded devices !

The pkg_add(1) utility uses fetch(1) to download the precompiled package and installs it automatically. On regular (bigger) FreeBSD systems you will pull a complete directory of ports into your local ports directory from the FreeBSD servers in use of the program cvsup. Since this is method of getting new programs was not meant to be used on embedded systems on which that dump just fills up the small flash disks, the manual way of getting the packages is preferred. Another reason why it’s necessary to use precompiled packages is that most of the embedded OS’ bring no compiler with themselves.

An experience I made while setting up a ftp server that the filesystem is read-only. The developers explain it is due to the limited writecycles on flashable media, so the volume gets mounted for updating the cfg file only. You have to use the web-based cmdline for executing file-modifying commands. That also includes SSH which isn’t even with root rights able to write something.

Tags: COMMENTS

BASH – generate a pseudo-random user agent

Posted in Programming by Julian Kessel - Oct 01, 2009

The following script will give you a user agent randomly out of a big list of all user agents that exist.

1
2
3
4
5
6
7
8
9
#!/bin/bash
 
userAgents=`curl -s http://www.user-agents.org/allagents.xml | grep -iB 5 '<Type>B</Type>' | grep -i '<String>' | cut -c 9- | sed 's/..........$//'`
maxLines=`echo "$userAgents" | wc -l | tr -d ' '`
randomUserAgent=$(echo "$userAgents" | sed -n $[ ( $RANDOM % ( $[ $maxLines - 1 ] + 1 ) ) + 1 ]p)
 
echo $randomUserAgent
 
</string>

The script searches for a type “B” in the xml document, which stands for Browser, if you want to include other types, write the letter in place of, or with one space seperated from “B”. It’s possible to specify more than 2 types.

B = Browser
C = Link-, bookmark-, server- checking D = Downloading tool
P = Proxy server, web filtering
R = Robot, crawler, spider
S = Spam or bad bot

Tags: COMMENTS

This tiny applescript lets you copy all files on any Playlist in Your iTunes Library to any folder you want. For example on an external hard drive.

If you have suggestions for features or fixes, comment.

cPlaylist.scpt (.scpt – Applescript Source)

cPlaylist.app (.app binary build)

Tags: COMMENTS