Thursday, 3 October 2013

What would be the best approach to implement a multi-select combo in SWT/JFace?

What would be the best approach to implement a multi-select combo in
SWT/JFace?

I need to implement a multi-select combobox using SWT/JFace, What would be
the best approach?

Wednesday, 2 October 2013

Getting the height of the image to set modal window size

Getting the height of the image to set modal window size

I am creating a photo gallery with thumbnails and loads the resized image
into the modal window.
The problem is I want to get the height and width of the image to set the
height of the modal window, however the height is not being set on the
modal window or my container for my image.
The src of the image is not in my markup originally but I add it to the
markup by appending it on the fly.
Original Thumbnail Image
<img src="\images\picture1.jpg" height="150" width="150" id="thumbnail">
Jquery code:
var tImageID = $(this).find('img').attr( 'id', 'thumbnail' );
var fullURL = $(tImageID).attr('src');
var dFigure = $('#dialog-media figure .media');
// fullSrcURL = "\images\picture_resized.jpg"
var fullSrcURL = fullURL.replace(".jpg", "_resized.jpg");
// Add html to the div tag
$(dFigure).append('<img id="resized-pic" src="' + fullSrcURL + '"
alt="' + $(tImage).attr('alt') + '" />');
var objHeight = $("#resized-pic").height();
var objWidth = $("#resized-pic").width();
// Perform some other code here
// Some more logic
//Set the positioning of the modal window with theses CSS properties
$('.ui-dialog').css('left', '0');
$('.ui-dialog').css('right', '0');
$('.ui-dialog').css('margin', '0 auto');
$('.ui-dialog').css('width', objWidth);
$('.ui-dialog').css('height', ObjHeight);
$('.ui-dialog').css('top', '5%');
The picture loads up, but the objWidth and objHeight show up as zero when
looking at firebug.
I refresh my page, click on the same thumbail and the picture loads up
with the image within the modal and the height of the modal is set
properly.
Is it because the picture hasn't completely loaded and that is why it is
zero? Or is it because it is cached?
Thanks
Cheers

Detect presence of a specific String in Javascript String

Detect presence of a specific String in Javascript String

How can i do to search if a Javascript String contains the following
pattern :
"@someting.temp"
I would like to know if the String contains @ character and then someting
and then ".temp" string.
Thanks

Receive an EnumSet from a spring form checkbox element?

Receive an EnumSet from a spring form checkbox element?

I've seen a few related questions on this topic but none that seem to
exactly match what I'm after.
I have a form where I'd like the user to be able to select a number of
items from a checkbox list (backed by an enum), and to receive that as a
Set. I have the following (using days as an example)
My enum:
public enum Day {
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY,
SUNDAY
}
Sending the enum values to the page in the controller to be displayed as
the options:
model.addAttribute("allDays", Day.values());
Writing the options as checkboxes and mapping to correct form field:
<form:form method="get" modelAttribute="filterForm" commandName="filterForm">
<c:forEach items="${allDays}" var="item">
<form:checkbox path="days" value="${item.ordinal()}"
label="${item.name()}"/>
</c:forEach>
</form:form>
The form object backing the form:
public class FilterForm {
private EnumSet<Day> days;
public EnumSet<Day> getDays() {
return days;
}
public void setDays(EnumSet<Day> days) {
this.days = days;
}
}
This works as far as showing the options correctly, but when I try to
submit, I get an error:
org.springframework.validation.BindException:
org.springframework.validation.BeanPropertyBindingResult: 1 errors Field
error in object 'filterForm' on field 'days': rejected value [0,1]; codes
[typeMismatch.filterForm.days,typeMismatch.days,typeMismatch.java.util.EnumSet,typeMismatch];
arguments
[org.springframework.context.support.DefaultMessageSourceResolvable: codes
[filterForm.days,days]; arguments []; default message [days]]; default
message [Failed to convert property value of type 'java.lang.String[]' to
required type 'java.util.EnumSet' for property 'days'; nested exception is
org.springframework.core.convert.ConversionFailedException: Failed to
convert from type java.lang.String[] to type java.util.EnumSet for value
'{0, 1}'; nested exception is java.lang.IllegalArgumentException: Could
not instantiate Collection type: java.util.EnumSet]
org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:111)
org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:75)
org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:156)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:117)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
Any idea what the problem is or if there is a better way to achieve this?
Thanks

Tuesday, 1 October 2013

What is the best way to deserialize the Byte Array in C++ which is in Big Endiaan format?

What is the best way to deserialize the Byte Array in C++ which is in Big
Endiaan format?

I am writing Byte Array value into a file using Java with Big Endian Byte
Order format.. Now I need to read that file from C++ program...
That Byte Array which I am writing into a file is made up of three Byte
Arrays as described below-
short employeeId = 32767;
long lastModifiedDate = "1379811105109L";
byte[] attributeValue = os.toByteArray();
I am writing employeeId , lastModifiedDate and attributeValue together
into a single Byte Array and that resulting Byte Array I am writing into a
file and then I will be having my C++ program which will retrieve that
Byte Array data from file and then deserialize it to extract employeeId ,
lastModifiedDate and attributeValue from it.
Below is my Java code which is writing Byte Array value into a file with
Big Endian format and it is working fine...
public class ByteBufferTest {
public static void main(String[] args) {
String text = "Byte Array Test For Big Endian";
byte[] attributeValue = text.getBytes();
long lastModifiedDate = 1289811105109L;
short employeeId = 32767;
int size = 2 + 8 + 4 + attributeValue.length; // short is 2 bytes,
long 8 and int 4
ByteBuffer bbuf = ByteBuffer.allocate(size);
bbuf.order(ByteOrder.BIG_ENDIAN);
bbuf.putShort(employeeId);
bbuf.putLong(lastModifiedDate);
bbuf.putInt(attributeValue.length);
bbuf.put(attributeValue);
bbuf.rewind();
// best approach is copy the internal buffer
byte[] bytesToStore = new byte[size];
bbuf.get(bytesToStore);
writeFile(bytesToStore);
}
/**
* Write the file in Java
* @param byteArray
*/
public static void writeFile(byte[] byteArray) {
try{
File file = new File("bytebuffertest");
FileOutputStream output = new FileOutputStream(file);
IOUtils.write(byteArray, output);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Now I need to retrieve Byte Array from that same file using the below C++
program and deserialize it to extract employeeId , lastModifiedDate and
attributeValue from it. I am not sure what is the best way on the C++
side. Below is the code I have got so far on C++ side-
int main() {
string line;
std::ifstream myfile("bytebuffertest", std::ios::binary);
if (myfile.is_open()) {
uint16_t employeeId;
uint64_t lastModifiedDate;
uint32_t attributeLength;
char buffer[8]; // sized for the biggest read we want to do
// read two bytes (will be in the wrong order)
myfile.read(buffer, 2);
// swap the bytes
std::swap(buffer[0], buffer[1]);
// only now convert bytes to an integer
employeeId = *reinterpret_cast<uint16_t*>(buffer);
cout<< employeeId <<endl;
// read eight bytes (will be in the wrong order)
myfile.read(buffer, 8);
// swap the bytes
std::swap(buffer[0], buffer[7]);
std::swap(buffer[1], buffer[6]);
std::swap(buffer[2], buffer[5]);
std::swap(buffer[3], buffer[4]);
// only now convert bytes to an integer
lastModifiedDate = *reinterpret_cast<uint64_t*>(buffer);
cout<< lastModifiedDate <<endl;
// read 4 bytes (will be in the wrong order)
myfile.read(buffer, 4);
// swap the bytes
std::swap(buffer[0], buffer[3]);
std::swap(buffer[1], buffer[2]);
// only now convert bytes to an integer
attributeLength = *reinterpret_cast<uint32_t*>(buffer);
cout<< attributeLength <<endl;
myfile.read(buffer, attributeLength);
// now I am not sure how should I get the actual attribute value
here?
//close the stream:
myfile.close();
}
else
cout << "Unable to open file";
return 0;
}
Can anybody take a look on C++ code and see what I can do to improve it as
I don't think so it is looking much efficient? Any better way to
deserialize the Byte Array and extract relevant information on the C++
side?
Thanks for the help..

Uncaught SyntaxError: Unexpected identifier Readability.js:108

Uncaught SyntaxError: Unexpected identifier Readability.js:108

I want to investigate the functionality of reader mode in Firefox for
Android. To do that I took Readability.js from Firefox sources and created
a simple HTML file:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<script src="Readability.js"></script>
</body> </html>
If I load the above page in Chrome and open JavaScript Console I see
Uncaught SyntaxError: Unexpected identifier Readability.js:108
If I do the same in Firefox, the result is similar:
SyntaxError: missing ; before statement @ file:///XXX/Readability.js:108
Why does Readability.js work in Firefox for Android and does not when used
as shown above in desktop browsers?

nginx - show different page when ip address is given instead of domain name

nginx - show different page when ip address is given instead of domain name

I have installed on my vps nginx with ISPConfig3. I created a domain
mydomain.com through ispconfig and everything works just fine except two
things.
When i go to the ip address of my vps, my website is shown. I want a
different page ex. /var/www/index.html to be shown
I want to redirect from www.mydomain.com to mydomain.com.
Here is the virtual hosts in sites-enabled:
000-apps.vhost
server {
listen 8081;
server_name _;
root /var/www/apps;
client_max_body_size 20M;
location / {
index index.php index.html;
}
# serve static files directly
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt)$ {
access_log off;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param HTTPS $https;
# PHP only, required if PHP was built with
--enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
fastcgi_pass unix:/var/lib/php5-fpm/apps.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
#fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 4k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
location ~ /\. {
deny all;
}
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD
$request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH
$content_length;
fastcgi_param SCRIPT_FILENAME
$request_filename;
fastcgi_param SCRIPT_NAME
$fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT
$document_root;
fastcgi_param SERVER_PROTOCOL
$server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE
nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param HTTPS $https;
# PHP only, required if PHP was built with
--enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
# To access phpMyAdmin, the default user (like
www-data on Debian/Ubuntu) must be used
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 4k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_read_timeout 240;
}
location ~*
^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$
{
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
location /squirrelmail {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/squirrelmail/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD
$request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH
$content_length;
fastcgi_param SCRIPT_FILENAME
$request_filename;
fastcgi_param SCRIPT_NAME
$fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT
$document_root;
fastcgi_param SERVER_PROTOCOL
$server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE
nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param HTTPS $https;
# PHP only, required if PHP was built with
--enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
# To access SquirrelMail, the default user (like
www-data on Debian/Ubuntu) must be used
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 4k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
location ~*
^/squirrelmail/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$
{
root /usr/share/;
}
}
location /webmail {
rewrite ^/* /squirrelmail last;
}
location /cgi-bin/mailman {
root /usr/lib/;
fastcgi_split_path_info (^/cgi-bin/mailman/[^/]*)(.*)$;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param HTTPS $https;
# PHP only, required if PHP was built with
--enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED
$document_root$fastcgi_path_info;
fastcgi_intercept_errors on;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}
location /images/mailman {
alias /usr/share/images/mailman;
}
location /pipermail {
alias /var/lib/mailman/archives/public;
autoindex on;
}
}
000-ispconfig.vhost
server {
listen 8080;
ssl on;
ssl_certificate /usr/local/ispconfig/interface/ssl/ispserver.crt;
ssl_certificate_key /usr/local/ispconfig/interface/ssl/ispserver.key;
# redirect to https if accessed with http
error_page 497 https://$host:8080$request_uri;
server_name _;
root /usr/local/ispconfig/interface/web/;
client_max_body_size 20M;
location / {
index index.php index.html;
}
# serve static files directly
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt)$ {
access_log off;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/lib/php5-fpm/ispconfig.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
#fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 4k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
location ~ /\. {
deny all;
}
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/lib/php5-fpm/ispconfig.sock;
fastcgi_param HTTPS on;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
location ~*
^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$
{
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
location /squirrelmail {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/squirrelmail/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/lib/php5-fpm/ispconfig.sock;
fastcgi_param HTTPS on;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
location ~*
^/squirrelmail/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$
{
root /usr/share/;
}
}
location /webmail {
rewrite ^/* /squirrelmail last;
}
}
100-mydomain.com.vhost
server {
listen *:80;
server_name mydomain.com www.mydomain.com;
root /var/www/mydomain.com/web;
index index.html index.htm index.php index.cgi index.pl index.xhtml;
error_log /var/log/ispconfig/httpd/mydomain.com/error.log;
access_log /var/log/ispconfig/httpd/mydomain.com/access.log combined;
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location /stats {
index index.html index.php;
auth_basic "Members Only";
auth_basic_user_file
/var/www/clients/client1/web1/web/stats/.htpasswd_stats;
}
location ^~ /awstats-icon {
alias /usr/share/awstats/icon;
}
location ~ \.php$ {
try_files /b4c43b69af764469f45973ffea6ff69d.htm @php;
}
location @php {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9010;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
}
Edit: So i want when i type the ip of the vps ex. 5.55.33.7 to show a
certain page and not the website that is hosted in this ip.