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 a function can return a function, then a function can also take a function | |
# as an argument | |
# Defining a function which we will pass as an argument to another function | |
def scream(word = 'yes'): | |
return '%s!' %(word.upper()) | |
# Function taking a function as argument | |
def do_something_before(func): | |
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
# Script to show how functions can return functions | |
def get_talk(type = 'shout'): | |
# We define some functions here on the fly. | |
def shout(word = 'yes'): | |
return '%s!' %(word.capitalize()) | |
def whisper(word = 'yes'): | |
return '%s...' %(word.lower()) |
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
# Script to show how to define functions inside functions and its scope | |
def talk(): | |
# We can define a function inside a function like this. In this case we define a | |
# function whisper() inside the funtion talk() | |
def whisper(word = 'yes'): | |
return '%s...' %(word) | |
# And we can use the function whisper right away inside the wrapping function |
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
# Script to show how functions are just objects | |
def shout(word = 'yes'): | |
return '%s!' %(word.capitalize()) | |
print shout() # Outputs: Yes! | |
scream = shout | |
# As functions are just objects, we can assign them just like a variable assignment |
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 | |
$file_path = '/home/siddharthsaha/Desktop/production.html'; | |
$data = array( | |
'owner' => 'siddharth saha' | |
); | |
$request = new HttpRequest($url, HttpRequest::METH_POST); | |
$request->addPostFields($data); # Adding the data with the POST method | |
$request->addPostFile('test_file', $file_path); # The file has to be posted with a separate method. | |
$request->send(); |
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 | |
$url = 'http://localhost/tests/upload_file'; #URL for the service | |
$file_path = '/home/siddharthsaha/Desktop/production.html'; # File to be uploaded | |
$data = array( | |
'owner' => 'siddharth saha', | |
'test_file' => '@' . $file_path # For files, you have to append a @ before the filepath. | |
); | |
# Make the curl request exactly as in the POST example above. |
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 | |
$url = 'http://localhost/tests/upload_file'; #URL for the service | |
$file_path = '/home/siddharthsaha/Desktop/production.html'; # File to be uploaded | |
$data = array( | |
'owner' => 'siddharth saha', | |
'test_file' => '@' . $file_path # For files, you have to append a @ before the filepath. | |
); | |
# Make the curl request exactly as in the POST example above. |
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 Requests.php and autoload the internal classes | |
$data = array( | |
'owner' => 'siddharth saha', | |
'test_file' => '@' . $file_path # File name to be pre-pended with @ | |
); | |
$response = Requests::request($url, array(), $data, Requests::POST); | |
if ($response->success) { | |
$response = json_decode($response->body); | |
} |
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 Requests.php and autoloader | |
$response = Requests::request($url, array(), $data, Requests::POST); # empty array for headers if you want to send any | |
if ($response->success) { | |
$response = json_decode($response->body); | |
} | |
?> |
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 | |
require_once('./requests/library/Requests.php'); # have to require this single file | |
Requests::register_autoloader(); # needed by Requests class to autoload internal classes | |
$response = Requests::request($url, array(), $data); # The empty array is for headers if you want to send any | |
if ($response->success) { | |
$response = json_decode($response->body); | |
} | |
?> |