All posts by Social marketing master

Python Read a file, ignore comments and match text

My code:

    import re
    import os
    import glob
    import numpy as np

    #regex for packets
    regTel = re.compile(r'[A-Z_]+[.][A-Z0-9_]+')

    infile = "C:\Users\\alopes\\afolder\doc_name.ext"
    with open(infile, "r") as fobj:
        fh = fobj.read()
        #search for the packets
        packets = regTel.findall(fh)
        for i in packets:
            print i

doc_name.ext:
This looks something like this:

    ;(C)**************************
    ;(C) some text here
    ;(C) U.S.                    *
    ;(C)**************************
    ;*** $Date
    ;*****************************
    ; text here HELLO_WORLD.THIS_IS_1_TEST
    ;
    ; more text here
    ;

read more

Google maps project does not work on mobile devices

I built a map using Google Map’s API. It works just as I want it to on desktop, but it does not load on mobile. My site is responsive and I have the width of the map-canvas set to 100%. I read some posts suggesting I need to get rid of my size styling for it to work, but I have not have had luck with this. Can anyone help me with this map? Thanks

This is the webpage where I am running the code. http://stlresidences.com/test-map

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<style>
 #googft-mapCanvas {
    height: 600px;
    margin: 0;
    padding: 0;
    width: 100%;
}
.controls {
    margin-top: 10px;
    border: 1px solid transparent;
    border-radius: 2px 0 0 2px;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    height: 32px;
    outline: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
#pac-input {
    background-color: #fff;
    font-family: Roboto;
    font-size: 15px;
    font-weight: 300;
    margin-left: 12px;
    padding: 0 11px 0 13px;
    text-overflow: ellipsis;
    width: 300px;
}
#pac-input:focus {
    border-color: #4d90fe;
}
.pac-container {
    font-family: Roboto;
}
#type-selector {
    color: #fff;
    background-color: #4d90fe;
    padding: 5px 11px 0px 11px;
}
#type-selector label {
    font-family: Roboto;
    font-size: 13px;
    font-weight: 300;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?libraries=geometry,places"></script>
<input id="pac-input" class="controls" type="text" placeholder="Enter Address Here">
<div id="googft-mapCanvas"></div>
<script>
function initialize() {
    google.maps.visualRefresh = true;
    var isMobile = (navigator.userAgent.toLowerCase().indexOf('android') > -1) || (navigator.userAgent.match(/(iPod|iPhone|iPad|BlackBerry|Windows Phone|iemobile)/));
    if (isMobile) {
        var viewport = document.querySelector("meta[name=viewport]");
        viewport.setAttribute('content', 'initial-scale=1.0, user-scalable=no');
    }

    var mapDiv = document.getElementById('googft-mapCanvas');
    mapDiv.style.width = isMobile ? '100%' : '1000px';
    mapDiv.style.height = isMobile ? '100%' : '300px';
    var map = new google.maps.Map(mapDiv, {
        center: new google.maps.LatLng(38.64936217820852, -90.53628850000001),
        zoom: 9,
        mapTypeId: google.maps.MapTypeId.HYBRID
    });
    map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(document.getElementById('googft-legend-open'));
    map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(document.getElementById('googft-legend'));

    layer = new google.maps.FusionTablesLayer({
        map: map,
        heatmap: {
            enabled: false
        },
        query: {
            select: "col26",
            from: "11Q0B7iRayT2JIOBl8_VRUmitimhX1W01byuFDnAv",
            where: ""
        },
        options: {
            styleId: 2,
            templateId: 2
        }
    });
    if (isMobile) {
        var legend = document.getElementById('googft-legend');
        var legendOpenButton = document.getElementById('googft-legend-open');
        var legendCloseButton = document.getElementById('googft-legend-close');
        legend.style.display = 'none';
        legendOpenButton.style.display = 'block';
        legendCloseButton.style.display = 'block';
        legendOpenButton.onclick = function () {
            legend.style.display = 'block';
            legendOpenButton.style.display = 'none';
        }
        legendCloseButton.onclick = function () {
            legend.style.display = 'none';
            legendOpenButton.style.display = 'block';
        }
    }
    var marker = new google.maps.Marker({
        position: new google.maps.LatLng(38.64936217820852, -90.53628850000001),
        map: map,
        draggable: true,
        title: "Your New Home",
    });
     // Create the search box and link it to the UI element.
  var input = document.getElementById('pac-input');
  var searchBox = new google.maps.places.SearchBox(input);
  map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

  // Bias the SearchBox results towards current map's viewport.
  map.addListener('bounds_changed', function() {
    searchBox.setBounds(map.getBounds());
  });

  // Listen for the event fired when the user selects a prediction and retrieve
  // more details for that place.
  searchBox.addListener('places_changed', function() {
    var places = searchBox.getPlaces();
    if (places.length == 0) {
      return;
    }
    // For each place, get the icon, name and location.
    var bounds = new google.maps.LatLngBounds();
    places.forEach(function(place) {
      if (place.geometry.viewport) {
        // Only geocodes have viewport.
        map.fitBounds(place.geometry.viewport);
      } 
      else {
         map.setCenter(place.geometry.location);
      map.setZoom(11);  // Why 17? Because it looks good.
      }
      // now let's move the marker
      marker.setPosition(place.geometry.location);
    });
    //map.fitBounds(bounds);
    map.panTo(marker.getPosition());
  });
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<body>
</body>
</html>

read more

Head first design pattern bug

I am studying Head First – design patterns and translating the exercises to PHP.

I dont get any errors but there is a bug that I cannot figure out.

Edit ( Code ):

abstract class Cat 
{
    public $meowBehaviour, $eatBehaviour;
    function __construct(MeowBehaviour $meowBehaviour, EatBehaviour $eatBehaviour)
    {
        $this->meowBehaviour = $meowBehaviour;
        $this->eatBehaviour = $eatBehaviour;
    }
    public abstract function sits();
    public function performMeowBehaviour()
    {
        $this->meowBehaviour->meow();
    }
    public function performEatBehaviour()
    {
        $this->eatBehaviour->eat();
    }
}



interface EatBehaviour {
    public function eat();
}

class EatCatFood implements EatBehaviour {
    public function eat()
    {
        echo "I eat cat food. <br />";
    }
}

class EatGazzelle implements EatBehaviour {
    public function eat()
    {
        echo "I hunt and eat gazzelle. <br />";
    }
}

interface MeowBehaviour {
    public function meow();

}

class Meow implements MeowBehaviour {
    public function meow()
    {
        echo "meow <br />";
    }
}

class Roar implements MeowBehaviour {
    public function meow()
    {
        echo "ROAR! <br />";
    }
}

class HouseCat extends Cat
{

    function __construct()
    {
        parent::__construct(new Meow, new EatCatFood);
    }
    public function sits()
    {
        echo "if I fits I sits";
    }
}

class CatSimulator {
    public $cat;
    public function __construct()
    {
        $this->cat = new HouseCat;
        $this->cat->performMeowBehaviour();
        $this->cat->performEatBehaviour();
    }
}

$c = new CatSimulator;

read more

Navigation Bar text aligning backwards (CSS)

I’m in the process of developing my first website and I’m having an issue with the Navigation Bar. I’m using CSS rules to align the bar but unfortunately when I set the rules to float:right; my text is floating right but it’s lining up backwards on the bar. How can I float the text over to the right and align the text correctly?

.nav ul li {
  display: inline-block;
  float: right;
  padding: 10px 10px;
}
.nav {
  background-color: black;
  position: fixed;
  width: 100%;
  top: 0px;
  margin: auto;
  font-weight: bold;
  border-bottom: 2px solid orange;
  margin-top: 5px;
}
.nav ul li a {
  color: orange;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0px 10px;
}
<div class="nav">
  <ul>
    <li><a href="#">Home</a>
    </li>
    <li><a href="#">About</a>
    </li>
    <li><a href="#">Contact</a>
    </li>
    <li><a href="#">Portfolio</a>
    </li>
    <li><a href="#">FAQ</a>
    </li>
  </ul>
</div>

read more

Navigation Bar text aligning backwards (CSS)

I’m in the process of developing my first website and I’m having an issue with the Navigation Bar. I’m using CSS rules to align the bar but unfortunately when I set the rules to float:right; my text is floating right but it’s lining up backwards on the bar. How can I float the text over to the right and align the text correctly?

.nav ul li {
  display: inline-block;
  float: right;
  padding: 10px 10px;
}
.nav {
  background-color: black;
  position: fixed;
  width: 100%;
  top: 0px;
  margin: auto;
  font-weight: bold;
  border-bottom: 2px solid orange;
  margin-top: 5px;
}
.nav ul li a {
  color: orange;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0px 10px;
}
<div class="nav">
  <ul>
    <li><a href="#">Home</a>
    </li>
    <li><a href="#">About</a>
    </li>
    <li><a href="#">Contact</a>
    </li>
    <li><a href="#">Portfolio</a>
    </li>
    <li><a href="#">FAQ</a>
    </li>
  </ul>
</div>

read more