Skip to content

Instantly share code, notes, and snippets.

@jehoshua02
jehoshua02 / SQL
Created September 25, 2011 02:09
Building the mba Search Query
/* 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
@jehoshua02
jehoshua02 / python
Created September 27, 2011 22:49
StupidGame
prompt = "> "
class StupidGame:
"""Stupid Game"""
def __init__(self):
self.run()
def run(self):
self.player = self.Player()
@jehoshua02
jehoshua02 / PYTHON
Created October 4, 2011 09:11
mutagen: mp3 tags in not showing in windows explorer
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
@jehoshua02
jehoshua02 / PYTHON
Created October 5, 2011 04:15
assert_raises
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'))
@jehoshua02
jehoshua02 / python
Created October 5, 2011 04:33
assert_raises nosetest output
js@JS-LAPTOP /d/vbox/shared/projects/lotus/lpthw/ex49 (master)
$ nosetests
...............
----------------------------------------------------------------------
Ran 15 tests in 0.030s
OK
@jehoshua02
jehoshua02 / Workflow FTP no VCS
Created October 15, 2011 22:52
Workflow for working with a team that doesn't use version control when only FTP access is available.
# 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!)
@jehoshua02
jehoshua02 / BrowserInformation
Created October 16, 2011 05:18
Rework of BrowserInformation class using class variables correctly
class BrowserInformation
{
private $agent;
private $browser;
public function __construct($agent = NULL)
{
if (empty($agent))
{
$agent = $_SERVER['HTTP_USER_AGENT'];
@jehoshua02
jehoshua02 / return a reference
Created October 16, 2011 05:59
What happens when I return a variable reference, then try to modify it?
<?php
// what happens when I return a reference to a variable, then try to modify it?
class ReferenceOrValue
{
private $variable;
public function __construct($value)
{
@jehoshua02
jehoshua02 / realpath()
Created October 16, 2011 10:13
Restricting file access using realpath
<?php
$file = pathinfo($_GET['form']);
$file = realpath($file['dirname']) . DIRECTORY_SEPARATOR . $file['basename'];
if (empty($file))
{
die("No file requested.");
}
@jehoshua02
jehoshua02 / order_to_warehouse.php
Created October 17, 2011 23:12
I don't think unlink() and ftp_put() are playing nice...
<?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!";