Create sequence in Oracle without dropping it

by GarciaPL on Thursday, 25 August 2016

Some of you might thinking how to create sequence for table which contains some records. You might always export all records from database, then eventually create sequence and after all import those records once again into database. Nevertheless there is a solution how to create this sequence using PL/SQL.



DECLARE
  seq_value_holder        NUMBER;
BEGIN
  -- create a sequence for YOUR_TABLE
  SELECT NVL(MAX(id), 0) + 1
  INTO seq_value_holder
  FROM YOUR_TABLE;
  EXECUTE immediate 'create sequence SEQ_YOUR_TABLE start with ' || seq_value_holder || ' increment by 1';
END;

Notes of Google recruitment process

by GarciaPL on Monday, 8 August 2016

A few days ago, I got an email with inquiry if I would like to participate in recruitment process to Google. I thought why not. It is always good to gain some experience around that. After a phone interview which was not successful for me, but I am not sad about that fact at all, I thought that I might give you some insight what areas you should refresh or just learn quickly. Of course your questions will be correlated with those areas which you picked up before phone interview, but I assume that some of them might be similar with those which I chose.


  • Operating systems - monitors, semaphores, mutexes, linux, unix, processes, inode
  • Algorithm Complexity - big O notation for different algorithms. Provide some complexity for sorting algorithms. Pick up those data structures which have following complexity for instance O(n log (n))
  • Mathematics - calculate something very quickly in mind for instance 2 to the power of 32
  • Trees - big O notation for different operation performed on trees like AVL, Binary trees
  • Java - question related to programming language which you chose

Above list might looks like little chaotic, but I think that you might find some segment of knowledge which is required to get into to the next level of recruitment process in Google. Good luck!

Mutation testing with Pitest

by GarciaPL on Saturday, 2 July 2016

Some of you might be interested in presentation which I made recently for internal training purpose. Topic is "Mutation testing with Pitest".


Face Slim - light Facebook for Android phones

by GarciaPL on Saturday, 18 June 2016

If you are trying to speed up your Android phone, you should consider uninstalling Facebook! You can read more about that phenomenon for instance here : https://www.reddit.com/r/Android/comments/42kyph/uninstalling_facebook_speeds_up_your_android/. To be honest my phone is much faster after removing Facebook.

After uninstalling Facebook, you might looking for replacement. There is a application called Face Slim [1]. Maybe it is not perfect, but if you only view posts on Facebook and put comment occasionally, it might be totally fine.

Recently I installed this application on Samsung Galaxy S3. After running it, I found that I am not able to login due to bad rendering of login screen [2]. Only what you need to do, is clearing UA (User Agent) settings in application.

Reference :

Guava Enum Mapper

by GarciaPL on Monday, 23 May 2016

Have you ever wondered how to map enums from one to another ? Did you use switch statement to make it work ? Now you can use method immutableEnumMap from class Maps which is part of Guava. Below you can find an example.


public class EnumSourceMapper {

    static ImmutableMap<EnumSource, EnumDestination> mapper;

    static {
        mapper = Maps.immutableEnumMap(ImmutableMap.<EnumSource, EnumDestination>builder()
                .put(EnumSource.SUCCESS,                  EnumDestination.SUCCESS)
                .put(EnumSource.INCOMPLETE,               EnumDestination.ERROR)
                .put(EnumSource.FAIL,                     EnumDestination.ERROR)
                .build());
    }

    public EnumDestination getEnumDestination(EnumSource enumSource) {
        return mapper.get(enumSource);
    }
}



Reference:

EuroMonitor - get email notification about currency

by GarciaPL on Monday, 9 May 2016

Recently I was trying to convert some cash in EUR currency, but I did not have time to watch currency graph all the time. So, I have created small tool which will let me know via email when currency will get more expensive above some concrete level. You can put below script in cron to execute it with some time interval. I used Sparkpost as a email provider.

import urllib2
import json
from sparkpost import SparkPost

sp = SparkPost('YOUR_API_KEY')

def currencyConverter(currency_from,currency_to):
    yql_base_url = "https://query.yahooapis.com/v1/public/yql"
    yql_query = 'select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20("'+currency_from+currency_to+'")'
    yql_query_url = yql_base_url + "?q=" + yql_query + "&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys"
    try:
        yql_response = urllib2.urlopen(yql_query_url)
        try:
            yql_json = json.loads(yql_response.read())
            currency_output = 1 * float(yql_json['query']['results']['rate']['Rate'])
            return currency_output
        except (ValueError, KeyError, TypeError):
            return "JSON format error"

    except IOError, e:
        if hasattr(e, 'code'):
            return e.code
        elif hasattr(e, 'reason'):
            return e.reason

currency_from = "EUR" # currency codes : http://en.wikipedia.org/wiki/ISO_4217
currency_to = "PLN"
direction_rate = 4.44

rate = currencyConverter(currency_from,currency_to)
print rate

if rate > direction_rate:
 response = sp.transmissions.send(
     recipients=['YOUR_EMAIL@gmail.com'],
     html='Rate of ' + currency_from + currency_to + ' equals ' + str(round(rate, 2)) + '
', from_email='test@sparkpostbox.com', subject='EuroMonitor' ) print(response) else: print "Rate too low"

Reference :
[1] EuroMonitor Source Code