lördag 29 december 2012

play framework jpa join two tables

http://stackoverflow.com/a/7873969/517457

Every time you have a field names "xxxId" in an entity, and "xxxId" is the ID of another entity, you did something wrong. The point of JPA is to manipulate objects, and associations between objects using object references or object collections.
Your tbl_lookup_user_major looks like a join table to me. Such a join table means that you have a many-to-many (or one-to-many, is one of the IDs is unique) between Major and User. So, your Major entity should have the following field :
@ManyToMany
@JoinTable(...) // details omitted
private Set<User> users;
And your JPA query should look like
select m from Major m
inner join m.users user
where user.id = :userId

torsdag 27 december 2012

limit bandwidth on dd-wrt router

http://markmaunder.com/2011/01/26/how-to-reliably-limit-the-amount-of-bandwidth-your-room-mate-or-bad-office-colleague-uses/



tisdag 25 december 2012

reload .bashrc after changes

http://askubuntu.com/a/152463

Please place those lines -
export PATH=$PATH:/to/path/play
, in .bashrc file in your user directory and restart the system OR just execute the following command:
source ~/.bashrc

onsdag 5 december 2012

Getting the response header

http://stackoverflow.com/a/2444499/517457


$(document).ready(function() { 
    $("[name='submit']").click(function() { 
        $.ajax({
            type: "POST",
            data: $(".form-signup").serialize(),
            url: "external.asp", 
            success: function(output, status, xhr) { 
              alert(xhr.getResponseHeader("Content-Length"));
            },
            error: function(output) {
              $('.sysMsg').html(output);
            }
        }); 
    }); 
});

söndag 25 november 2012

upgrade or downgrade java version ubuntu/linux

http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html

To add our PPA and install the latest Oracle Java 7 in Ubuntu (supports Ubuntu 13.04, 12.10, 12.04, 11.10, 11.04 and 10.04), use the commands below:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

After the installation finishes, if you wish to see if it was successful, you can run the following command:
java -version
It should return something like this:
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b20)
Java HotSpot(TM) Server VM (build 23.0-b21, mixed mode)

The package installs all the Java binaries, so you can also try "javac -version" which should return "javac 1.7.0_04" and so on (the "_04" part of the version can be different because I'm constantly updating the PPA with the latest Oracle Java 7 version).

If for some reason, the Java version in use is not 1.7.0, you can try to run the following command:
sudo update-java-alternatives -s java-7-oracle

Update: the Oracle Java 7 (JDK & JRE) PPA is now available for Ubuntu 12.10 Quantal Quetzal and 13.04 Raring Ringtail.

Update 2: the installer now requires you accept the Oracle license before the installation begins. This is only required once. If for some reason you need the installation to be automated, you can run the following command to automatically accept the Oracle license:
sudo echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections



Removing Oracle Java 7


If you don't want to use Oracle Java (JDK) 7 anymore and want to go back to OpenJDK, all you have to do is remove the Oracle JDK7 Installer and the previous Java (OpenJDK, etc.) version will be used:
sudo apt-get remove oracle-java7-installer

tisdag 18 september 2012

TinyMCE in JEditable


$.fn.tinymce = function(options){
   return this.each(function(){
      tinyMCE.execCommand("mceAddControl", true, this.id);
   });
}
function initMCE(){
   tinyMCE.init({
        mode : "textarea",
        theme : "advanced",
        ... // YOUR CUSTOMIZATION
      });
}

initMCE();

$.editable.addInputType('mce', {
   element : function(settings, original) {
      var textarea = $('<textarea id="'+$(original).attr("id")+'_mce"/>');
      if (settings.rows) {
         textarea.attr('rows', settings.rows);
      } else {
         textarea.height(settings.height);
      }
      if (settings.cols) {
         textarea.attr('cols', settings.cols);
      } else {
         textarea.width(settings.width);
      }
      $(this).append(textarea);
         return(textarea);
      },
   plugin : function(settings, original) {
      tinyMCE.execCommand("mceAddControl", true, $(original).attr("id")+'_mce');
      },
   submit : function(settings, original) {
      tinyMCE.triggerSave();
      tinyMCE.execCommand("mceRemoveControl", true, $(original).attr("id")+'_mce');
      },
   reset : function(settings, original) {
      tinyMCE.execCommand("mceRemoveControl", true, $(original).attr("id")+'_mce');
      original.reset(this);
   }
});
 
In your JEditable initiation make it of type mce. So:


    $(".edit").editable('ajax/save.php?editnotetext', {
        type
: 'mce',
       
... // etc
   
});
 





http://stackoverflow.com/a/5969896/517457

söndag 2 september 2012

Sound fix for SKYPE in UBUNTU

http://ubuntuforums.org/showpost.php?p=11086836&postcount=12 

Re: skype can only see pulseaudio, but not alsa devices

there's an easier way to make skype (i'm using 2.2.0.35) not use pulseaudio - there's no need to uninstall or disable pulse:

create an executable file
/usr/bin/skype-wrapper
with the following content:
PULSE_SERVER=127.0.0.1 /usr/bin/skype &

don't forget to also change the desktop file so that the new script will be called when choosing skype from the start menu:
edit file /usr/share/applications/skype.desktop
and change
Exec=skype
to
Exec=skype-wrapper

explanation:
PULSE_SERVER is a way to tell skype to use a pulse instance on a machine other than the local.
invalid values (e.g. empty string) make skype interrupt the startup and quit - so we give the local adress which is valid but obviously pulse runs at user level so it's not reachable via network, even not on the local machine.
skype tries to use pulse but cannot reach/connect to it and falls back to alsa.
the result on ubuntu natty is that pulse continues to work unmodified and skype can be configured to use whatever you want to



HOWEVER
the real problem - at least in my case - wasn't skype. the strange distortion came from somewhere below and was noticeable also in some other programs.
the real solution for my case was not to disable pulseaudio but to fix it: edit file /etc/pulse/default.pa
and change
load-module module-udev-detect
to
load-module module-udev-detect tsched=0

see http://pulseaudio.org/wiki/BrokenSoundDrivers

Last edited by thomas.horner; July 26th, 2011 at 03:11 AM..

måndag 27 augusti 2012

Android fixing R error in Android project in Eclipse

I've just spent half an hour trying to fathom how to get back my auto-generated R.java that magically disappeared at some point.

The usual ways of resolving issues such as clean build, restarting IDE, and wiping the screen clean with a damp cloth didn't work.

Googling around did reveal a lot of similar complaints and revived a stark deja vu feeling. The hilarious thing is that once the R guy is gone, a good chunk of your code goes red thus adding to the insult.

Rather than continuing the discovery of all the conceivable strains of the issue found in the wild, I decided to leverage the tried-and-true approach of staring at the code. Having done so for a while I spotted a few red guys under res folder. They were a leftover of my current redesign work that I was about to delete before things went awry. Sure enough, as soon as I hit Del on them the darn R thing automagically reappeared.

The moral of the story is there's just so much magic Google can do for us. Bad resources (e.g. layouts with errors) are not treated gracefully by Google Android Eclipse plugin and can deceive it into deleting R.java with no sound reason.
Posted by
Labels: android

semester på fårö

Längst ner...


www.sudersand.se/galleri/

Apache load balancing module

Apache loadbalancing module




http://wiki.magnolia-cms.com/display/WIKI/Guide+-+How+to+configure+an+apache+load+balancer

söndag 26 augusti 2012

JQuery in-place editor

Editing content in-place, must if ajax can be usued as desired in conjunction with play framework validation.


http://www.appelsiini.net/projects/jeditable

Auto incrementing id in POSTGRES


Auto incrementing id in POSTGRES

Yes, SERIAL is the equivalent function.
CREATE TABLE foo (
id SERIAL,
bar varchar);
INSERT INTO "foo" (bar) values ('blah');
INSERT INTO "foo" (bar) values ('blah');
SELECT * FROM foo;
1,blah2,blah


http://stackoverflow.com/questions/787722/postgresql-autoincrement

fredag 24 augusti 2012

Tomcat set memory in [$TOMCAT_HOME]/bin/setenv.sh

============================== setenv.sh ================

#! /bin/sh
# ==================================================================
# ______ __ _____
# /_ __/___ ____ ___ _________ _/ /_ /__ /
# / / / __ \/ __ `__ \/ ___/ __ `/ __/ / /
# / / / /_/ / / / / / / /__/ /_/ / /_ / /
#/_/ \____/_/ /_/ /_/\___/\__,_/\__/ /_/
# Multi-instance Apache Tomcat installation with a focus
# on best-practices as defined by Apache, SpringSource, and MuleSoft
# and enterprise use with large-scale deployments.
# Credits:
# Google -> Couldn't survive without it
# Stackoverflow.com -> Community support
# SpringSource -> Specifically best-practices and seminars (Expert Series)
# Based On:
# http://www.springsource.com/files/uploads/tomcat/tomcatx-performance-tuning.pdf
# http://www.springsource.com/files/u1/PerformanceTuningApacheTomcat-Part2.pdf
# http://www.springsource.com/files/uploads/tomcat/tomcatx-large-scale-deployments.pdf
# Created By: Terrance A. Snyder
# URL: http://www.terranceasnyder.com, http://shutupandcode.net
# Best Practice Documentation:
# http://terranceasnyder.com/2011/05/tomcat-best-practices/
# Looking for the latest version?
# github @ https://github.com/terrancesnyder
# ==================================================================
# discourage address map swapping by setting Xms and Xmx to the same value
# http://confluence.atlassian.com/display/DOC/Garbage+Collector+Performance+Issues
export CATALINA_OPTS="$CATALINA_OPTS -Xms64m"
export CATALINA_OPTS="$CATALINA_OPTS -Xmx512m"
# Increase maximum perm size for web base applications to 4x the default amount
# http://wiki.apache.org/tomcat/FAQ/Memoryhttp://wiki.apache.org/tomcat/FAQ/Memory
export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxPermSize=256m"
# Reset the default stack size for threads to a lower value (by 1/10th original)
# By default this can be anywhere between 512k -> 1024k depending on x32 or x64
# bit Java version.
# http://www.springsource.com/files/uploads/tomcat/tomcatx-large-scale-deployments.pdf
# http://www.oracle.com/technetwork/java/hotspotfaq-138619.html
export CATALINA_OPTS="$CATALINA_OPTS -Xss192k"
# Oracle Java as default, uses the serial garbage collector on the
# Full Tenured heap. The Young space is collected in parallel, but the
# Tenured is not. This means that at a time of load if a full collection
# event occurs, since the event is a 'stop-the-world' serial event then
# all application threads other than the garbage collector thread are
# taken off the CPU. This can have severe consequences if requests continue
# to accrue during these 'outage' periods. (specifically webservices, webapps)
# [Also enables adaptive sizing automatically]
export CATALINA_OPTS="$CATALINA_OPTS -XX:+UseParallelGC"
# This is interpreted as a hint to the garbage collector that pause times
# of <nnn> milliseconds or less are desired. The garbage collector will
# adjust the Java heap size and other garbage collection related parameters
# in an attempt to keep garbage collection pauses shorter than <nnn> milliseconds.
# http://java.sun.com/docs/hotspot/gc5.0/ergo5.html
export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxGCPauseMillis=1500"
# A hint to the virtual machine that it.s desirable that not more than:
# 1 / (1 + GCTimeRation) of the application execution time be spent in
# the garbage collector.
# http://themindstorms.wordpress.com/2009/01/21/advanced-jvm-tuning-for-low-pause/
export CATALINA_OPTS="$CATALINA_OPTS -XX:GCTimeRatio=9"
# The hotspot server JVM has specific code-path optimizations
# which yield an approximate 10% gain over the client version.
export CATALINA_OPTS="$CATALINA_OPTS -server"
# Disable remote (distributed) garbage collection by Java clients
# and remove ability for applications to call explicit GC collection
export CATALINA_OPTS="$CATALINA_OPTS -XX:+DisableExplicitGC"
# Check for application specific parameters at startup
if [ -r "$CATALINA_BASE/bin/appenv.sh" ]; then
  . "$CATALINA_BASE/bin/appenv.sh"
fi
echo "Using CATALINA_OPTS:"
for arg in $CATALINA_OPTS
do
echo ">> " $arg
done
echo ""
echo "Using JAVA_OPTS:"
for arg in $JAVA_OPTS
do
echo ">> " $arg
done
echo "_______________________________________________"
echo ""
 
=========================== END setenv.sh ==============================




https://gist.github.com/986029

SQL good practies

SQL good practies, from SO

Column order does matter so if (and only if) the column orders match you can for example:

insert into items_verselect * from items where item_id=2;

Or if they don't match you could for example:

insert into items_ver(item_id, item_group, name)
select * from items where item_id=2;

but relying on column order is a bug waiting to happen (it can change, as can the number of columns) - it also makes your SQL harder to read
There is no good 'shortcut' - you should explicitly list columns for both the table you are inserting into and the query you are using for the source data, eg:
insert into items_ver (item_id, name, item_group)
select item_id, name, item_group from items where item_id=2;

torsdag 16 augusti 2012

JQuery UI Dialog width issue in IE 7, solution ?!

JQuery UI Dialog width issue in IE 7, solution ?!

PROBLEM==================================================
I get a scroll bar on every dialog.  Looking at it, the content height is apparently calculated by the UI.  In FF, that is the size of the content, INSIDE the padding.  IE seems to calculate the size PLUS the padding, so there is always a scrollbar for the amount of the padding.

SOLUTION==================================================

I had this problem, and found that adding a call to height("auto") after creating the dialog seems to have done the trick for now. (Tested IE 7, Chrome, Firefox) E.g.




http://forum.jquery.com/topic/jquery-ui-dialog-size-scrollbar-issue-in-ie

ANOTHER SOLUTION==========================================

var tag = $("<div></div>");
//IE7 workaround
var w;
if (navigator.appVersion.indexOf("MSIE 7.") != -1)
    w = 400;
else
    w = "auto";

tag.html('My message').dialog({
    width: w,
    maxWidth: 600,
 
http://stackoverflow.com/a/9950298 
 

FlashPlayer issue in Ubuntu, probable FIX

FlashPlayer issue in Ubuntu, probable FIX

Try using gnash instead of Flashplayer. To install gnash sudo apt-get install gnash . I have used it for over a year and gnash seems to work better than flash.
If you feel better uninstalling flash then installing gnash you can do this by opening terminal


sudo apt-get purge flashplugin-nonfree flashplugin-installer gnash gnash-common mozilla-plugin-gnash swfdec-mozilla
sudo rm -f /usr/lib/firefox-addons/plugins/libflashplayer.so
sudo rm -f /usr/lib/mozilla/plugins/libflashplayer.so
sudo rm -f /usr/lib/mozilla/plugins/flashplugin-alternative.so
sudo rm -f /usr/lib/mozilla/plugins/npwrapper*flash*so
rm -f ~/.mozilla/plugins/*flash*so
sudo apt-get install gnash


http://askubuntu.com/questions/54044/choppy-flash-video-playback

söndag 22 juli 2012

fredag 20 juli 2012

Postgis in Play Framework

Possible solution for geometry column in play framework JPA

https://groups.google.com/forum/?fromgroups#!topic/play-framework/f-vp8JgJda0

 [...]
import com.vividsolutions.jts.geom.
Point;
[...]
@Column(name = "the_geom", columnDefinition = "GEOMETRY")
@Type(type = "org.hibernatespatial.GeometryUserType")
public Point theGeom;
[...]

onsdag 11 juli 2012

CSS Reset

referencing Eric Meyer, on resetting in css for fixing so and so browsers behaviour


http://meyerweb.com/eric/tools/css/reset/

Blue border around image fix

How to remove the blue border around an image, particurlarly concerning IE, do the following


a img{
    border: none;
}

also, where it came from, http://stackoverflow.com/a/3003704

söndag 1 juli 2012

Play Framework 2.0 lecture

From JFokus about Play Framework 2.0

http://www.jfokus.se/jfokus/video.jsp?v=3081

Styling links within links in divs

Just a quickie to horisontally align links in divs inside a li element

<!DOCTYPE html>
  <html>
  <head>
  <style type="text/css">
  li{
    list-style: none;
  }
  div.my-spaced-links{
    display: inline;
    margin-left: 10px;
    padding: 10px;
  }
  </style>
  </head>
  <body>
  <ul>
  <li><a href="#">Första</a></li>
  <li><span><div class="my-spaced-links"><a href="#">Två1</a></div><div
  class="my-spaced-links"><a href="#">Två2</a></div></span>
</li>
  </ul>
  </body>
  </html>

Wrap anchor tag around other tags

How to succesfully wrap an anchor tag around other tags, in HTML5
http://davidwalsh.name/html5-elements-links

Remove whitespace, ImageMagick

Remove whitespace from a picture in imagemagick

http://hilbertastronaut.blogspot.se/2008/08/imagemagick-crops-your-white-space.html

Show images - Flexslider

Flexslider - show of images on a page

http://www.woothemes.com/flexslider/

Test site in browsers

Testing site crossbrowser - online

http://browserstack.com

http://crossbrowsertesting.com/

Styling input-fields using CSS3

CSS3 style input field using gradients

http://www.webstuffshare.com/2010/04/stylize-input-element-using-css3/

Gradient - crossbrowser

CSS Gradient cross-browser from IE 5.5
http://www.puremango.co.uk/2010/04/css-gradient-background/