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
numbers = range(1, 999 + 1) | |
result = 0 | |
for that in numbers: | |
if that % 3 == 0 or that % 5 ==0: | |
result += that | |
print result # Prints '233168'. |
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
/^\S+$/ |
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
full_name = raw_input('What\'s your full name? ') | |
parts_of_name = full_name.split() | |
first_name = parts_of_name[0] | |
last_name = parts_of_name[1] | |
initial_letter_of_last_name = last_name[0] | |
print '{0} {1}.'.format(first_name, initial_letter_of_last_name) |
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 sys, os | |
try: | |
root = sys.argv[1]; | |
except IndexError: | |
root = '.' | |
for dirname, dirnames, filenames in os.walk(root): | |
for subdirname in dirnames: | |
print os.path.join(dirname, subdirname) |
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
Y-m-d H:i:s |
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 | |
/** | |
* Makes SQL compatible WHERE statement from assoc array where array's keys are table's columns, but values - rows. | |
* | |
* @param array `array('a' => 'foo', 'b' => 123, 'c' => 'bar',)` | |
* @return string `WHERE `a` = 'foo' AND `b` = 123 AND `c` = 'bar'` | |
* | |
* @author daGrevis | |
*/ |
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 | |
class Request extends Kohana_Request { | |
/** | |
* Helper to reduce LOCs. | |
* | |
* @param string Key of the value | |
* @return boolean | |
* |
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
# A. donuts | |
# Given an int count of a number of donuts, return a string | |
# of the form 'Number of donuts: <count>', where <count> is the number | |
# passed in. However, if the count is 10 or more, then use the word 'many' | |
# instead of the actual count. | |
# So donuts(5) returns 'Number of donuts: 5' | |
# and donuts(23) returns 'Number of donuts: many' | |
def donuts(count): | |
if count < 10: | |
return 'Number of donuts: ' + str(count) |
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
# D. verbing | |
# Given a string, if its length is at least 3, | |
# add 'ing' to its end. | |
# Unless it already ends in 'ing', in which case | |
# add 'ly' instead. | |
# If the string length is less than 3, leave it unchanged. | |
# Return the resulting string. | |
def verbing(s): | |
if len(s) < 3: | |
return s |
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 | |
echo '<div style="display: none;">'; | |
$s1 = microtime(true); | |
for ($i = 0; $i < 1000000; ++$i) { | |
echo 'a'.'b'; |