ignace
Moderators-
Posts
6,457 -
Joined
-
Last visited
-
Days Won
26
Everything posted by ignace
-
You might wanna pass your API key to your function, since it accesses it but it is not defined in the function scope. header('Content-type: application/json'); $token = "[myapitoken]";//my api token function get_data($url, $token, $timeout = 5) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPGET, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_USERPWD, $token.':api_token'); $data = curl_exec($ch); curl_close($ch); return $data; } $returned_content = get_data("https://toggl.com/reports/api/v2/weekly?&workspace_id=282507&since=2013-05-19&until=2013-08-20&user_agent=[user agent]", $token);//user agent here var_dump($returned_content);
-
Need help understanding how strategy patterns work
ignace replied to eldan88's topic in Application Design
By interchangeable they mean you can swap one for the other, as in setStrategy($strategy), now the object who has that method has his strategy changed, for example if you have a class that displays the filesystem in an hierarchy, a strategy could be to sort it by name (class SortByNameStrategy) or sorted by folders-first (class SortByFolderFirstStrategy). You can change the display by changing the strategy on the filesystem object. Adapter and Strategy are quite alike from a design POV where one is about making one thing work with another, the other is about selecting the proper algorithm/behaviour. -
Poor OOP practices that programmers should avoid
ignace replied to Hall of Famer's topic in Miscellaneous
Replacement for If/Switch: http://sourcemaking.com/refactoring/replace-conditional-with-polymorphism Although I mostly agree with HoF in terms of OOP practices and principles. He's wrong about pretty much everything else. Like his view about procedural programming. I don't like hard-liners. -
Remove all link stylesheets from document (Regex or DOM)
ignace replied to kikookik's topic in PHP Coding Help
This snippet should remove any and all <link/> tags. echo preg_replace('!<link([^>]+)/?>!', '', file_get_contents('http://domain.top/file.ext')); -
Duplicate: http://forums.phpfreaks.com/topic/282282-add-edit-delete-script-problems/?do=findComment&comment=1450234
-
Do a "forgot password" or contact your hosting company to get your credentials. If you are paying for the hosting this should be no problem.
-
From their website: LOL $lastClaim = strtotime($lastClaimQ->fetch_assoc());Is wrong what else is in the dispenses table? Also knowing this has been hacked together, not properly tested, you sure you wanna run this on your server?
-
Help me with cross-domain ajax request (or JSONP)
ignace replied to mostafatalebi's topic in Javascript Help
The url has to be: http://url.com/file_to_process.php -
eduTrac: An Open Source Student Information System
ignace replied to NomadicJosh's topic in Beta Test Your Stuff!
Looks really good. -
What to do when your code gets messy and confusing?
ignace replied to FrogWarrior's topic in Application Design
It's a problem many programmers face and this is due to the fact that you don't put any thought into your application before starting to program. To get better at this you need to break your application down into parts you know how to do and parts you don't know how to do. Start with the parts you know how to do, think of how you will achieve them. Then take the one of the parts you don't know how to do and research it, until you have a better understanding of it, and see if you can break it down further again in a part you know how to do and the part you don't know how to do. To take your example: "GETS A LIST OF PDF FILES IN A DIRECTORY AND LOADS THE FILENAMES INTO AN XML DOCUMENT" "CHECKS THE URL VARIABLES, AND DECIDES WHETHER TO RUN THE SPIDER, OR DISPLAY THE XML FILE" "THE OPTIONS LIST WHERE THE USER CAN CHANGE THE WAY THE APPLICATION RUNS" These are just comments in your script, but added together they don't make much sense. Because you just started to hack away and none of the classes in your script have a real goal. From what I deduced from your code I gather that you want a script that checks an url variable then scrapes or displays an xml. When you say it like that it sounds so simple, right? So, thus summarize for yourself what you want to achieve. /** * Crawls an URL endpoint and returns a list of PDF files. * When $crawl_next_pages is true will crawl paginated content. */ function spider_crawl($url, $crawl_next_pages = false) { .. } /** * Given a list of PDF files generates a standard XML file. */ function xml_generate($files, $filename = null) { .. } if ($_GET['action'] == 'scape') { $pdf_files = spider_crawl($_GET['url']); $xml_path = xml_generate($pdf_files); echo 'XML generated.'; } else { readfile($_GET['xml_path']); }When you have all pieces of the puzzle, you may want to consider what your best plan of attack is, like what functions/classes will you have, what will their responsibilities be. Where do you need/want flexibility. -
Remember that when cloning an object the object references it holds are left untouched. class Woll { private $thickness; .. } class Sheep { private $woll; public function __construct() { $this->woll = new Woll(3); } public function setWollThickness($thickness) { .. } } $sheep = new Sheep; $dolly = clone $sheep; $dolly->setWollThickness(6); echo $sheep->getWollThickness(); // 6 echo $dolly->getWollThickness(); // 6To avoid this you need to clone the object references inside your object aswell: public function __clone() { $this->woll = clone $this->woll; }Whom in turn would have to do the same thing etc..
-
No question. No topic.
-
Doing Quick Saves Via PHP/Client Side for Turned Based Game?
ignace replied to Monkuar's topic in Application Design
Just store it in your database. You can still optimize later. -
@Monkuar it IS your computer, you have anti-aliasing disabled. Not all fonts require anti-aliasing, but clearly this one does.
-
Talking about missing the point of discussion, I think the OP wants an answer to his question.
-
Great! Now you can learn it.
-
@Hall of Famer: You are constantly advocating good OO design, yet here you tie your application layer to your model.. A user should not be concerned about how an application handles login or about where a user should go after login.
-
if ($user['position'] == 'admin') { header('Location: admin.php'); exit; } elseif ($user['position'] == 'student') { header('Location: student.php'); exit; } ..
-
define('USER_LEVEL_TEACHER', 1); define('USER_LEVEL_STUDENT', 2); define('USER_LEVEL_CASHIER', 4); define('USER_LEVEL_ADMIN', ; if ($userLevel & USER_LEVEL_ADMIN) { // admin }
-
You are gonna be more specific. I have no idea what you are talking about.
-
Writer's block. He'll get over it!
-
No hotdogs for you, mister!
-
how to re-size temporary image file and upload to mysql blob
ignace replied to merck_delmoro's topic in PHP Coding Help
1. Download composer.phar from http://getcomposer.org and drop it inside your project directory 2. Create a composer.json file: { "require": { "imagine/imagine": "0.6.*@dev" } }3. Run $ /path/to/php composer.phar install in the terminal4. Use the imagine library: <?php require_once 'vendor/autoload.php' $imagine = new Imagine\Gd\Imagine(); $image = $imagine->open('/path/to/image'); $image // scale image to 50% ->thumbnail($image->getSize()->scale(0.5)) // display as jpeg at 75% ->show('jpeg', array('quality' => 75));Documentation can be found at http://imagine.readthedocs.org/en/latest/index.htmlAPI is available at http://imagine.readthedocs.org/en/latest/_static/API/ -
Yes. Simply state your new topic title here, I'll change it for you.