Archive for the ‘ Snippets ’ Category

Calorie Counting Controversy

In my last post, I told users that I am writing a calorie script – this includes a weight-loss/gain calculator, and the ability to track progress. However, I’m running into a snag, as there’s a lot of controversy surrounding the best way to calculate the needed daily calorie intake to hit your target weight in a set time period. The following are all formulas I’ve run across while researching this.

One More Bite:

Desired_Weight x ALM

Peer Trainer:

(Curr_Weight – 10) + (Height_Inch x 4.6) + (Age x 4.7) x ALM

(Wednesday, December 02, 2009, 9:37 AM) Peer Trainer:

Target_Weight x 10

(Thursday, March 30, 2006, 8:35 AM) Peer Trainer:

((Curr_Weight x 11) – Calorie_Min) x Target_Days = a

(Target_Loss_Gain x One_Pound[3500 calories]) – a / (Weekly_Work_Out x Target_Weeks)

BMI Calculator:

Curr_Calories / 20%

*ALM = Activity Level Multiplier

If anyone has other references, suggestions, or knows an accurate formula for weight-loss/gain, feel free to leave a comment below.

I came across a question on answers.yahoo that I felt was somewhat – unintelligent? It stated something along the lines of “Is it alright for me to put 1,000 ‘good’ calories in, and then burn 1,500 calories daily?”. Then I did a little searching, and realized that most individuals have absolutely no idea how many calories they should be putting into their body to make up for what the exert during any given day.

Here’s how calories work… Contrary to popular belief, there is no average based on normality ie. 2,000/daily. It ranges based on four aspects, which are age, height, weight and your exercise routine. I found a few websites that offer visitors to view their estimated daily calorie intake, but any that allow you to manage it so that a user can manage weight loss are all paid membership websites.

I’ve started writing a script that will allow individuals to do the above, free. Because, why should you have to pay cash to use something that you will be inputting all the numbers yourself? So as most of my scripts, this will be completely free, and completely open source for others to learn, share and modify as needed to fit your needs.

You can find the script in ZIP format at http://phux.org/downs/calories.script.06072010.v0.0.1[www.nitobelmont.com].zip.

You can also find the script in readable format in a post on the phux forums: http://forum.phux.org/index.php/topic,316.0.html

Feel free to leave suggestions, feedback or comments =)

PHP Menu: Get Current Page

This is a quick and easy way to determine which page you’re currently on, and then setting your menu button’s overlay based on that page.

First we need to create a function to determine the page we’re on.
function getCurrPage() {
return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}

Next we need to check our this against the menu.
$thisPage = getCurrPage();
if($thisPage == 'index.php') { $navHome = '[Current Class]'; } else { $navHome = '[Noncurrent Class]'; }
if($thisPage == 'search.php') { $navSearch = '[Current Class]'; } else { $navSearch = '[Noncurrent Class]'; }
if($thisPage == 'about.php') { $navAbout = '[Current Class]'; } else { $navAbout = '[Noncurrent Class]'; }
if($thisPage == 'faq.php') { $navFAQ = '[Current Class]'; } else { $navFAQ = '[Noncurrent Class]'; }
if($thisPage == 'contact.php') { $navContact = '[Current Class]'; } else { $navContact = '[Noncurrent Class]'; }

After everything’s been checked, you can simply set your menu as-needed.
echo $navHome . $navSearch . $navAbout . $navFAQ. $navContact;

If you’re dealing with a dozen or more menu links, it would be more efficient to create an array to scan and verify the current page, but this will work fine for smaller menus. Enjoy.

I just got back in to software development after about a year and a half of focusing purely on web development. I can thank the Raptr client for that, because their newest version of the client is disgusting. It hogs all TCP connections, lagging any online games you may be playing, and slowing web page’s to a crawl. I decided to write my own, with a few additions that I feel would benefit me. In doing this, I *borrowed* Raptr’s games list, adding more games they didn’t have listed. I encoded it in Base64, in case I decide to make it a public application, and thus the hunt for a much simpler Base64 decode function started…

Encoding/Decoding Base64 shouldn’t take hundreds of lines of code to do. I was looking for a simple way to decode a base64 text file, without having to use write up an extensive module. In my journey for a cleaner, more simplistic code, I ran across a nice snippet from Tim Hastings which is probably the simplest way to do this.

First, you’ll need to reference XML in your VB6 project:
Project -> References -> Microsoft XML (Any version => 2.6)

Public Function EncodeBase64(ByRef arrData() As Byte) As String

Dim objXML As MSXML2.DOMDocument
Dim objNode As MSXML2.IXMLDOMElement

' help from MSXML
Set objXML = New MSXML2.DOMDocument

' byte array to base64
Set objNode = objXML.createElement("b64")
objNode.dataType = "bin.base64"
objNode.nodeTypedValue = arrData
EncodeBase64 = objNode.Text

' thanks, bye
Set objNode = Nothing
Set objXML = Nothing

End Function

Public Function DecodeBase64(ByVal strData As String) As Byte()

Dim objXML As MSXML2.DOMDocument
Dim objNode As MSXML2.IXMLDOMElement

' help from MSXML
Set objXML = New MSXML2.DOMDocument
Set objNode = objXML.createElement("b64")
objNode.dataType = "bin.base64"
objNode.Text = strData
DecodeBase64 = objNode.nodeTypedValue

' thanks, bye
Set objNode = Nothing
Set objXML = Nothing

End Function

Test the above function by using the following code, which decodes a encoded string back in to it’s original text.

Public Sub Main()
Dim strData As String
strData = EncodeBase64(StrConv("ohaithr", vbFromUnicode))
Debug.Print strData
Debug.Print StrConv(DecodeBase64(strData), vbUnicode)
End Sub

The output should be..
b2hhaXRocg==
ohaithr

*Thanks again to Tim Hastings for posting this on his blog.

-Nito

Promo Code Source

Alright, so as most who know me already know, I do a lot of freelance jobs.. I don’t ever go by the rules they post on the freelance sites such as “You may not start a project until your bid has been selected as the winner.”. I find this to be a retarded rule which shouldn’t be there. Who fucking cares if I work on it before I even get the job? Do you think the people buying the code really give a shit – I think not. If anything, they’d be happier since the job will then be done that much quicker.

Anyways, I recently bid on something people may need code for in the future. I’m not sure if I’ll win the bid, but whatever.. I’m posting the code for free here for future use. I don’t use CSS when I don’t have to, mainly because it’s kind of stupid to write it out if it’s not going up as a full page, or when it’s being integrated into a pre-existing site…

Now this has no fancy admin panel, as like I said before – it’s meant to be integrated into an existing website.

index.php

profile.php

enter_code.php

set_code.php

save_code.php

config.php

inc.php

sql.sql

So there’s the files if you wanna run through ‘em, and integrate it into your own site somehow. And remember, open source is free, so don’t fucking turn around and sell the code and scripts we write for profit, douchebags…

-Nito