Laravel 5 and simple Forms workaround

Here is a simple example of using laravel 5 powerful forms to deliver a secure and fast result!
To make our lives easier we need to install the HTML package!

In file /compojer.json we add:
"require": {
"laravel/framework": "5.0.*",
"laravelcollective/html": "~5.0"

Next add the service provider and aliases.
In /config/app.php we update the following:

'providers' => [

'aliases' => [
'Form'=> 'Illuminate\Html\FormFacade',
'HTML'=> 'Illuminate\Html\HtmlFacade',


Laravel 5 TIPS For Beginners!

Here are some tips you might find handy when you think you have done everything according to the tutorials!

In formrequests to authorise access only for registered/signed users we add

use Auth;
public function authorize()
if ( !Auth::check() )
return false;
return true;


Redirecting varnish to new backend on the fly

varnishCache1) Change VCL backend config

Go to your vcl file (in my case /etc/varnish/default.vcl). Edit the backend param to point to another server. Also increase the timeouts since it will take longer than accessing localhost.

backend default {
 .host = "";
 .port = "80";
 .connect_timeout = 120s;
 .first_byte_timeout = 600s;
 .between_bytes_timeout = 60s;

2) Validate VCL script on the fly

sudo varnishd -C -f /etc/varnish/default.vcl

This will notify if any syntax issues exist.


3) Reload the VCL Script without restarting varnish

I utilized:

$varnishadm -T localhost:6082
vcl.load reload01 /etc/varnish/default.vcl 
vcl.use reload01


Changing user agent for RESTClient firefox extension


If you are using RESTClient (and don’t want to switch to CURL) but need to modify the user-client when testing a request, there are two ways:

  • Adding a custom “user-agent” header through RESTClient
  • Changing the user agent through an extension.

Since RESTClient is an extension, by default it uses the user-agent of firefox.

As a start we can do a test and access the page through the RestClient.


Calling Mysql Iteratively and Passing Parameters from Bash Loop

Linux and MysqlBelow we see an example of calling a mysql script from a file and passing a param.

sql script

So make a file with the following (or whatever else you wish):

SET @i = 1;
use databaseName;
SET @pID=@i+100;
SET @partnerID=concat('partner',@pID);
select @i, @pID , @partnerID;

Now, this will print out the values of i, pID, and partnerID.
Below that you could include insert statements or whatever else you wish.

Now how do we call this from bash and set the @i param?

bash script


for i in {300..400..5}
sed -i "1 s/.*/set @i=$i;/" sample.sql
mysql --user="$user" --password="$password" < sample.sql

So how does this work?
We use sed to replace the first line completely in sample.sql with a new “set @i=” command containing the i param we want.
We then call mysql and feed the rewritten file.

Another way to do this would be to concatenate the sample.sql contents to the set command, and feed them to mysql in memory.

Build a Server – Client Application in C that executes concurrently Terminal Commands

In this post we will build a server – client application that will get our hands dirty with signals, fork, named pipes and the exec command. This application has a very simple concept:

“Client creates, with a new process, the Server and sends to him terminal commands using as interprocess communication a named pipe (aka fifo pipe)”

Moreover this model must executes terminal commands concurrently and we accomplish that using a signal handler. To be more specific when a client sends through the named pipe a command, the server wakes up because the signal handler  receives the SIGCONT signal and changes the wake up variable from 1 to 0. This wake up variable is being used in the server to keep him in sleep mode and not busy waiting. Let’s see a simple example with just the mechanism of it:

API-Axle: Tips, Tricks and Gotchas


This is a brief post to help beginners with API-Axle. What is API-Axle? As described on their site:

ApiAxle is a proxy that sits on your network, in front of your API(s) and manages things that you shouldn’t have to, like rate limiting, authentication and analytics. It’s fast, open and easy to configure.

Here are some tips to help out with the initial instructions at: .

Note: myapi in myapi.api.localhost should be replaced by your own api name.

Increase Timeout

The initial timeout (2 seconds) can result in errors because your backend API server takes time to reply to api-axle. In order to increase this you can use the endPointTimeout parameter.

Example (10 seconds):

axle> api "myapi" create endPoint="" endPointTimeout=10 
axle> key "1234" create 
axle> api myapi linkkey "1234"


Android: Circular ViewPager

Recently I was building an Android Application and needed a circular ViewPager. That is a ViewPager that will automatically move to the first page when you swipe the last. Apparently there is no Native Support for this, neither could I find any good implementation online.

So here is a simple but effective way to do this.

The idea is basically to apply the functionality to the PagerAdapter you will insert in the ViewPager. What you do is create a huge set of Pages (lets say 10000) and set the current page in the middle.

So here it is:

 * Created by Chris Georgoulis on 8/3/2014.
public class ImageAdapter extends PagerAdapter {

	public static final int PAGER_PAGES = 10000;
	public static final int PAGER_PAGES_MIDDLE = PAGER_PAGES / 2;

	private List drawables;

	public ImageAdapter(List drawables) {
		this.drawables = drawables;


Create a Word Auto-Completer in C using the Trie Data Structure

So first of all a few words about our basic structure, the trie…

In computer science, a trie, also called digital tree and sometimes radix tree or prefix tree (as they can be searched by prefixes), is an ordered tree data structure that is used to store a dynamic set or associative array where the keys are usually strings. Unlike a binary search tree, no node in the tree stores the key associated with that node; instead, its position in the tree defines the key with which it is associated. All the descendants of a node have a common prefix of the string associated with that node, and the root is associated with the empty string. Values are normally not associated with every node, only with leaves and some inner nodes that correspond to keys of interest.

For example, in our case, our project involves alphabets with every inner node of the trie data structure representing a letter which means that each node has a unique path from the root (can have up to 26 children as the number of the Latin alphabet) that symbolizes a word.


In our project, in order to create our fancy auto-completer we will need three structures. Firstly we need the structure of the

inner nodes that store a character that represents the letter of this node, an array of 26 letters that will navigate through the next letter. Moreover to make our program more accurate we will use an array that stores the top leafs (top words) under this inner node and a leaf pointer that is going to show us that the path from the root until this inner node reflects a word. The leaf structure contains the frequency of this word (which is the parent of the leaf) and a pointer to the last letter of the word.


Java EE DAO Pattern

Java EE really makes our life easy when dealing with Database Management. Here is a basic DAO design pattern that I use in most of my projects:

public abstract class AbstractDao, ID extends Serializable> {

protected abstract EntityManager getEntityManager();

private Class entity;

public AbstractDao(Class entity) {
this.entity = entity;

public T find(ID id) {
return getEntityManager().find(entity, id);

public List findAll() {
CriteriaQuery cq = getEntityManager().getCriteriaBuilder()

return getEntityManager().createQuery(cq).getResultList();

public List findByPage(int pageNum, int pageSize) {
CriteriaQuery cq = getEntityManager().getCriteriaBuilder()

int firstResult = pageNum * pageSize;
return getEntityManager().createQuery(cq).setFirstResult(firstResult)

public long count() {
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery cq = cb.createQuery(Long.class);
Root personRoot = cq.from(entity);;

List list = getEntityManager().createQuery(cq).setMaxResults(1)

long personsNumber = 0l;
if (!list.isEmpty()) {
personsNumber = list.get(0);
return personsNumber;

public T save(T entity) {
try {
if (entity.getId() == null) {
} else {
entity = getEntityManager().merge(entity);
} catch (Exception e) {
return entity;

public T saveAndFlush(T entity) {
try {
entity = save(entity);
} catch (Exception e) {
return entity;

public void flush() {

public List saveAllAndFlush(Collection collection) {
List list = null;
try {
list = collection.parallelStream()
} catch (Exception e) {
return list;

public boolean exists(ID id) {
return find(id) != null;

protected abstract Logger getLogger();