Jump to content

jbwebdesign

Member
  • Posts

    167
  • Joined

  • Last visited

About jbwebdesign

  • Birthday 07/25/1989

Profile Information

  • Gender
    Male
  • Location
    New York
  • Interests
    Web Development

Contact Methods

  • Website
    http://www.affordablewebdev.com

jbwebdesign's Achievements

Newbie

Newbie (1/14)

-1

Reputation

  1. Hello, I am working on creating an angular js directive for using HTML5 Canvas My goal is to output a canvas and use Font Awesome icons for writing inside of the canvas. My code is the following, however the problem i have is that the font awesome icons don't seem to render: angular.module('myApp') .directive('customButtonCanvas', ['$document', function($document) { return { restrict: 'A', scope: { width : '=', height : '=', options : '=' }, link: function(scope, element){ console.log(scope); console.log(element); //first lets get the canvas element from our template.... var ctx = element[0].getContext('2d'); ctx.font = "40px FontAwesome"; ctx.fillText("\uf000", 120, 120); console.log(ctx); } }; }]); any help with this will be greatly appreciated. thanks!
  2. Hello guys, i am trying to create an api request but the problem i have is that the code is not written in PHP. they only have Ruby and Python samples. can someone please help me so that i can create a request to the api with PHP. import hashlib import hmac import urllib2 import time API_KEY = 'YOUR-API-KEY' API_SECRET = 'YOUR-API-SECRET' def get_http(url, body=None): opener = urllib2.build_opener() nonce = int(time.time() * 1e6) message = str(nonce) + url + ('' if body is None else body) signature = hmac.new(API_SECRET, message, hashlib.sha256).hexdigest() opener.addheaders = [('ACCESS_KEY', API_KEY), ('ACCESS_SIGNATURE', signature), ('ACCESS_NONCE', nonce)] try: return opener.open(urllib2.Request(url, body)) except urllib2.HTTPError as e: print e return e print get_http('https://thewebsite.com/api/v1/account/').read()
  3. Hello, i have been researching some real time functionality and i would like to create a realtime website. something that can function similar to an auction. for this, i would like to use web sockets but i can't figure out how to use web sockets with php. can anyone help me? i have some code below..... server.php #!/php -q <?php /* >php -q server.php */ error_reporting(E_ALL); set_time_limit(0); ob_implicit_flush(); $master = WebSocket("localhost", 8752); $sockets = array($master); $users = array(); $debug = false; while(true){ $changed = $sockets; socket_select($changed,$write=NULL,$except=NULL,NULL); foreach($changed as $socket){ if($socket==$master){ $client=socket_accept($master); if($client<0){ console("socket_accept() failed"); continue; } else{ connect($client); } } else{ $bytes = @socket_recv($socket,$buffer,2048,0); if($bytes==0){ disconnect($socket); } else{ $user = getuserbysocket($socket); if(!$user->handshake){ dohandshake($user,$buffer); } else{ process($user,$buffer); } } } } } //--------------------------------------------------------------- function process($user,$msg){ $action = unwrap($msg); say("< ".$action); switch($action){ case "hello" : send($user->socket,"hello human"); break; case "hi" : send($user->socket,"zup human"); break; case "name" : send($user->socket,"my name is Multivac, silly I know"); break; case "age" : send($user->socket,"I am older than time itself"); break; case "date" : send($user->socket,"today is ".date("Y.m.d")); break; case "time" : send($user->socket,"server time is ".date("H:i:s")); break; case "thanks": send($user->socket,"you're welcome"); break; case "bye" : send($user->socket,"bye"); break; default : send($user->socket,$action." not understood"); break; } } function send($client,$msg){ say("> ".$msg); $msg = wrap($msg); socket_write($client,$msg,strlen($msg)); } function WebSocket($address,$port){ $master=socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("socket_create() failed"); socket_set_option($master, SOL_SOCKET, SO_REUSEADDR, 1) or die("socket_option() failed"); socket_bind($master, $address, $port) or die("socket_bind() failed"); socket_listen($master,20) or die("socket_listen() failed"); echo "Server Started : ".date('Y-m-d H:i:s')."\n"; echo "Master socket : ".$master."\n"; echo "Listening on : ".$address." port ".$port."\n\n"; return $master; } function connect($socket){ global $sockets,$users; $user = new User(); $user->id = uniqid(); $user->socket = $socket; array_push($users,$user); array_push($sockets,$socket); console($socket." CONNECTED!"); } function disconnect($socket){ global $sockets,$users; $found=null; $n=count($users); for($i=0;$i<$n;$i++){ if($users[$i]->socket==$socket){ $found=$i; break; } } if(!is_null($found)){ array_splice($users,$found,1); } $index = array_search($socket,$sockets); socket_close($socket); console($socket." DISCONNECTED!"); if($index>=0){ array_splice($sockets,$index,1); } } function dohandshake($user,$buffer){ console("\nRequesting handshake..."); console($buffer); list($resource,$host,$origin,$strkey1,$strkey2,$data) = getheaders($buffer); console("Handshaking..."); $pattern = '/[^\d]*/'; $replacement = ''; $numkey1 = preg_replace($pattern, $replacement, $strkey1); $numkey2 = preg_replace($pattern, $replacement, $strkey2); $pattern = '/[^ ]*/'; $replacement = ''; $spaces1 = strlen(preg_replace($pattern, $replacement, $strkey1)); $spaces2 = strlen(preg_replace($pattern, $replacement, $strkey2)); if ($spaces1 == 0 || $spaces2 == 0 || $numkey1 % $spaces1 != 0 || $numkey2 % $spaces2 != 0) { socket_close($user->socket); console('failed'); return false; } $ctx = hash_init('md5'); hash_update($ctx, pack("N", $numkey1/$spaces1)); hash_update($ctx, pack("N", $numkey2/$spaces2)); hash_update($ctx, $data); $hash_data = hash_final($ctx,true); $upgrade = "HTTP/1.1 101 WebSocket Protocol Handshake\r\n" . "Upgrade: WebSocket\r\n" . "Connection: Upgrade\r\n" . "Sec-WebSocket-Origin: " . $origin . "\r\n" . "Sec-WebSocket-Location: ws://" . $host . $resource . "\r\n" . "\r\n" . $hash_data; socket_write($user->socket,$upgrade.chr(0),strlen($upgrade.chr(0))); $user->handshake=true; console($upgrade); console("Done handshaking..."); return true; } function getheaders($req){ $r=$h=$o=null; if(preg_match("/GET (.*) HTTP/" ,$req,$match)){ $r=$match[1]; } if(preg_match("/Host: (.*)\r\n/" ,$req,$match)){ $h=$match[1]; } if(preg_match("/Origin: (.*)\r\n/",$req,$match)){ $o=$match[1]; } if(preg_match("/Sec-WebSocket-Key2: (.*)\r\n/",$req,$match)){ $key2=$match[1]; } if(preg_match("/Sec-WebSocket-Key1: (.*)\r\n/",$req,$match)){ $key1=$match[1]; } if(preg_match("/\r\n(.*?)\$/",$req,$match)){ $data=$match[1]; } return array($r,$h,$o,$key1,$key2,$data); } function getuserbysocket($socket){ global $users; $found=null; foreach($users as $user){ if($user->socket==$socket){ $found=$user; break; } } return $found; } function say($msg=""){ echo $msg."\n"; } function wrap($msg=""){ return chr(0).$msg.chr(255); } function unwrap($msg=""){ return substr($msg,1,strlen($msg)-2); } function console($msg=""){ global $debug; if($debug){ echo $msg."\n"; } } class User{ var $id; var $socket; var $handshake; } ?> and client.php <html> <head> <title>WebSocket</title> <style> html,body{font:normal 0.9em arial,helvetica;} #log {width:440px; height:200px; border:1px solid #7F9DB9; overflow:auto;} #msg {width:330px;} </style> <script> var socket; function init(){ var host = "ws://localhost:8752/websocket/server.php"; try{ socket = new WebSocket(host); log('WebSocket - status '+socket.readyState); socket.onopen = function(msg){ log("Welcome - status "+this.readyState); }; socket.onmessage = function(msg){ log("Received: "+msg.data); }; socket.onclose = function(msg){ log("Disconnected - status "+this.readyState); }; } catch(ex){ log(ex); } $("msg").focus(); } function send(){ var txt,msg; txt = $("msg"); msg = txt.value; if(!msg){ alert("Message can not be empty"); return; } txt.value=""; txt.focus(); try{ socket.send(msg); log('Sent: '+msg); } catch(ex){ log(ex); } } function quit(){ log("Goodbye!"); socket.close(); socket=null; } // Utilities function $(id){ return document.getElementById(id); } function log(msg){ $("log").innerHTML+="<br>"+msg; } function onkey(event){ if(event.keyCode==13){ send(); } } </script> </head> <body onload="init()"> <h3>WebSocket v2.00</h3> <div id="log"></div> <input id="msg" type="textbox" onkeypress="onkey(event)"/> <button onclick="send()">Send</button> <button onclick="quit()">Quit</button> <div>Commands: hello, hi, name, age, date, time, thanks, bye</div> </body> </html> the problem i have is..... when i use server.php from shell, it seems to return the following: Server Started : 2013-07-08 09:58:50 Master socket : Resource id #4 Listening on : localhost port 8752 However, when i try to use it on the Client side, it doesn't connect at all. can someone please help me to figure out what i am doing wrong? any suggestion will be appreciated.
  4. I've just looked into some realtime stuff and it looks like Websockets can be good for what i am looking to do. does anyone know weather websockets is the best way for me to go?
  5. Try to use the foreach loop for the entire table....for example: <?php foreach($rotadetails as $rotadetail): ?> <table align="center" border=0 cellspacing=0 cellpadding=0 width=633> <tr> <td colspan=7 valign=top style="height:4px; "></td> </tr> <tr align="center"> <td width="70" rowspan="2">Week <?php echo $i; ?></td> <td width="80" colspan=1 bgcolor="#DBE5F1">Breakfast</td> <td width="80" colspan=1 bgcolor="#DBE5F1">Lunch</td> <td width="80" colspan=1 bgcolor="#DBE5F1">Dinner</td> <td width="80" colspan=1 bgcolor="#DBE5F1">Bed</td> <td width="120" colspan=2 bgcolor="#DBE5F1">Extra Time</td> </tr> <tr align="center" bgcolor="#DBE5F1"> <td width="80" colspan=1>08:00-09:00</td> <td width="80" colspan=1>13:30-14:30</td> <td width="80" colspan=1>17:00-18:00</td> <td width="80" colspan=1>22:00-23:00</td> <td width="120" colspan=1>Start</td> <td width="60">Duration</td> </tr> <tr> <td colspan=1><?php echo date("l",$rotadetail['pa_rotaDate']); ?></td> <td colspan=1><?php echo $rotadetail['pa_hrs0800']; ?></td> <td colspan=1><?php echo $rotadetail['pa_hrs1300']; ?></td> <td colspan=1><?php echo $rotadetail['pa_hrs1700']; ?></td> <td colspan=1 bgcolor="#DBE5F1"><?php echo $rotadetail['pa_hrs2200']; ?></td> <td ><?php echo $rotadetail['pa_rotaETime']; ?></td> <td><?php echo $rotadetail['pa_rotaETimeDur']; ?></td> </tr> <tr> <td colspan=7 valign=top style="height:4px; "></td> </tr> <tr> <td colspan=1 align="right" valign=top>TOTAL </td> <td colspan=1><?php echo $bttot1; ?></td> <td colspan=1><?php echo $lttot1; ?></td> <td colspan=1><?php echo $tttot1; ?></td> <td colspan=1 bgcolor="#DBE5F1"><?php echo $nttot1; ?></td> <td colspan=2><?php echo $ettot1; ?></td> </tr> </table> <?php endforeach; ?>
  6. well what i am trying to do is take the TABLE and convert it into a php array so that i can insert it into a MySQL database.
  7. hello everyone, i am working on a script and i want to do the following i have a table that looks like this... <table> <tr> <td>Tuesday</td> <td>12/31</td> <td>New Years Eve</td> <td>Test</td> <td>Apples</td> <td>Oranges</td> <td>Bananas</td> </tr> <tr> <td>Monday</td> <td>12/30</td> <td>New Years Eve EVE</td> <td>Test</td> <td>Apples</td> <td>Oranges</td> <td>Bananas</td> </tr> <tr> <td>Sunday</td> <td>12/29</td> <td>New Years Eve Eve EVE</td> <td>Test</td> <td>Apples</td> <td>Oranges</td> <td>Bananas</td> </tr> </table> I want to convert EACH TR into a PHP ARRAY I want the code to look something like this and it does in the console, however i need to output all of it into a string: <?php array( "data" => 0, array( "Tuesday", "12/31", "New Years Eve", "Test", "Apples", "Oranges", "Bananas" ), "data" => 1, array( "Monday", "12/30", "New Years Eve EVE", "Test", "Apples", "Oranges", "Bananas" ), "data" => 2, array( "Sunday", "12/29", "New Years Eve Eve EVE", "Test", "Apples", "Oranges", "Bananas" ), ); ?> My Current Javascript code is as follows: var count = 0; $("#output").find('tr').each(function(){ count++ var array_str = 'array(' + '"data" => "' + count + '", array('; console.log(array_str); $(this).find('td').each(function(value){ var str = '"'+ value +'" => "'+$(this).text()+'",'; //this makes the php array keys //var str = Array(value); console.log(str); }); console.log("));"); }); Can anyone please help me to output the entire console code that gets returned into a string or into a DIV. thanks
  8. Hello everyone, I am working on a website and i am using AJAX. I am sending requests to the server constantly to have a "LIVE" FEED. I am sending an ajax request to the server to reload a table constantly and another one to reload a different piece of data constantly etc. is there anything bad with doing this? will this run slow if i start to have more traffic?
  9. Hello everyone, i am working on a website that uses facebook api to login with facebook. However i am having a problem with the Javascript and PHP sdk. The problem is that i keep getting an unexpected error which basically expires the facebook Auth Token and then it logs the user out of the website then logs them back in. The code that i am using is below.... <?php require 'facebook.php'; $facebook = new Facebook(array( 'appId' => 'MY_APP_ID_HERE', 'secret' => 'MY_APP_SECRET', 'cookie' => true )); // See if there is a user from a cookie $user = $facebook->getUser(); if ($user) { try { // Proceed knowing you have a logged in user who's authenticated. $user_profile = $facebook->api('/me'); } catch (FacebookApiException $e) { echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>'; $user = null; } } ?> <!DOCTYPE html> <html xmlns:fb="http://www.facebook.com/2008/fbml"> <body> <?php if ($user) { ?> Your user profile is <pre> <?php print htmlspecialchars(print_r($user_profile, true)) ?> </pre> <?php } else { ?> <fb:login-button></fb:login-button> <?php } ?> <div id="fb-root"></div> <script> window.fbAsyncInit = function() { FB.init({ appId: '<?php echo $facebook->getAppID() ?>', cookie: true, xfbml: true, oauth: true }); FB.Event.subscribe('auth.login', function(response) { window.location.reload(); }); FB.Event.subscribe('auth.logout', function(response) { window.location.reload(); }); }; (function() { var e = document.createElement('script'); e.async = true; e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; document.getElementById('fb-root').appendChild(e); }()); </script> </body> </html> The error that i get when the user logs out is this: [error] => Array ( [message] => An active access token must be used to query information about the current user. [type] => OAuthException [code] => 2500 ) Can someone please tell me if i am doing something wrong? How can i get the session to NOT expire so fast?
  10. Hello everyone, I have been thinking of making a casino (poker) game for iOS/Android/Website/facebook etc. Basically i want a clone of Zynga Poker app for iphone. The problem is that i'm not sure where to start. Does anyone have any suggestions on where i could start to make an app exactly like Zynga Poker?? I don't have much knowledge about Servers or Application Security. Also, if i need to hire a team to make this work, what type of job positions would be needed?
  11. yes there is khanahk but sometimes when you have a Large database to import, that will not work because of php's limitations. so the best solution for that is to run a LOAD DATA query on the SQL.
  12. For anyone who is trying to do something similar to what i have to do which is to LOAD a large database onto phpmyadmin..... here is what i did to solve my issue..... 1.) Login to cPanel and white list your ip address. ( go to the mysql remote access and enter your ip address) 2.) Download a program called MySQL Work Bench 3.) Connect to MySQL Workbench using the ip address that shows on on the left side of your cPanel (in my case it's a shared ip address because i am on a shared hosting account) 4.) After you have connected, create a table with the same fields that appear in your Large database file. (in my case it is a .csv file) 5.) use a similar query like the one below (i am on my mac, the path should be your own computer's path): in the example below, i am using the table name "targets" and the fields in my table are State,NPANXX,LATA,ZipCode,ZipCodeCount,ZipCodeFreq,NPA,NXX LOAD DATA LOCAL INFILE '/Users/mycomputername/Downloads/2012-8-StandardAreaCodeDatabase-csv/2012-8-StandardAreaCodeDatabase.csv' INTO TABLE targets FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (State,NPANXX,LATA,ZipCode,ZipCodeCount,ZipCodeFreq,NPA,NXX); I hope i was able to help anyone else who had the same problem as me
  13. hello, i am trying to load a large CSV file in the database and it's not working can someone please tell me what i'm doing wrong?? here is my query for the SQL LOAD DATA LOCAL INFILE '/tmp/2012-8-StandardAreaCodeDatabase.csv' INTO TABLE targets FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (State,NPANXX,LATA,ZipCode,ZipCodeCount,ZipCodeFreq,NPA,NXX); but i get the following error: #2 - File 'tmp/2012-8-StandardAreaCodeDatabase.csv' not found (Errcode: 2)
  14. i have no idea what the problem was..... but i found a way around it. by the way, i think the switch case statement is working correctly. i am trying to say that if the $_SERVER['HTTP_USER_AGENT'] contains any of the following: ipad, iphone, android, ipod, webos then return is mobile. so that i can re-direct the user to a mobile compatible website. Thanks for your help
×
×
  • Create New...