Friday, 24 June 2016

Post 60: MacBook Pro as single DIV with pure CSS

MacBook Pro as single DIV with pure CSS. Looks best in Google Chrome:

Thursday, 23 June 2016

Post 59: iPhone drawing with one DIV only.

I drew an iPhone with only one HTML element only. The rest is pure CSS. Chrome displays the picture the best:

See the Pen iPhone one div with pure CSS by Thadeusz (@thadeuszlay) on CodePen.

Sunday, 19 June 2016

Post 58: Minion with only one div and pure CSS

I'm not really content with the feet. If you've got a better suggesiton, please feel free. I'd be grateful for any comments.

See the Pen Minion by Thadeusz (@thadeuszlay) on CodePen.

Saturday, 18 June 2016

Post 57: Browsers I'm currently using

Chrome Canaary

Do you know more?

Post 56: How to set up Grunt build system

In your terminal type in this

npm install -g grunt-cli

create a project
mkdir myproject

go to you project
cd myproject

type in
npm init

to save grunt into my package
npm install -S grunt

Create a grunt file:
touch Gruntfile.js

grunt has now created a grunt file. You can now go in there an register task:

module.exports = function (grunt) {
grunt.registerTask('speak', function() {

grunt.registerTask('yell', function () {

grunt.registerTask('both', ['speak', 'yell']);
grunt.registerTask('default', ['speak', 'yell']);


To execute these task go to your terminal:
grunt speak

You'll see that it logs out the speak task we defined earlier. The same for
grunt yell

If you typed in 'grunt both', then the tasks in the array in will be executed. If you only type grunt, then the task in the array of our default task will be executed.

You can now go to

For example we want to install the plugin 'contrib-concat'

In your module exports function type in this:

module.exports = function (grunt) {

// Project configuration.
  concat: {
    options: {
      separator: ';',
    dist: {
      src: ['src/intro.js', 'src/project.js', 'src/outro.js'],
      dest: 'dist/built.js',

grunt.loadNpmTasks('grunt-contrib-concat'); // npm loads some preconfigured tasks in the initConfig; in this case it looks in the initConfig and sees the concat key
In your grunt project folder create a folder called 'src'. In that folder create the files intro.js, project.js and outro.js

In these files you can write - for testing purposes - anything you want. We will later see that the content in the 3 mentioned files will be concatened into one - the built.js in the dist-folder.

You can see this effect by running in your terminal:
grunt concat

Another intersting plugin is 'contrib-watch':

Whenever a pattern in your file structure changes, it will update it automatically in the grunt build folder, so you don't have to run the grunt command everytime.

First install it:
npm install grunt-contrib-watch --save-dev

Update your grunt file so it looks like this:
module.exports = function (grunt) {
grunt.registerTask('speak', function() {

grunt.registerTask('yell', function () {

grunt.registerTask('default', ['speak', 'yell']);

// Project configuration.
  concat: {
    jsPortion: {
                  src: ['js/1.js', 'js/2.js'],
                  dest: 'dist/built.js',
     cssPortion: {
                   src: ['css/1.css', 'js/2.css'],
                   dest: 'dist/built.js',
  watch: {
  js: {
          files: ['js/**/*.js'],
      tasks: ['concat:jsPortion'],
   css: {
          files: ['css/**/*.css'],
       tasks: ['concat:cssPortion'],




If you type in your terminal
grunt watch

..and then change one of your js files in your js folder, then you'll see grunt watch executes concat and concatenates the updates into one file.

Feel free to play around with grunt.

Friday, 10 June 2016

Post 55: Sound Motion - Android App uses device motion to generate sounds

I wrote and published a new app that uses the device's accelerometer:

It's a small and fun app. With this app you can imitate different items, like a whip, a hand granade, a machine gun, etc.

Tuesday, 7 June 2016

Post 54: Open Link in Ionic app

In order to open a link in your app you need to install this plugin

cordova plugin add

Sunday, 5 June 2016

Post 53: Add AdMob to your ionic project

Add this plugin:

cordova plugin add cordova-plugin-admobpro

create another JS file with this content and put it into the JS folder (replace the key with your keys):
var admobid = {};
// TODO: replace the following ad units with your own
if( /(android)/i.test(navigator.userAgent) ) {
admobid = { // for Android
banner: 'ca-app-pub-6869992474017983/9375997553',
interstitial: 'ca-app-pub-6869992474017983/1657046752'
} else if(/(ipod|iphone|ipad)/i.test(navigator.userAgent)) {
admobid = { // for iOS
banner: 'ca-app-pub-6869992474017983/4806197152',
interstitial: 'ca-app-pub-6869992474017983/7563979554'
} else {
admobid = { // for Windows Phone
banner: 'ca-app-pub-6869992474017983/8878394753',
interstitial: 'ca-app-pub-6869992474017983/1355127956'
function initApp() {
if (! AdMob ) { alert( 'admob plugin not ready' ); return; }
// this will create a banner on startup
AdMob.createBanner( {
adId: admobid.banner,
isTesting: true, // TODO: remove this line when release
overlap: false,
offsetTopBar: false,
bgColor: 'black'
} );
// this will load a full screen ad on startup
adId: admobid.interstitial,
isTesting: true, // TODO: remove this line when release
autoShow: false
AdMob.showInterstitial(); // can be used to show later,e.g. after the end of the game
if(( /(ipad|iphone|ipod|android|windows phone)/i.test(navigator.userAgent) )) {
document.addEventListener('deviceready', initApp, false);
} else {
Now go to your index.html file and add a reference to that JS file above:
    <script type="text/javascript" src="js/myAdmobFile.js"></script>

Saturday, 4 June 2016

Post 52: detect device motion with Ionic

In this post I'll show you how to detect the motion of your device with Ionic framework.

First create an Ionic project and then add a platform. How to do this with android is explained here.

I created a "tabs" ionic project. But you can choose whatever project type ("blank", "sidemenu") you want.
Download the ng-cordova zip file here. After downloading unzip and find the file "ng-cordova.min.js". The file is located at "ng-cordova-master\dist\". Put that file into the following folder of our project: "yourProject\www\js\".

Add this line in your index.html
<script src="js/ng-cordova.min.js"></script>
<script src="cordova.js"></script>

Install the following two plugins:

cordova plugin add cordova-plugin-device-motion
cordova plugin add cordova-plugin-whitelist

In your app.js add "ngCordova" to your service array:

angular.module('starter', ['ionic', 'starter.controllers', '', 'ngCordova'])

Add this to your index.html:
    <ion-pane ng-controller="MotionController">
        <ion-header-bar class="bar-stable">
            <h1 class="title">Start Watching Device Motion</h1>

            <div class="list">
                <label class="item item-input">
                    <span class="input-label">Frequency</span>
                    <input type="text" placeholder="0" ng-model="options.frequency">
            <button class="button button-full button-positive" ng-click="startWatching()">
                Start Measurement
            <button class="button button-full button-positive" ng-click="stopWatching()">
                Stop Measurement
            <h2>X: {{measurements.x}}</h2>
            <h2>Y: {{measurements.y}}</h2>
            <h2>Z: {{measurements.z}}</h2>

And add this into the header of your index.html

<meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src  'self' 'unsafe-inline' *">

In your controller.js add the MotionController:
.controller('MotionController', function($scope, $cordovaDeviceMotion, $ionicPlatform) {
// watch Acceleration options $scope.options = { frequency: 100, // Measure every 100ms deviation : 25 // We'll use deviation to determine the shake event, best values in the range between 25 and 30 }; // Current measurements $scope.measurements = { x : null, y : null, z : null, timestamp : null } // Previous measurements $scope.previousMeasurements = { x : null, y : null, z : null, timestamp : null } // Watcher object $ = null; // Start measurements when Cordova device is ready $ionicPlatform.ready(function() { //Start Watching method $scope.startWatching = function() { // Device motion configuration $ = $cordovaDeviceMotion.watchAcceleration($scope.options); // Device motion initilaization $, function(error) { console.log('Error'); },function(result) { // Set current data $scope.measurements.x = result.x; $scope.measurements.y = result.y; $scope.measurements.z = result.z; $scope.measurements.timestamp = result.timestamp; // Detecta shake $scope.detectShake(result); }); }; // Stop watching method $scope.stopWatching = function() { $; } // Detect shake method $scope.detectShake = function(result) { //Object to hold measurement difference between current and old data var measurementsChange = {}; // Calculate measurement change only if we have two sets of data, current and old if ($scope.previousMeasurements.x !== null) { measurementsChange.x = Math.abs($scope.previousMeasurements.x, result.x); measurementsChange.y = Math.abs($scope.previousMeasurements.y, result.y); measurementsChange.z = Math.abs($scope.previousMeasurements.z, result.z); } // If measurement change is bigger then predefined deviation if (measurementsChange.x + measurementsChange.y + measurementsChange.z > $scope.options.deviation) { $scope.stopWatching(); // Stop watching because it will start triggering like hell console.log('Shake detected'); // shake detected setTimeout($scope.startWatching(), 1000); // Again start watching after 1 sex // Clean previous measurements after succesfull shake detection, so we can do it next time $scope.previousMeasurements = { x: null, y: null, z: null } } else { // On first measurements set it as the previous one $scope.previousMeasurements = { x: result.x, y: result.y, z: result.z } } } }); $scope.$on('$ionicView.beforeLeave', function(){ $; // Turn off motion detection watcher });