This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def get_choices(): | |
'''Generates a list of size 3 that represents the doors. 0 is a loss (goat) | |
while 1 is a win (car). 1 door will have a 1 in it, the other two will have | |
0s.''' | |
choices = [0, 0, 0] | |
choices[random.randint(0, 2)] = 1 | |
return choices | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print "Hello, world!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 + 2 # addition, returns 4 | |
4 - 1 # subtraction, returns 3 | |
5 * 5 # multiplication, returns 25 | |
2 ** 3 # 2 to the power of 3, returns 8 | |
10 / 2 # division, returns 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"id":"544780370","name":"Sam Rose","first_name":"Sam","last_name":"Rose","username":"samwho","gender":"male","locale":"en_GB"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id":15437714861, | |
"source":"twitter", | |
"location":"", | |
"place":null, | |
"geo":null, | |
"in_reply_to_user_id":null, | |
"is_reply_by_friend":false, | |
"in_reply_to_post_id":null, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (isset($post->user->other->avg_tweets_per_day)) { | |
$post->user->avg_tweets_per_day = $post->user->other->avg_tweets_per_day; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Okay, I've made significant progress on understanding the nature of this error. | |
It's, at its heart, very simple. $post->user->other is an array, not an object. Accessing it like an object was a very costly oversight on my part. It isn't tested for, either, because it was never a problem on my server and I'll explain why: | |
Take this script: | |
<?php | |
ini_set('display_errors', '1'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!isset($argv[1])) { | |
echo "You must specify an SQL query as the first parameter.\n"; | |
exit; | |
} else { | |
if (strpos($argv[1], 'SELECT') !== 0) { | |
echo "Parameter must be a SELECT query. Please try again.\n"; | |
exit; | |
} | |
$query = strval($argv[1]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Original puzzle: A secretary receives 10 letters along with 10 addressed | |
# envelopes to be sent out. She accidentally drops the all the letters and | |
# envelopes and mixes them all up. So, she decides to put each of the 10 | |
# letters randomly into one of the 10 addressed envelopes and mail them out. | |
# What is the probability that at least one letter arrives at the correct | |
# destination? | |
# Gets a hash that represents the envelopes containing their randomly placed | |
# letter. Both envelope and letter are represented by a number. If the key and | |
# the value of each item in the hash are the same, that is a correct |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Include the Router class and a sample Controller to use. | |
require_once dirname(__FILE__) . '/lib/models/class.Router.php'; | |
require_once dirname(__FILE__) . '/lib/controllers/class.FooController.php'; | |
require_once dirname(__FILE__) . '/lib/controllers/class.NotFoundController.php'; | |
// Get the singleton instance of the Router class. | |
$router = Router::getInstance(); | |
/* |
OlderNewer