Some Trials & a lot of Errors

I tried a bunch of framework and other language and I usually feel overwhelm when its time to do something real with what I've learned. So that why I created this site, to write my progress and help some noob like me that stumble into the sames problems.

Browse: Page 10

Hibernate Oracle to MySQL: changing the generator class

By Chris on July 9, 2014

Really quick post to a problem I’ve got un hibernate when converting to mySQL, I’ve found that the problem was because we were using a generator class “sequence” and in mySQL we needed to use “assigned” or “increment” instead.

Note you might not have that problem in your project but that was preventing me from creating my ids my mySQL db.

What are that generator class thing, well it how you generate your id. In oracle it usally use a sequence (hence the setting was sequence in hibernate) and mySQL didn’t support sequence at the time I was trying to convert it.

Sequence is safer if any other program/person is going to insert into the database table. Increment is less safer solution (but portable, to those db that don’t support Sequence) and good for testing and\or getting started. There are better ways than using Increment for use in production.

Note that you could use the generationType.AUTO and hibernate will produce the best strategy for you db.

@Id
@GeneratedValue(strategy=GenerationType.AUTO)

Related:

How to have multiple database in a eclipse Java project (candidjava)

Changing database from Hibernate (stackoverflow)

Hibernate Generator class (javaTpoint)

Posted in db | Tagged hibernate, java, mysql, oracle | Leave a response

5 years ago, what did you think would be different from your life today ?

By Chris on November 18, 2013

Posted in inspiration | Tagged inspiration, motivation | Leave a response

How can I pad a String in Java?

By Chris on September 16, 2013

I’ve stumbled upon that problem recently and couldn’t remember how to do it.  Has you except it’s trivial to do and like most of what can be done in programming there more than one way to do it. 

1- Good old jdk String 🙂

Since Java 1.5 you have the new String format method do something similar.

String.format(“%10s”, “bob”).replace(‘ ‘, ‘*’);

String.format(“%-10s”, “bassen”).replace(‘ ‘, ‘*’);

output:

*******bob
bassen****

2- Apache StringUtils

Apache StringUtils has several methods to do this too: leftPad, rightPad, center and repeat.

if you use Apache StringUtils you get this :

StringUtils.leftPad(“bob”, 10, “*”)

StringUtils.rightPad(“bassen”, 10, “*”)

you get the same result

*******bob
bassen****

 3- Google library Guava

If you still want to use another 3rd party library there Google utils library Guava that have something for you too:

Strings.padStart(“bob”, 10, ‘*’);//Equivalent of leftPad
Strings.padEnd(“bassen”, 10, ‘*’); //Equivalent of rightPad

More info on the java doc : http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/base/Strings.html#padStart(java.lang.String, int, char)

 

Has you can see typically, to use these methods, you specify the String that you’d like to pad and the total size of the finished String. This total size includes the starting length of the String. You can specify an alternative padding character or characters via a third argument to these methods.

Posted in java, tips | Tagged Apache, format, Guava, java, String, StringUtils | Leave a response

How to add Run command in windows 7 start menu

By Chris on September 9, 2013

For some reason the pc at work didn’t had the run command in the start menu.

I write it here so I won’t forget it again and to help you too 🙂

  1. Click on start menu.
  2. Select “Control Panel”.
  3. Click on “Personalization”.
  4. Click on “Taskbar and start menu”.
  5. Click on “Customize”.
  6. Now select the “Run command” check box.
  7. Click ok and select “Apply” in the next window
  8. click Ok again 🙂

That’s how you can add back the run command in the windows 7 start menu !!!

 

Posted in prog, tips, tips | Tagged run, run command, start menu, windows 7 | Leave a response

How to synchronize a List in java ? A Vector vs ArrayList Showdown !

By Chris on September 5, 2013

They’re always a question that comeback either in interview or when you are playing old code.
Why the hell are they using Vector over arrayList ?

Vector is a class that exists since the beginning of java (aka Java 1.0) it’s implement List. It seems to pollute old code and still use programmer that don’t know that there is better alternative.

Common knowledge and our teacher use to tell us that the difference between Vector and arrayList is that Vector is synchronized and ArrayList is not, which is true… But what it fails to explain is that you should not use Vector for synchronized operation either. Why ?
Because it’s synchronizes on each individual operation. That’s almost never what you want to do.

Normally if you really need synchronization you want to synchronize a whole sequence of operations, not just the individual operation.
Because even if the add, remove or get operation is synchronized you still need to have a lock to avoid anyone changing the collection at the same time (preventing those pesky ConcurrentModificationException) and it also slower because it lock on each access when once would be enough.

Instead use a ArrayList and use Collections.synchronizedList on your array list when you truly need synchronization.
If you want something more efficient that the Collections.synchronizedList and you are using JDK 1.5 and higher. There is a good concurrent collections that have been introduced in java 1.5. The name of that collection is CopyOnWriteArrayList, it’s highly efficient for high volume , low latency system.

While the Collections.synchronizedMap and Collections.synchronizedList, provide a basic conditionally thread-safe implementation of Map and List.
Several factors make them unsuitable for use in highly concurrent applications — their single collection-wide lock is an impediment to scalability and it often becomes necessary to lock a collection for a considerable time during iteration to prevent ConcurrentModificationExceptions.

The CopyOnWriteArrayList implementation provide much higher concurrency while preserving thread safety, with some minor compromises in their promises to callers. CopyOnWriteArrayList are not necessarily useful everywhere you might use ArrayList, but are designed to optimize specific common situations. Many concurrent applications will benefit from their use.

Posted in prog, tips | Tagged arraylist, collections, java, java.util.List, List, synchronization, synchronizedList, vector | Leave a response

Link Crop: soap vs rest – how quora helped a startup investing in a very old star

By Chris on September 2, 2013

http://blog.foundersnetwork.com/2013/01/how-quora-sent-us-82-10-of-our-visitors/

Story of a startup and how quora helped them bring visitors to the site.

 

http://slant.co/topics/what-is-the-best-architecture-for-building-a-web-service/

soap vs rest…

basicly every new provider use rest now a day…

 

http://antjanus.com/blog/seo/running-a-blog-what-i-did-wrong-and-right-in-2012/

incredible journey from 0 to 20k visitor/month.

What really interesting is how he self-evaluate himself, that really important.

Many point are really good to take action on and will probably worth revisiting when my blog readership grow bigger.

 

https://www.futureadvisor.com/401k/comics/top-three-beginning-investing-books

I love the way they propose book through an infographic/comics, I’ll try that with my business/blog

 

http://www.nature.com/news/nearby-star-is-almost-as-old-as-the-universe-1.12196

What actually great with that discovery is that it’s almost as old as the universe and has some heavy element in them which mean it was a second generation star.

it’s not surprising for small stars to live a long time (they burn quite slowly).

what’s surprising is that we don’t see any older than about 14 billion years old.

 

Posted in link, prog, tips | Tagged blog, quora, rest, seo, soap, star, startup, webservice | Leave a response

Linux vs Microsoft and train your brain for Monk-Like Focus

By Chris on August 29, 2013

Microsoft study: Linux migration cost Munich €60.7 million (h-online.com)

This article really caught my attention, because a government agency (Munich city administration’s) want to get rid of Microsoft and they’re not replacing it with the bloated IBM or Oracle solution and because Microsoft did a study to show how much it cost them (that stink bias here).

What Strange is that Microsoft study made some assessments that were false, forgot to include cost of licensing and upgrade for a windows base solution and they don’t want to publish their study.

Here the study and a HN new discussion (quite old).

 

Train Your Brain for Monk-Like Focus

Here the full article (Source Lifehacker) : http://lifehacker.com/5895509/train-your-brain-for-monk+like-focus

This explain process of the brian to get focus and lose it.

 

The take away point of the article: Your brain will naturally break focus to anything that represents a reward or danger, (blinking light, loud noise, notification)

You can minimize this behavior by wearing earplug or head phone (for the loud noise) and cut notification (phone, email, facebook)

Do a self survey on how you lose your attention. By identifying your triggers you can try to avoid them or program yourself to ignore them.

They even include some tips to help focusing on the task, here a quick list:

  • increase the value of the task you are trying to complete (add a reward or something)
  • meditate
  • practice focus by getting lost in a good story/game etc.

Related : How to improve concentration

Posted in link, prog, tips | Tagged brain, focus, lifehack, linux, meditation, Microsoft, motivation, munich | Leave a response

Setting the class to struts tag

By Chris on August 26, 2013

I had a problem setting up my styleclass in struts, here how I fixed it.

I hope the code come nicely in that theme.

In struts class is not recognized but styleClass is :

http://struts.apache.org/1.x/struts-taglib/tlddoc/html/checkbox.html

you can check the source the styleClass is generated class.

<script language=”JavaScript”>

$(function () {

 $(‘#checkall’).toggle(

       function() {

           $(‘#resultTable .tf’).prop(‘checked’, true);

       },

       function() {

           $(‘#resultTable .tf’).prop(‘checked’, false);

       }

   );

});

</script>

class=”tf” or styleClass if your using struts like me

but his work but only for a button, if checkall is the id of a checkbox with the class tf, it’s change all the checkbox except it’s self

then I tried that: (from : http://stackoverflow.com/questions/2228382/select-all-checkboxes-with-jquery)

$(‘#checkall’).change(function() {

   var checkboxes = $(this).closest(‘form’).find(‘:checkbox’);

   if($(this).is(‘:checked’)) {

       checkboxes.attr(‘checked’, ‘checked’);

   } else {

       checkboxes.removeAttr(‘checked’);

   }

 Mix the 2 solutions together you get the working solution:

$(function () {

$(‘#checkall’).change(

       function() {

if($(this).is(‘:checked’))

$(‘#resultTable .tf’).prop(‘checked’, true);

else

$(‘#resultTable .tf’).prop(‘checked’, false);

       }

   );

});

Hope it help !

Posted in error, prog, tips | Tagged struts, struts tag, styleClass, tags | Leave a response

Link crop: Finding ideas, learning Programing and self help addiction.

By Chris on August 19, 2013

On Finding Ideas

http://nathanbarry.com/finding-ideas-project/

Post on Finding Ideas For Your Next Project, which Nathan describes what do to find a idea that solve a painful problem.

 

http://sivers.org/multiply

Nathan linked this in the previous post, I’ve read this post in the past but it’s always worth revisiting good post.

The basic behind this, is that ideas are not what worth the most, it’s mostly the execution that counts and the other one is that an awful idea will almost always make you lose money 🙂

 

Programing and learning

http://www.perlmonks.org/?node_id=26380

Path to mastery (not just perl)

 

http://www.simplyahmazing.com/2013/01/how-i-read-programming-books.html

Ahmed Abdalla is an electrical engineer that talks about his journey from electrical engineering in the world software  startup.

Here he described how reading his programing book 3 time helped him becoming a better coder.

(reading and making a home project out of the language you are learning.)

 

http://www.simplyahmazing.com/2013/01/are-you-addicted-to-self-help-stuff.html

Another great post from Ahmed Abdalla blog about self help book (and tips/blog) addiction)

Maybe I’m a addict That why I’ve read the link at the bottom of the post (next link)

 

http://www.screwworkletsplay.com/2011/03/are-you-a-self-help-addict-check-for-these-4-warning-signs/

Read it if you want to know if you are actually an addict.

the best quote from the post is that most self help can be generalize in one sentence:

“Take complete responsibility for your own life and the results you get.

Don’t waste time blaming others or complaining about your situation.

Instead, take the actions required to get the results you now want.”

Posted in link, prog | Tagged addiction, ideas, programing, self help | Leave a response

How to know who using what port (linux/window)

By Chris on August 13, 2013

That one is easy, on linux use netstat :

netstat -tlnp | grep 9998

replace 9998 with the port you want to check.

More on net stats here : http://www.thegeekstuff.com/2010/03/netstat-command-examples/

 

On windows :

netstat -an |find /i “9998”

replace 9998 with the port you want to check.

 More info on netstat on Microsoft site or here on Quickly Find Local Open Ports.

Posted in prog, tips | Tagged linux, netstat, port, windows | Leave a response

« PreviousNext »

Tags

2018 2022 app apparment baby book books cleaner date daycare db fantasy draft fantasy sports food foods fridge games gifts grocery hibernate hockey hockey pools ideas inspiration java java.util.List learning List meal plan meal planner motivation mysql oracle productivity retail shopping reviews service social games sql String students The Practice to_date uber wedding

Recent Comments

  • pawan on How to update an entry in an array in mongodb with java MongoTemplate?
  • kevin on Oracle have no Boolean, how to fix this

Calendar

January 2026
MonTueWedThuFriSatSun
 1234
567891011
12131415161718
19202122232425
262728293031 
« Dec  

Archives

  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • March 2021
  • February 2021
  • May 2020
  • January 2019

Copyright © 2026 Some Trials & a lot of Errors.

Powered by WordPress and Hybrid.