Thursday, January 31, 2013

painted "Loved" pins

I recently got myself a set of lighter acrylic paints, and had a pack of blank clothespins around, then this happened:


Six colors of paint, many clothespins, and a set of sharpies met up for a party and created something beautiful.

It took me about a day to paint, write on, and re-assemble the clothespins.  The result is so pleasing that I almost don't want to give them away, but the knowledge that I can always make balances that feeling out.

Wednesday, January 30, 2013

simple yellow back bag

One afternoon I decided to stick a strap on my yellow nylon packing bag, and it turned into a very nice back sling bag.


I have everything I need on the road except for hammocks and food in this bag.  I haven't tried walking with this bag for 5km yet, but I expect it would work fine.

Tuesday, January 29, 2013

java regular expression on byte array

Ever wanted to use a regular expresson on a byte array in Java? It turns out that regular expressions are eight bit safe in Java, and bytes can safely map into the lower half of the character type. With a simple adapter it becomes a trivial task. Demonstration:
package org.yi.happy.binary_regex;

import static org.junit.Assert.assertEquals;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.junit.Test;

public class BinaryRegexTest {
    /**
     * Find line endings in a byte array using a regular expression.
     */
    @Test
    public void testExpression() {
        byte[] data = new byte[] { 'a', '\r', '\r', 'c' };
        Pattern p = Pattern.compile("\r\n?|\n\r?");
        Matcher m = p.matcher(new ByteCharSequence(data));

        assertEquals(true, m.find(0));
        assertEquals(1, m.start());
        assertEquals(2, m.end());

        assertEquals(true, m.find(2));
        assertEquals(2, m.start());
        assertEquals(3, m.end());

        assertEquals(false, m.find(3));
    }

    /**
     * Find null bytes in a byte array using a regular expression.
     */
    @Test
    public void testNull() {
        byte[] data = new byte[] { 'a', 0, 'b', 0 };

        Pattern p = Pattern.compile("\0");
        Matcher m = p.matcher(new ByteCharSequence(data));

        assertEquals(true, m.find(0));
        assertEquals(1, m.start());
        assertEquals(2, m.end());

        assertEquals(true, m.find(2));
        assertEquals(3, m.start());
        assertEquals(4, m.end());

        assertEquals(false, m.find(4));
    }
}
And the adapter is as one might expect,
package org.yi.happy.binary_regex;

public class ByteCharSequence implements CharSequence {

    private final byte[] data;
    private final int length;
    private final int offset;

    public ByteCharSequence(byte[] data) {
        this(data, 0, data.length);
    }

    public ByteCharSequence(byte[] data, int offset, int length) {
        this.data = data;
        this.offset = offset;
        this.length = length;
    }

    @Override
    public int length() {
        return this.length;
    }

    @Override
    public char charAt(int index) {
        return (char) (data[offset + index] & 0xff);
    }

    @Override
    public CharSequence subSequence(int start, int end) {
        return new ByteCharSequence(data, offset + start, end - start);
    }

}

Sunday, January 27, 2013

More rainbow lighters

I wanted another rainbow lighter, so I went to the hardware store, got a five pack of BIC lighters, taped them, and painted them over a game of risk.


I used someone else's paint for the upper five colours, and I like the shade that I ended up with more than the shade on my existing lighter.

Wednesday, January 23, 2013

Long rainbow fleece scarf

Today I decided that I had spent enough time flattening my single layer rainbow fleece scarf out, so I doubled the thickness and made it longer.  Now it is about 2.25m long and about 25cm wide.  I also did not full close up the cross seams connecting the sections of fleece together, giving me the ability to stick small things in the resulting pockets on the ends of the scarf.


The scarf barely shows up on the rainbow sweater, it is interesting how rainbow blends into rainbow so well.

Rainbow fleece sweater jacket

Yesterday I made another rainbow fleece sweater jacket, for wearing under my rainbow fleece jacket, or over it.  This one has ties instead of buttons and I am not going to put any elastics in the sleeves, so they will stay covering my hands when they fall down.

 

I actually have a scarf on in the picture on the left, but it blends into the outfit extremely well.

Blue flower print sweater

A while ago I made another sweater like the rainbow jacket, using the same pattern, but as an under layer to go with the jacket, it is blue flower printed fleece that formerly was dollar store blankets.  The ties on the front are ribbons.