Wednesday, April 11, 2012

Parse: Sending Push Notifications using PHP with/without cURL

I started using Parse to easily send push notifications to phones with my app. However I needed to use PHP to send the notifications and not from the command line as shown in their api.

I came up with the following using cURL:

 $ch = curl_init(); 

 $arr = array();
 array_push($arr, "X-Parse-Application-Id: YOUR_APPLICATION_ID");
 array_push($arr, "X-Parse-REST-API-Key: YOUR_REST_API_KEY");
 array_push($arr, "Content-Type: application/json");
 curl_setopt($ch, CURLOPT_HTTPHEADER, $arr);
 curl_setopt($ch, CURLOPT_URL, '');
 curl_setopt($ch, CURLOPT_POST, true);
 curl_setopt($ch, CURLOPT_POSTFIELDS, '{ "channel": "","data": { "alert": "Red Sox win 7-0!" } }');

And if for some reason you don't want to use cURL, here is the code using the default stream_context_create and file_get_contents methods:

 $url = '';
 $data = '{"channel":"","data":{ "alert":"Red Sox win 7-0!"}}';

 $opts = array('http' =>
   'method'  => 'POST',
   'header'  => "X-Parse-Application-Id: YOUR_APPLICATION_ID\r\n
       X-Parse-REST-API-Key: YOUR_REST_API_KEY\r\n
       Content-Type: application/json\r\n
       Content-Length: " . strlen($data) . "\r\n",
   'content' => $data

 $context  = stream_context_create($opts); 
 $result = file_get_contents($url, false, $context);
 echo $result;

Tuesday, April 3, 2012

Virtual Nomads

Why do we play video games? We play video games for a social experience. Games can be after all part of the greate social network of the Internet. We play with others because it is more fun. Are social networks a bad things and can such social stimulation be addictive? Perhaps. Games start to become addictive when the player starts to feel compelled be there. The virtual world can be great and terrible. Not only is a product of our genius, but it costs virtually nothing to contribute too. It is something that we can get sucked into and lose our way. Most of us cannot do anything without our computers. The virtual world is has become our lives now. But we are humans, and no man is an island. We can't get all of our social fulfillment from video games. Eventually we feel that need and we come out into the light eventually. Do video games have lasting value? We play for many reasons: to relax, to create, to feel acomplished when we win, but mostly because we are bored. It is much easier to play a video game then it is to go out and make a new, real friend, or to learn a new skill. We lose ourselves if we lose the desire to innovate.

Monday, April 2, 2012

Multi-line overflow in Sencha Touch/ExtJS

Unfortunately CSS doesn't support multi-line overflow. I stumbled upon a stackoverflow question that addressed this. I applied this to work in Sencha Touch and ExtJS.

Try it yourself on jsfiddle:
ExtJS fiddle
Original jquery fiddle

With the following HTML:

<style type="text/css">
.item { 
   width: 300px; height: 120px; overflow: hidden;

.item div { 
  padding: 10px; margin: 0; 

<div class="category-item">
   <div class="list-item-title">Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
      Proin nisi ligula, dapibus a volutpat sit amet, mattis et dui. Nunc porttitor accumsan 
      orci id luctus. Phasellus ipsum metus, tincidunt non rhoncus id, dictum a lectus. Nam sed
      ipsum a lacus sodales eleifend. Vestibulum lorem felis, rhoncus elementum vestibulum eget, 
      dictum ut velit. Nullam venenatis, elit in suscipit imperdiet, orci purus posuere mauris, 
      quis adipiscing ipsum urna ac quam.

The javascript to add multi-line overflow in Sencha Touch is:

var item ='.item div').first();
var divh ='.item').first().getHeight();
while (item.getOuterHeight()>divh) {
   item.dom.innerText = item.dom.innerText.replace(/\W*\s(\S)*$/, '...');

ExtJS is the same with one line changed:

var'.item div').first();

while (item.getComputedHeight()>divh) { //this line changed
    item.dom.innerText = item.dom.innerText.replace(/\W*\s(\S)*$/, '...');

The above code with display the following:

Lorem ipsum dolor sit amet, consectetur 
adipiscing elit. Proin nisi ligula, dapibus a
volutpat sit amet, mattis et dui. Nunc
porttitor accumsan orci id luctus. Phasellus
ipsum metus, tincidunt non rhoncus id...