torstai 29. lokakuuta 2015

Advanced git. Cherry-pick, rebase and reset.

Today I encountered the following problem: I had put code in another branch that I would need in my master branch, BUT I could not take all code, just few commits. So I first found command called cherry-pick.

With cherry-pick you can merge one (1) commit from another branch and is quite easy to do, but eventually I found out that it is not a right tool for my job. Anyway, checkout your branch where you want to pick the commit.

git checkout mysecondbranch

then do git log with oneline option to show prettier log.

git log --oneline

Then just select the commit you want and checkout back to the master branch. Do

git cherry-pick 62ecb3

And you will merge that commit to your master.

Now if you need to merge multiple commits but not the whole branch cherry-picking is not the right tool for this job. We can rebase. First create a new temporary branch from the branch you want to do the changes. Then do rebase.

git rebase --onto mythirdbranch 76cada^

This means that from our "mythirdbranch" from commit number to the last one are applied to the temporary branch. 


OK so if you mess up with the rebase thing, you can do 

git rebase --abort

or if you already did the rebase, revert it with the following:

git reflog

git reset --hard HEAD@{5}

and the number inside head is the commit where you started the rebase. 

Finally merge the temporary branch your master branch.


PRO TIP


ssh-add id_rsa will add your ssh key to keyring or something. Then you don't need to enter password every single time when you connect to git.


perjantai 14. elokuuta 2015

Potatoman adventures - Mobile game

Long time no articles for my blog. I attended to Haaga-Helias mobile programming couse last year so this post is about my experience about mobile programming.

We had to use PhoneGap for compiling our apps, but in the end we decided to use CocoonJS for building our game. The final task of the course was to create our own mobile application of course. I haven't created any mobile games yet, so I decided with my friend we will make a mobile game for Android. I also had two Android phones to test the application.

First we decided the game should be Super Mario like 2D runner game with very easy controllers. Maximum of 4 buttons. Then we decided to use only 3 buttons. Left, right and jump. The game is easy enough to be played on the mobile. The challenging part was which game engine we should use or use our own? We found many different engines, but we wanted HTML5 based game engine, because then the game would be easy to port to any operating system. Then we found Quintus which was what we were looking for. It had mobile controllers implemented already. We decided to do at least three levels for the game, create some sound effects, background music and a little starting intro like in Max Payne which is black and white comic.

It actually took us very long to do the game. If we had created the whole engine it would have taken over a year from the team of two guys.


I was in charge of the game graphics. All graphics are done with Adobe Photoshop and Illustrator. Our game engine needed Tiled map editor for the level design. I created also the levels. Then I used microphone and Audacity to create sound effects. My partner focused on game logic and programming. When all the material were ready we also created teaser video for our application and compiled it in the CocoonJS. We had some trouble converting the game but in the end we managed to do it. It was a nice little project. To keep our code nice and clean we put it to GitHub.


Till this day 14.8.2015 our game has got over 200 downloads from the Play Store.

https://play.google.com/store/apps/details?id=com.potatoman.adventures

We got 5/5 grade for creating and publishing this game.


keskiviikko 27. toukokuuta 2015

Robots.txt file for Wordpress

For Wordpress its good idea to put wp-admin in disallow. This means Google bots don't visit wp-admin page and rank it on search.

User-agent: *
Disallow: /wp/wp-admin/

sunnuntai 23. marraskuuta 2014

Android application - pixel check

I just published my second Android application to Google PlayStore. It goes by the name "Pixel check". You can change the screen color by tapping screen. If there are dead pixels they show as black/grey and if the pixel has color errors it should stand out. Try it out here: https://play.google.com/store/apps/details?id=com.shnigi.pixelcheck





perjantai 7. marraskuuta 2014

Alphabets game

When I was a kid I played game where I had to enter all the alphabets as fast as I can. Two days ago I remembered that game and wanted to create my own version. This game is written with Javascript + HTML + CSS + PHP + MySQL. Game is created with Javascript and then PHP saves results to database. Top 10 players are queried from the database. Try it out here: http://84.251.124.101/~shnigi/aakkoset/index.php


tiistai 14. lokakuuta 2014

Javascript applications

So I have been learning Javascript for a while now and I'm getting it slowly. But still it feels so hard. I completed codeacademy.com Javascript course and had some other things to read. So far I have quickly developed three little things.

First one is rock, scissors, paper game. Simple game. Try the demoversion here: http://84.251.124.101/~shnigi/kivisaksipaperi/pewi.html


Next one is coinflipper. Select your side and flip it here: http://84.251.124.101/~shnigi/kolikonheitto/


Last one is Lotto-machine where you enter 4 different things and the machine tells you which one is best. Try it here: http://84.251.124.101/~shnigi/lottokone/

I'm planning to do a mobile app (Android) later from one of these.

perjantai 3. lokakuuta 2014

What is XML and how to use

XML was designed to describe data. With XML one can for example change data between two systems running on different platform and code. XML does not do anything. XML needs to be manipulated that it can be used. Here is an example of XML file from W3 schools:

<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>

XSD is somekind of file that defines how XML file should be formatted. For example elements are defined as string and should be manipulated as string.

<xs:element name="note">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="to" type="xs:string"/>
      <xs:element name="from" type="xs:string"/>
      <xs:element name="heading" type="xs:string"/>
      <xs:element name="body" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>
</xs:schema>

XML and XSD files can be easily generated from online converters. Next is XSLT file which is used to select data and define how it is generated in HTML file. To define the XSLT file which will be used to convert the XML file to HTML use this tag

<?xml-stylesheet href="filename.xslt" type="text/xsl" ?>

To select values from XML file with XSLT one can put HTML tags inside XSLT and then use for example for each loop to select all items. In the select tag is the "path" to the thing that should be selected. If the XML file path has "properties" use @ to select the property. Example of XSLT file:

<div>
<xsl:for-each select="sports-content/tournament/tournament-division/tournament-round">
<h3> 
<xsl:value-of select="tournament-round-metadata/site/site-metadata/home-location/@city"/>
<xsl:value-of select="tournament-round-metadata/site/site-metadata/home-location/@country"/>
</h3> 
 </div>

Then open the XML file with web browser and if it is correctly set up it will show up as HTML. Tada!


As IDE I use Eclipse. For more information check W3 Schools. I find XML hard to understand. But for example data could be changed from PHP program to Java program with XML.