This file contains hidden or 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
/* Requirements: | |
I'm writing an SQL query for a search feature on a website in a PHP/MySQL application. | |
I have customer and ad tables. Customer may have many ads. | |
The user enters a keyword and sees the results in a web page. Here's the rules for the search results: | |
each item in the search result contains customer info and one ad for that customer | |
the customer, or the customer's ad must match the keyword |
This file contains hidden or 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
prompt = "> " | |
class StupidGame: | |
"""Stupid Game""" | |
def __init__(self): | |
self.run() | |
def run(self): | |
self.player = self.Player() |
This file contains hidden or 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
from shutil import copyfile | |
from mutagen.mp3 import MP3 | |
from mutagen.id3 import ID3, TIT2, TCON, TALB | |
def resetFile(): | |
"""Copies original.mp3 to somefile.mp3 and returns an mutagen MP3 file handle""" | |
filename = 'somefile.mp3' | |
copyfile('original.mp3', filename) | |
file = MP3(filename) | |
return file |
This file contains hidden or 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
from nose.tools import * | |
from simplegame import lexicon | |
def test_parse_verb(): | |
word_list = lexicon.scan('the bear eat') | |
assert_raises(lexicon.ParseError, lexicon.parse_verb, *[word_list]) | |
assert_equal(lexicon.parse_verb('eat the bear'), ('verb', 'eat')) |
This file contains hidden or 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
js@JS-LAPTOP /d/vbox/shared/projects/lotus/lpthw/ex49 (master) | |
$ nosetests | |
............... | |
---------------------------------------------------------------------- | |
Ran 15 tests in 0.030s | |
OK |
This file contains hidden or 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
# 1) merge changes from live server | |
# create new branch for downloading live changes into | |
git branch live | |
git checkout live | |
# in working directory: | |
# delete old files | |
# download new/modified files | |
# (need magic here!) |
This file contains hidden or 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
class BrowserInformation | |
{ | |
private $agent; | |
private $browser; | |
public function __construct($agent = NULL) | |
{ | |
if (empty($agent)) | |
{ | |
$agent = $_SERVER['HTTP_USER_AGENT']; |
This file contains hidden or 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 | |
// what happens when I return a reference to a variable, then try to modify it? | |
class ReferenceOrValue | |
{ | |
private $variable; | |
public function __construct($value) | |
{ |
This file contains hidden or 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 | |
$file = pathinfo($_GET['form']); | |
$file = realpath($file['dirname']) . DIRECTORY_SEPARATOR . $file['basename']; | |
if (empty($file)) | |
{ | |
die("No file requested."); | |
} |
This file contains hidden or 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 | |
// ... | |
// send file to warehouse | |
$conn_id = ftp_connect($ftp_server); | |
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); | |
if ((!$conn_id) || (!$login_result)) { | |
// echo "FTP connection has failed!"; |
OlderNewer