Slow cooked goat 2012-02-22

I went to the zoo last weekend with my family and got a chance to stop and pet a goat. And it got me thinking, what does goat taste like? I decided to stop by my local butcher to see if they had any.

I was in luck! They had several cuts of goat- from ribs to limbs to organs. I asked what the butcher's favorite cut of goat was and the answer was shoulder. Goat shoulder.

The meat looked pretty good. This is 4lbs of goat shoulder. It looked lean and delicious. here's a close up.

Read online to slow cook it but I hate waiting for food, so I used my convection oven to slow cook it. It is supposed to cook for ~6 hours but I was able to get away with 4. I dressed it with salt, pepper, oregano, and thyme.

On the side I did bacon with stirfried kale in bacon fat. This side dish is one of the easiest and tastiests things to prepare. You chop raw bacon, fry it, and then dump kale into the pan and stirfry it with the resulting bacon and fat. It's awesome.

The end result was great. The meat fell off the bone and was very moist towards the center of the cut. Next time I do it I'm going to wrap the whole thing in tinfoil before I roast it because it would have been better even more moist. The meat tastes like lamb but much less gamey. I would say it is a beefier lamb. It's really good.

Lifes Alright

New camera 2012-02-16

I can finally take pictures with something other than my phone now. I got a Nikon D5100 manufacturer refurbished for $590. It arrived today and it's awesome. Took a couple test pictures of my dinner. I had a surf and turf with shrimp.

Definitely an improvement over the phone. Next I'll have to learn how to use this thing and later get a better lens. I'll definitely be posting more pictures here now that I have this.



Lifes Alright

Calulcated background image position 2012-02-15

I have a project where I need to know the pixel value for a backgroundImage's position. The problem? The positions are percentages. For example, the backgroundPosition for my background image is 50% 30%... and I need to know the PIXEL value for that! Dynamically!

CSS calulates the background position not just by the percent of the element. For example, you can't set the background position to 50% of the body's width and expect that to have the same result as background-position: 50%. The browser takes the size of the image itself into consideration. It centers the center of the image with the center of the element. So you need to have both the dimensions of the image and the dimensions of the element.

So here's how I went about doing it. This function takes an id for the element who has the background image, and the percentages you want calculated. It returns an array of the width and height.

// Example:
// backgroundPositionX = getBackgroundPosByPercent('body', 50, 30)[0]

function getBackgroundPosByPercent(id, widthP, heightP) {
    elm = document.getElementById(id);
    style = elm.currentStyle || window.getComputedStyle(elm, false);
    imgurl = style.backgroundImage.slice(4, -1);
    imgurl = imgurl.replace(/"/g, '');
    imgelm = new Image();
    imgelm.src = imgurl;
    imgwidth = imgelm.width;
    imgheight = imgelm.height;
    elmwidth = style.width.replace('px', '');
    elmheight = style.height.replace('px', '');
    windowWidth = 0;
    return [((elmwidth*widthP)/100) - ((imgwidth*widthP)/100), ((elmheight*heightP)/100) - ((imgheight*heightP)/100)] 
}

Lifes Alright

Pty allocation failed? 2012-02-13

I've ran into this problem a few times on several VPS's over the years. Thought I would make a note of the solution here for the future and for anyone else. The exact error is:

[blice@blice ~]$ ssh blice@domain
blice@domains password: 
PTY allocation request failed on channel 0

The problem is usually that for whatever reason you've failed to mount /dev/pts on your last reboot. Luckily this error doesn't stop us from executing commands via ssh, only stops us from getting a prompt. So we just get it mounted and then we should be good.

ssh root@domain mount -v -t devpts none /dev/pts
Lifes Alright

Strength Standards 2012-02-06

I made a tool for checking strength standards, inspired by the one over at strstd.com. I added totals at the bottom and (indirectly) made it more true to Rippetoe's strength standards. I also use a different 1RM algorithm than the other site. I find his come out a little high so I dug out a study that shows the wathan algorithm produced a lower error margin across the board. The study uses untrained people which makes it nearly irrelivent but it's the only data I have and the numbers are right for me, so I'm sticking to it.

Gender: Bodyweight: lbs

Squat lbs for Reps

Press lbs for Reps

Bench lbs for Reps

Deadlift lbs for Reps

Clean lbs for Reps

Lifes Alright

Nutrition Hack: Kelp Granules 2012-01-31

Nutrition Facts
Serving Size 10g
Amount Per Serving
Calories 4
% Daily Value *
Total Fat 0g 0%
Saturated Fat 0g 0%
Trans Fat 0g
Cholesterol 0mg 0%
Sodium 23mg 1%
Total Carbohydrate 1g 0%
Dietary Fiber 0g 1%
Sugars 0g
Protein 0.17mg
* The Percent Daily Values are based on a 2,000 calorie diet, so your values may change depending on your calorie needs.
Vitamins
Amounts Per Selected Serving
Vitamin A 11.6 IU 0%
Vitamin C 0.3mg 1%
Vitamin D ~ ~
Vitamin E 0.1mg 0%
Thiamin 0.0g 0%
Riboflavin 0.0g 1%
Niacin 0.0g 0%
Vitamin B6 0.0g 0%
Folate 18.0mcg 5%
Vitamin B16 0.0mcg 0%
Pantothenic Acid 0.1mg 1%
Choline 1.3mg
Minerals
Amounts per Selected Serving
Calcium 16.8mg 2%
Iron 0.3mg 2%
Magnesium 12.1mg 3%
Phosphorus 4.2mg 0%
Potassium 8.9mg 0%
Sodium 23.3mg 1%
Zinc 0.1mg 1%
Copper 0.0mg 1%
Manganese 0.0mg 1%
Selenium 0.1mcg 0%

Kelp is amazing. Besides being one of the few foods with iodine, kelp also has calcium, phosphorus, selenium, carotene, vitamin B1, and also alginic acid which prevents the function of leukemia, stomach cancer, and lowers blood pressure. There's also a correlation between kelp consumption and lowered LDL Type B particles.

But here's the 'hack' part; Kelp granules are very salty. Infact they taste like.. salt. They have a very mild "green" flavor that is very overpowered by their saltiness. Because of this you can literally use kelp instead of salt. I do. I dust my hard boiled eggs with kelp, I use kelp in sauces, spices, and general seasoning instead of salt. If you are on a "no refined-salt" diet, this could be the perfect solution. (By the way I say no refined salt diet because low sodum diets are unhealthy)

Lifes Alright

Train Like an Athlete 2012-01-09

I'm doing Mark Rippetoe's Starting Strength program for basic strength and conditioning. I've been doing it for 3 months now and I've been thinking about what I'm going to do when I stall on my lifts. The options I have going forward are to continue to an intermediate powerlifting routine or to go foward to a novice olympic weightlifting routine, like the one outlined in Gregg Everett's book.

I've decided at least to do Jim Steel's "Train Like an Athlete" program after SS before I move on. It's a 9 week program that will be a nice break. The program is in three 3 week segments and introduces some stuff like sprinting and box jumps. It alternates two lifting days and 3 running days a week, with two days of rest, to look like LRxLRRx.

Full program is below for my own memory... some terms like "Square of death" are described in the original blog posts by Jim Steel.

Week 1
Week 2
Week 3
Week 4
Week 5
Week 6
Week 7
Week 8
Week 9 - PR Week

Lifes Alright

UNO Module 2011-12-20

Here's an UNO module I wrote, enjoy.

#!/usr/bin/python
import random, datetime

class player():
    def __init__(self, uno):
        self.game = uno
        self.hand = []
        self.turn = 0
        self.pi = 0 #Picked up card flag.
        self.prevdeck = [] #If this isn't [] he's played an illegal hand and needs to replay out of prevdeck.


    def laydown(self, card):
        self.game.discard = card
        try:
            self.hand.remove(card)
        except:
            #Not in hand, probably a wild.
            self.hand.remove(card[1:])

        self.game.nextturn()
        self.pi = 0
        self.prevdeck = []

    def pas(self):
        """Pass the turn"""
        drawn = []
        if not self.pi and not self.game.pstack:
            #You need to pick up a card first.
            return 1

        if not self.turn:
            return 2

        elif self.game.pstack:
            #Pick it up.
            drawn = self.game.draw(self.game.pstack)
            self.hand += drawn
            self.game.pstack = 0

        self.pi = 0
        self.game.nextturn()
        self.prevdeck = []
        return drawn

    def draw(self):
        if not self.turn:
            return 2

        if not self.pi and not self.game.pstack:
            drawed = self.game.draw()
            self.hand += drawed
            self.pi = 1
            return drawed

        elif self.game.pstack:
            #Pick it up.
            drawed = self.game.draw(self.game.pstack)
            self.hand += drawed
            self.game.pstack = 0
            self.game.nextturn()
            return drawed

        else:
            #You've already drawn.
            return 1
        
    

    def play(self, card):
        """Play a card"""

        if not card in self.hand or card[0] == 'w':
            #Doesn't have that card.
            #But could be wild, lets check.
            if not card[1:] in self.hand:
                return 1

        if self.prevdeck:
            #He can only play out of his previous hand.
            if not card in self.prevdeck:
                if not card[1:] in self.prevdeck:
                    return 1

        if not self.turn:
            #Not your turn.
            return 2

        if (card[0] == self.game.discard[0] or card[1] == self.game.discard[1] or card[1] == 'w') and self.game.pstack == 0:
            #Legal.
            #Check if they are playing a +.
            self.game.illegalplay = 0
            if len(card) >= 3:
                self.game.pstack = int(card[-1])
                #If it's a wild+4 we need to check if it's legal.
                if len(card) == 4:
                    for x in self.hand:
                        if x[0] == self.game.discard[0]:
                            self.game.illegalplay = 1

            elif card[1] == 'r':
                self.game.reverse()
                if len(self.game.players) == 2:
                    self.game.nextturn()

            elif card[1] == 's':
                self.game.skip()


            self.laydown(card)

        elif self.game.pstack != 0:
            #If they are playing another + they can play so long as its higher or == what was previously played. Or a reverse.
            if len(card) >= 3:
                try:
                    discardint = int(self.game.discard[-1])
                except:
                    #Reverse. Treat it as a 4, I guess.
                    discardint = 4

                if int(card[-1]) >= discardint:
                    #Legal.
                    self.game.pstack += int(card[-1])
                    self.laydown(card)
                else:
                    return 3

            elif card[1] == 'r' and card[0] == self.game.discard[0]:
                #Legal.
                self.game.reverse()
                self.laydown(card)

            else:
                #Illegal.
                return 3

        else:
            #ILLEGAL
            return 3



class UNO():
    def __init__(self):
        self.players = {}
        self.gendeck()
        self.discard = ''
        self.turn = 0
        self.pstack = 0 #Plus stack, how many should they draw now?
        self.plist = []
        self.illegalplay = 0 #Flag for if wild+4s are legally played.
        self.starttime = 0

    def gendeck(self):
        colors = ['r', 'g', 'b', 'y']
        cards = [str(num) for num in range(1,10)] #NUMBERS
        cards += ['r', 's', '+2'] #SPECIALS
        self.deck = [color+card for card in cards*2 for color in colors] + [color+'0' for color in colors] + ['w+4', 'w']*4
        random.shuffle(self.deck)

    def draw(self, num=1):
        """Draw some amount of cards."""
        return [self.deck.pop() for x in range(0,num)]

    def addplayer(self, nick):
        """Add a player."""
        if nick in self.players:
            return 1
        else:
            self.players[nick] = player(self)
            self.plist.append(nick)
            if self.discard:
                #The game was already started so we should probably give them cards.
                self.players[nick].hand = self.draw(7)

    def start(self):
        """Start the game."""
        if len(self.players) < 2:
            return 1

        if self.discard:
            return 2

        #Lay down the discard.
        x = player(self)
        x.hand = self.draw()
        while x.hand[0][0] == 'w': #We can't put down a wild as the fisrt card.
            self.deck = x.hand + self.deck
            x.hand = self.draw()
        #We want the discard to have an effect on the next player, eg, b+2, so we make a player object to play the discard.

        self.discard = x.hand[0]
        x.play(x.hand[0])


        #Deal the cards.
        for person in self.players:
            self.players[person].hand = self.draw(7)

        #Set the first players turn.
        firstplayer = self.plist[0]
        self.players[firstplayer].turn = 1
        self.turn = 0

        #Time started.
        self.starttime = datetime.datetime.now()

    def currentplayer(self):
        """Shortcut to see who's turn it is."""
        return self.plist[self.turn]
        

    def nextturn(self):
        self.players[self.plist[self.turn]].turn = 0

        if len(self.players.keys()) > self.turn + 1:
            self.turn += 1

        else:
            self.turn = 0

        nextplayer = self.plist[self.turn]
        self.players[nextplayer].turn = 1

    def changeturn(self, player):
        """Change someone's turn manually."""
        playernumber = self.plist.index(player)
        self.players[self.plist[self.turn]].turn = 0
        self.turn = playernumber
        self.players[self.plist[playernumber]].turn = 1

    def reverse(self):
        curturn = self.currentplayer()
        self.plist.reverse()
        self.turn = self.plist.index(curturn)

    def skip(self):
        """Skip the next player in line."""
        self.nextturn()


    def challenge(self):
        """Challenge a w+4. If play was illegal, he draws 6 cards and playes again."""
        if self.discard[1:] != 'w+4':
            return 1

        if self.pstack > 4:
            return 1

        if self.illegalplay != 1:
            return 2

        self.reverse()
        self.nextturn()
        self.reverse()
        self.pstack = 0
        for card in self.players[self.plist[self.turn]].hand:
            self.players[self.plist[self.turn]].prevdeck.append(card)
        self.players[self.plist[self.turn]].hand += self.draw(6)

Example Usage:

>>> from uno import UNO
>>> game = UNO()
>>> game.addplayer('Wibox')
>>> game.addplayer('Neo')
>>> game.start()
>>> game.discard
'r3'
>>> game.currentplayer()
'Wibox'
>>> game.players['Wibox'].hand
['b+2', 'y1', 'y8', 'r5', 'y3', 'b6', 'r3']
>>> game.players['Wibox'].play('r3')
>>> game.players['Neo'].hand
['r2', 'g4', 'gs', 'g2', 'g9', 'r+2', 'b6']
>>> game.players['Neo'].play('r+2')
>>> game.players['Wibox'].play('b+2')
>>> game.players['Neo'].draw()
>>> game.players['Wibox'].play('b6')
Lifes Alright