Introducing: Nested Scroll

Published by cybso on

Nested Scroll is a Javascript library that allows you to scroll
selected elements into the viewport. You can define if the element should be aligned to the upper, lower, left or right
boundary, or let Nested Scroll automatically decide depending on the shortest path.

Additionally, it is possible to define some animation methods, respect the element's border and margin
and add extra margins on each side when scrolling.

But what makes this library unique compared to other libraries I've looked into is that it that it
not only works with vertical but also with horizontal scrollbars, with nested scrollable DIVs
and with fixed elements!

Usage

  // Scroll with default options
  var target = document.getElementById('target-element');
  nestedScroll(target);

  // Scroll with additional parameters
  var options = {
    // See section options
    animationMethod: 'easeInOut',
    animationTimeout: 500,
    force: true,
    align: 'auto',
    withCssMargins: true,
    marginTop: 10,
    marginLeft: 10,
    marginRight: 10,
    marginBottom: 10
  };
  nestedScroll(target, options);

  // Define a global option
  nestesScroll.defaultOptions['animationMethod'] = 'easeIn';

Download

Download the library on github.

Disclamer: This is tested on Vivaldi 1.10, Firefox 52 and Chromium 59. Edge should also work, but I had some problems using the example file with IE11. Maybe I'll fix this later, or somebody as does ;-)

Mod: Wii Sensor Bar with USB power supply

Published by cybso on

My Wii Sensor Bar is built of two arrays of IR-LED that get its power from a proprietary port on the Wii / WiiU. Since I have a beamer as second screen with its own Sensor Bar, a Wii-to-HDMI-Adapter and a 4x2 HDMI switch I don't want to unplug and reconnect the sensor bar cable anymore when I switch from one screen to the other.

My idea: connect one sensor bar to the USB port of the TV, and the other one to the USB port of the beamer, so both will only be enabled when the specific screen is in use. Another reason to get power from an external power supply could be that you have both, a Wii and a WiiU.

So, I've tried to find out what current and amperage the sensor bar requires, and since I did not find any reliable information I've took a screwdriver, my multimeter and had a look at it.

Important: These pictures where taken on a cloned sensor bar from ebay since I don't have a screwdriver for the Tri-Wings Nintendo used on the original one. The original sensor bar has five LEDs on each side which means that you would have to short-circuit two of them when following this guide. Otherwise you would need a power source with a minimum current of 7.5V.

If you don't want to hack your original sensor bar and don't have a cloned one you could also buy a cloned sensor bar that comes with an USB connector.

When measured at the connector on the Wii's backside the multimeter shows a current of 12V. But measured under load directly at the sensor bar the current goes down to 5.5V. I think this is due to the relative long cable combined with extremly thin wires, resulting in a relative high resistivity R0. However, the exact value doesn't matter since I will replace the cable anyway.

My sensor bar consists of two arrays of three LED, both having their own R1=24Ω resistors. I'm not sure what kind of infrared LED is used but some googling reveals that 940nm seems to be reasonable. Typical values for these LEDs are a Vf=1.5V and If=50mA, so we have 150mA on each side and a total of 300mA a total of 100mA (thanks @ Daniel for correcting this error). The minimal required current is 3*1.5V=4.5V, which is lower than the 5V specified for USB[1] (if your sensor bar has more LEDs on each side you should bridge or remove all but three on each side). Combined with a 10Ω resistor R1 on each side this should be fine.

The first step is to unsolder the existing cable. Use a desoldering pump to clean the holes on the board from the old solder. Now take an existing USB cable (for example an old MicroUSB cable), remove the Type B plug and strip the isolation. You only need the wires for +5V and Ground, which are typically colored in red and black, so you should remove the other ones. Strip the inner isolation, put some solder on the conductors and connect them with the ports on the board where the original cable was connected. The holes are labed on the back side of the board with + (red) and - (black). The + conductor is connected with the first LED on both sides, the - conductor with the resistors. If you inadvertently switched the poles, this is not fatal, since diodes only allow the current to pass in one direction - but the sensor bar will not work, of course.

Next, remove the original resistors and replace each of them with a 10Ω resistor.

Now you should take your multimeter and a camera (most digital cameras are able to see infrared light) and check if the sensor bar works. For personal security I suggest to use an external power bank for this test.

If you see the IR-LEDs on the camera screen you can connect the sensor bar to your TV and test them. Maybe you have to calibrate the sensivity of your Wiimotes since the brightness might have changed, especially when you were forced to bridge some LEDs.

[1]: Please note that USB uses a low-power mode per default that does not allow a device to pull more that 100mA from the port. If a device requires more power (up to 500mA) it has to ask the USB controller for permission. Since this requires active components we do not have please ensure that no other USB devices are connected to the same port, or usea dedicated USB power supply.

How to merge Apache access logs and sort them by date

Published by cybso on

Just dropping this here:

https://gist.github.com/Cybso/77b8f7bdec78e0a8df8f8435e3ccb8fc

# Sorts the rows of one or multiple apache access_log files by date (ascending) 
# and converts them from 'common' log format
# into 'combined' (if you switched the log file format meanwhile).
#
# This is useful when you want to merge multiple log files, e.g. when
# you have different files for HTTP and HTTPS.
#
# Usage:
#     sort-access-log [file [file...]]
#
# If the argument ends on .gz it will be extracted using 'gunzip'.
# If no argument has been given the script expects the input on STDIN.
#
# The date is expected to have the following format, which must occur
# *anywhere* within the line:
#
#     [20/Mar/2017:12:00:37 +0100]
#
# The timezone argument is ignored, so this might be inaccurate when
# changing from summer time to winter time - for me this doesn't matter.
#
# The output of the program can be used as input for awffull or
# webalizer.

Put a stamp on the last page of a PDF document

Published by cybso on

PDFTK, the swiss-knife pdf toolkit, can be used to put a stamp an all pages of a pdf file; but it is not possible to put the stamp on the last page only. There is a commercial tool "stamptk" available for this. But you can also workaround this with a few lines of shell code:

input="INPUT.pdf"
stamp="STAMP.pdf"
output="OUTPUT.pdf"
tmp1="tmp1.pdf"
tmp2="tmp2.pdf"

pdftk "$input" cat end output "$tmp1"
pdftk "$tmp1" stamp "$stamp" output "$tmp2"
pdftk "$input" cat 1-r2 output "$tmp1"
pdftk "$tmp1" "$tmp2" cat output "$output"

I've put this code into a simple bash script and uploaded it to github: stamp-last-page.sh.


Program Arduino Pro Mini with CP2102 USB module

Published by cybso on

When I ordered a bunch of Arduino Pro Mini clones I didn't notice that these don't come with an integrated USB-to-Serial adapter (in fact I needed Arduino Nano - well, I was relative new into this).

So to get a change to use them I've also ordered a CP2102 board that converts between USB and TTL. Since it took a while for me to figure out how to use that I will document it here.

First, connect the CP2102 with the Arduino:

CP2102Arduino Pro Mini
DTRDTR
RXDTXO
TXDRXI
(5V)*5V
(CTS)**GND
GNDGND
*) Optional, only if the Arduino isn't powered from another source
**) Optional, worked for me without connecting CTS to GND

Next, select the correct configuration.

Arduino IDE

Board: "Arduino Pro or Pro Mini"
Processor: "ATmega328 (5V, 16MHz)" (or the one that is soldered on your board)
Port: /dev/ttyUSB0 (or whatever port the CP2101 is connected to)
Programmer: "ArduinoISP"

Eclipse

Board: "Arduino Pro or Pro Mini"
Processor: "ATmega328 (5V, 16MHz)" (or the one that is soldered on your board)
Port: /dev/ttyUSB0 (or whatever port the CP2101 is connected to)
Upload Protocol: "Default"

Command Line

$ avrdude -C/etc/avrdude.conf <strong>-patmega328p -carduino -P/dev/ttyUSB0 -b57600 </strong>-D -Uflash:w:PATH_TO_HEXFILE:i