29
Dec/09
0

Project Euler Problems

Just started two days ago. Lots of fun.

Notes to self: javascript is cool and does crazy things

int are very limited

use float and double

if output is not the right precision, use setprecision(x) where x is an int

math.h -> cmath

there are a lot of STL data structures.. vector, queue, stack, etc.

Filed under: Journalish
26
Dec/09
0

String Library for PHP

I am just creating string functions for PHP that I tend to need. If you want to use it feel free to.

<?php
/************************************************
Programmer: Robin Chang
Date:       12/26/09
Description:
String library
************************************************/

// $content = haystack; $start = needle; $stop = ending needle
// returns string starting from the end of $start until the beginning of $stop
//      substrR(”what now”,”h”,”w”) returns “at no”
function cut($content,$start,$stop)
{
$cutOff = strlen($start);
$strStart = strpos($content,$start);
$content2 = substr($content,$strStart);
return substr($content,$strStart+$cutOff,strpos($content2,$stop)-$cutOff);
}

// $content = haystack; $start = needle
// returns string starting from the end of $start until the end
//      substrR(”what”,”h”) returns “at”
function substrR($content,$start)
{
return substr($content,strpos($content,$start)+strlen($start));
}

?>

26
Dec/09
0

Where v.2

Updated http://where.isrobin.com with new code, same design. Implemented two string functions I created.

<?php
/************************************************
Programmer: Robin Chang
Date:       12/26/09
Description:
A program that uses a TWITTER account
and the format “w:*” where * is a place
************************************************/

include “../lib/stringR.php”;

// change this information
$site = “http://twitter.com/rchang4/”;
$keyword = ‘W:’;
$current = “ROBIN IS”;
// stop editing

$read = file_get_contents($site);                               // reads from the website
$read = stristr($read,$keyword);                                // searches for W:
$time = cut($read,’<span data=”‘,’</span>’);
$time = substrR($time,’”>’);
$location = cut($read,’W:’,'</span>’);

echo “<div id=’message’>$current</div>”;
echo “<div id=’where’>$location</div>”;
echo “<div id=’when’>$time</div>”;
?>

26
Dec/09
0

Go Biker Go

http://www.liveleak.com/view?i=ff2_1261805235

Filed under: Journalish
25
Dec/09
0

Your Childhood was a LIE

Well, I just have to say, Disney found a perfect recipe for good animated movies at least.

http://www.youtube.com/watch?v=e4ia5TBmY78

Filed under: Journalish
25
Dec/09
0

Free Fresco Taco

http://static.tacobell.com/drivethrudiet/chttp://static.tacobell.com/drivethrudiet/coupon.htmloupon.html

get it because you can o:

Filed under: Journalish
25
Dec/09
0

Where is Robin?

You can find WHERE I AM (as long as I have updated my last location via twitter)

http://where.isrobin.com

code to grab where and when from twitter…

<?php
/************************************************
Programmer: Robin Chang
Date:       12/25/09
Description:
A program that uses a TWITTER account
and the format “w:*” where * is a place
************************************************/

// change this information
$site = “http://twitter.com/rchang4/”;
$current = “ROBIN IS”;
// stop editing

$read = file_get_contents($site);                               // reads from the website
$location = stristr($read,’W:’);                                    // searches for W:
$time = substr($location,0,strpos($location,”</a>”));           // grabs the time
$time = substr($time,strpos($time,’<span data=”‘));
$time = substr($time,strpos($time,’”>’));
$time = substr($time,2);
$time = substr($time,0,strpos($time,”</span>”));
$location = substr($location,0,strpos($location,”</span>”));    // gets rid of the rest of the info after the first <span> containing the location
$location = substr($location,2);                                // gets rid of the W:

echo “<div id=’message’>$current</div>”;
echo “<div id=’where’>$location</div>”;
echo “<div id=’when’>$time</div>”;
?>

Also did vertical alignment stuff, NOTE TO SELF…

<style type=’text/css’>#floater { float:left; height:30%; margin-bottom:-50px; }</style>

<div id=”floater”></div>

is magical. Can do center with changing height:50%! Very neat-o.

25
Dec/09
0

basic include + require files

totally forgot about SQL injection but ya, here’s a quick fix
also has stuff for mysql database connect + disconnect

required.php

<?php
/************************************************
Programmer: Robin Chang
Date:       12/24/09
Description:
Required for several things
** Filters form input
** (Dis)Connects to MySQL DB
** Grabs SESSION information
************************************************/

// connects to the database
// returns the link
function ConnectDatabase($server,$user,$pass)
{
$link = mysql_connect($server, $user, $pass);
if (!$link) {
die(’Could not connect: ‘ . mysql_error());
}
return $link;
}

// closes a connection to the MySQL DB
// VOID
function CloseConnect($link)
{
mysql_close($link);
}

// stores into global the session variables
// VOID
function GrabSession()
{
global $playerID = $_SESSION['playerID'];
global $playerName = $_SESSION['playerName'];
global $playerPass = $_SESSION['password'];
}

// VOID
// returns 0 if failed
function CheckLogin()
{
if (!$playerID || !$playerName || !$playerPass) return 0;
$result = mysql_query(”SELECT password FROM Players WHERE userID=$playerID”);
$result = mysql_fetch_row($result);
if ($result[0]!=$playerPass) return 0;
return 1;
}

// where $input is a string
// returns a string with escape characters, ‘ = \’, ” = \”, \=\\, etc.
function FilterInput($input)
{
return preg_quote($input);
}

?>

include.php

<?php
/************************************************
Programmer: Robin Chang
Date:       12/24/09
Description:
Required for startup
** MySQL Databasee Connect
** Session info
************************************************/

include “required.php”;

session_start();
GrabSession();
ConnectDatabase($server,$user,$pass);
if (CheckLogin()==0) die(”Error”);

?>

And that’s it so far. Continuing on sometime soon.

Filed under: Projects
24
Dec/09
0

Bored

Went to a clan website. didn’t like it. Made a slightly better looking one. Emphasis on slightly.

I think it’s a good start for 10 minutes of work. If I had photoshop I would create a navigation background image and a background image for the whole thing. But oh well.

http://www.isrobin.com/2010/ewv/

Filed under: Design
23
Dec/09
0

working on a turn-based game generator in PHP

objects.php

<?php
/************************************************
Programmer: Robin Chang
Date:       12/23/09
Description:
Allows for objects to
be created and edited
************************************************/

function CreateObject($name,$value)
{
mysql_query(”INSERT INTO Objects(Name) VALUES (’$name’)”);
mysql_query(”ALTER TABLE Players ADD COLUMN $name VARCHAR(128)”);
mysql_query(”UPDATE players SET $name=$value”);
}

function AddRequirement($id,$required_id,$value,$consume)
{
mysql_query(”UPDATE Objects SET requirements=’$required_id:$value:$consume;’ WHERE id=$id”);
}

?>

buy.php

<?php
/************************************************
Programmer: Robin Chang
Date:       12/23/09
Description:
Allows for objects to
be bought
**REQUIRES**
global $playerID for current player
************************************************/

// requires object ID that is being bought
// returns 0 if requirements have been met, otherwise the ID that is needed
function Buy($id)
{
$result = CheckRequirements($id);
if (!is_array($result)) return $result;
ConsumeRequirements($result);
AddObject($id)
return 0;
}

// requires object ID
// returns list of requirements
function CheckRequirements($id) {
$result = mysql_query(SELECT requirements FROM Objects WHERE id=$id);
$result = mysql_fetch_row($result);
$result = $result[0];
$result = explode(’;',$result);
for ($i=0;$i<count($result);$i++)
{
$requirementInfo = explode(’:',$result[$i]);
for ($j=0;$j<count($requirementInfo);$j++)
{
$result2 = mysql_query(”SELECT $requirementInfo[0] FROM Players WHERE playerID=$playerID”);
$result2 = mysql_fetch_row($result2);
if ($result2[0] < $requirementInfo[1])
return $requirementInfo[1];
}
}
return $result;
}

// requires list of requirements
// VOID
function ConsumeRequirements($result)
{
for ($i=0;$i<count($result);$i++)
{
$requirementInfo = explode(’:',$result[$i]);
for ($j=0;$j<count($requirementInfo);$j++)
{
$result2 = mysql_query(”SELECT $requirementInfo[0] FROM Players WHERE playerID=$playerID”);
$result2 = mysql_fetch_row($result2);
$newValue = $result2 – $requirementInfo[2];
mysql_query(”UPDATE Players SET $requirementInfo[0]=$newValue WHERE playerID=$playerID”);
}
}
}

// requires object ID, player ID
// VOID
function AddObject($id,$playerID)
{
$result = mysql_query(”SELECT $id FROM Players WHERE playerID=$playerID”);
$result = mysql_fetch_row($result);
$newValue = $result[0] + 1;
mysql_query(”UPDATE Players SET $id=$newValue WHERE playerID=$playerID”);
}

?>

Filed under: Projects