Thursday, 3 October 2013

Random data generator in java

Random data generator in java

i have to fill every property of a given object with a random value.
All properties are native java type (int, double, String, etc)
I canuse reflection
I can use Spring DirectFieldAccessor
I don't want to re-invent the square wheel so I prefer to ask.
For now I came up with this : Get all properties name with
Field field : myObject.getClass().getDeclaredFields()
Iterate over those field and get their class.
Then use a giant switch statement for each known native java type and
generate a random value.
What do you think?

Wednesday, 2 October 2013

Count and Joins

Count and Joins

Customer
CustomerID Name
4001 John Bob
4002 Joey Markle
4003 Johny Brown
4004 Jessie Black
Orders
OrderID Customer
50001 4001
50002 4002
50003 4001
50004 4003
50005 4001
50006 4003
50007 4001
I tried this join
Select c.Customer, COUNT(o.OrderID) as TotalOrders
from Customer c
inner join Orders o
on c.Customer = o.Customer
Group by c.Customer
But here is the result.
Customer TotalOrders
4001 4
4002 1
4003 2
The customer with no order is not included. How I will include all the
customer even they don't have orders?
Customer TotalOrders
4001 4
4002 1
4003 2
4004 0

ReadObject is returning null values

ReadObject is returning null values

I have the following class design. My engine attribute is coming as null
each time,even though I have read its value from readObject
public class Car implements Serializable {
private int regId;
transient Engine e;
private void writeObject(ObjectOutputStream oos) {
try {
oos.defaultWriteObject();
oos.writeInt(e.horsePower);
} catch (Exception e) {
e.printStackTrace();
}
}
private void readObject(ObjectInputStream oxos) {
try {
oxos.defaultReadObject();
Engine e = new Engine(oxos.readInt());
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
}
public class Engine {
int horsePower;
}

HTML/CSS Help w/ Validating! Unclosed Element

HTML/CSS Help w/ Validating! Unclosed Element

I am new to HTML and CSS and am trying to make it to CSS but when i use
the validaotr, it just says unclosed element!Ignore the pi
enter code here
<style>
h1{color:white;}
body{background-color:#C9C9DB;}
p{text-align:right;font-size:2em;}
p{color:#FFFFFF}
h2{color:white;font-size:1em;text-align:left;}
IMG.displayed {
display: block;
margin-left: auto;
margin-right: auto }
p1.italic {font-style:italic;}x
p1.a {list-style-type:circle;}
</style>
<p>MyTSC</p>
<IMG class="displayed" src="123.jpg" alt="Logo">
<hr width="50%" color="white"/>
<p style="font=size:2em;text-align:left;">My Fall Courses</p>
<h2>
<p1 class="a">
<li>
<p1 class="italic">COSC 4330 Computer Graphics</p1>
</br><li>
IMED 1416 Wed Design I
ITNW 2413 Networking Hardware

RGB to binary in android

RGB to binary in android

I would like to find an android code that will assist me convert an RGB
image to a binary image. Please assist. Also kindly assist me to find out
how I can modify a code as this below to integrate it for an Adroid mobile
application.
package ij.process;
import java.awt.*;
/** This class processes binary images. */
public class BinaryProcessor extends ByteProcessor {
private ByteProcessor parent;
/** Creates a BinaryProcessor from a ByteProcessor. The ByteProcessor
must contain a binary image (pixels values are either 0 or 255).
Backgound is assumed to be white. */
public BinaryProcessor(ByteProcessor ip) {
super(ip.getWidth(), ip.getHeight(), (byte[])ip.getPixels(),
ip.getColorModel());
setRoi(ip.getRoi());
parent = ip;
}
static final int OUTLINE=0;
void process(int type, int count) {
int p1, p2, p3, p4, p5, p6, p7, p8, p9;
int inc = roiHeight/25;
if (inc<1) inc = 1;
int bgColor = 255;
if (parent.isInvertedLut())
bgColor = 0;
byte[] pixels2 = (byte[])parent.getPixelsCopy();
int offset, v=0, sum;
int rowOffset = width;
for (int y=yMin; y<=yMax; y++) {
offset = xMin + y * width;
p2 = pixels2[offset-rowOffset-1]&0xff;
p3 = pixels2[offset-rowOffset]&0xff;
p5 = pixels2[offset-1]&0xff;
p6 = pixels2[offset]&0xff;
p8 = pixels2[offset+rowOffset-1]&0xff;
p9 = pixels2[offset+rowOffset]&0xff;
for (int x=xMin; x<=xMax; x++) {
p1 = p2; p2 = p3;
p3 = pixels2[offset-rowOffset+1]&0xff;
p4 = p5; p5 = p6;
p6 = pixels2[offset+1]&0xff;
p7 = p8; p8 = p9;
p9 = pixels2[offset+rowOffset+1]&0xff;
switch (type) {
case OUTLINE:
v = p5;
if (v!=bgColor) {
if (!(p1==bgColor || p2==bgColor ||
p3==bgColor || p4==bgColor
|| p6==bgColor || p7==bgColor ||
p8==bgColor || p9==bgColor))
v = bgColor;
}
break;
}
pixels[offset++] = (byte)v;
}
if (y%inc==0)
parent.showProgress((double)(y-roiY)/roiHeight);
}
parent.hideProgress();
}
// 2012/09/16: 3,0 1->0
// 2012/09/16: 24,0 2->0
private static int[] table =
//0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1
{0,0,0,0,0,0,1,3,0,0,3,1,1,0,1,3,0,0,0,0,0,0,0,0,0,0,2,0,3,0,3,3,
0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,3,0,2,2,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2,0,0,0,0,0,0,0,2,0,0,0,2,0,0,0,3,0,0,0,0,0,0,0,3,0,0,0,3,0,2,0,
0,0,3,1,0,0,1,3,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
3,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2,3,1,3,0,0,1,3,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2,3,0,1,0,0,0,1,0,0,0,0,0,0,0,0,3,3,0,1,0,0,0,0,2,2,0,0,2,0,0,0};
private static int[] table2 =
//0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1
{0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,2,2,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,2,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
/** Uses a lookup table to repeatably removes pixels from the
edges of objects in a binary image, reducing them to single
pixel wide skeletons. There is an entry in the table for each
of the 256 possible 3x3 neighborhood configurations. An entry
of '1' means delete pixel on first pass, '2' means delete pixel on
second pass, and '3' means delete on either pass. Pixels are
removed from the right and bottom edges of objects on the first
pass and from the left and top edges on the second pass. A
graphical representation of the 256 neighborhoods indexed by
the table is available at
"http://imagej.nih.gov/ij/images/skeletonize-table.gif".
*/
public void skeletonize() {
int pass = 0;
int pixelsRemoved;
resetRoi();
setColor(Color.white);
moveTo(0,0); lineTo(0,height-1);
moveTo(0,0); lineTo(width-1,0);
moveTo(width-1,0); lineTo(width-1,height-1);
moveTo(0,height-1); lineTo(width/*-1*/,height-1);
ij.ImageStack movie=null;
boolean debug = ij.IJ.debugMode;
if (debug) movie = new ij.ImageStack(width, height);
if (debug) movie.addSlice("-", duplicate());
do {
snapshot();
pixelsRemoved = thin(pass++, table);
if (debug) movie.addSlice(""+(pass-1), duplicate());
snapshot();
pixelsRemoved += thin(pass++, table);
if (debug) movie.addSlice(""+(pass-1), duplicate());
} while (pixelsRemoved>0);
do { // use a second table to remove "stuck" pixels
snapshot();
pixelsRemoved = thin(pass++, table2);
if (debug) movie.addSlice("2-"+(pass-1), duplicate());
snapshot();
pixelsRemoved += thin(pass++, table2);
if (debug) movie.addSlice("2-"+(pass-1), duplicate());
} while (pixelsRemoved>0);
if (debug) new ij.ImagePlus("Skel Movie", movie).show();
}
int thin(int pass, int[] table) {
int p1, p2, p3, p4, p5, p6, p7, p8, p9;
int bgColor = -1; //255
if (parent.isInvertedLut())
bgColor = 0;
byte[] pixels2 = (byte[])getPixelsCopy();
int v, index, code;
int offset, rowOffset = width;
int pixelsRemoved = 0;
int count = 100;
for (int y=yMin; y<=yMax; y++) {
offset = xMin + y * width;
for (int x=xMin; x<=xMax; x++) {
p5 = pixels2[offset];
v = p5;
if (v!=bgColor) {
p1 = pixels2[offset-rowOffset-1];
p2 = pixels2[offset-rowOffset];
p3 = pixels2[offset-rowOffset+1];
p4 = pixels2[offset-1];
p6 = pixels2[offset+1];
p7 = pixels2[offset+rowOffset-1];
p8 = pixels2[offset+rowOffset];
p9 = pixels2[offset+rowOffset+1];
index = 0;
if (p1!=bgColor) index |= 1;
if (p2!=bgColor) index |= 2;
if (p3!=bgColor) index |= 4;
if (p6!=bgColor) index |= 8;
if (p9!=bgColor) index |= 16;
if (p8!=bgColor) index |= 32;
if (p7!=bgColor) index |= 64;
if (p4!=bgColor) index |= 128;
code = table[index];
if ((pass&1)==1) { //odd pass
if (code==2||code==3) {
v = bgColor;
pixelsRemoved++;
}
} else { //even pass
if (code==1||code==3) {
v = bgColor;
pixelsRemoved++;
}
}
}
pixels[offset++] = (byte)v;
}
}
return pixelsRemoved;
}
public void outline() {
process(OUTLINE, 0);
}
}

Tuesday, 1 October 2013

Pick 4 random elements from an NSArray of count 6

Pick 4 random elements from an NSArray of count 6

I am new to Objective C. I am coding the game Mastermind where the
computer chooses 4 random colors out of 6 and the user tries to guess the
4 colors in 6 tries.
I have an NSArray to represent all the six possible colors here:
NSArray * allColors = [[NSArray alloc] initWithObjects:@"r", @"g",
@"b", @"y", @"p", @"o", nil];
//Computer choose 4 random colors:
NSArray * computersSelection = [[NSArray alloc] init];
I need to write code to choose 4 UNIQUE random colors from the array. Is
there a smart way to do this?
I can create four int variables and use a while loop to generate four
random numbers and then pull the objects from the NSArray based on the
four random integer values and put them in the computerSelection array but
I am wondering if there's any simpler way of doing things?
Thanks

Menus in Batch File

Menus in Batch File

I don't usually create batch files as I just type what I need into the run
box or the command prompt but I'm trying to make one just to let me access
basic utilities in windows and check up on things (I really don't need it
but I think my dad would find it helpful). I am familiar (but new) with
python so if using python for these things is a better option I can do
that, however I thought batch was the best way of doing something as
simple as this. The problem is with my menu. I think because of my menu ,
it is cycling through all of the commands before doing the command
selected. Any help with this will be fully appreciated, the batch script
is in a code box below.
echo off
:menu
echo This is a simple cleanup and repair utility. Please select an option:
echo 1 - Check the hard disk c:\ for errors and inconsistancies.
echo 2 - Renew the IP address
echo 3 - View IP Address information
echo 4 - Check internet connection by pinging http://www.google.co.uk/
echo 5 - Start disk cleanup utility
echo 6 - ping 192.168.0.1
echo 7 - ping 192.168.1.1
echo 8 - Open notepad
choice /n /c:12345678 /M "Choose an option (1-8) "
IF ERRORLEVEL == 1 GOTO CHKDSK
IF ERRORLEVEL == 2 GOTO RENEW
IF ERRORLEVEL == 3 GOTO DISPLAYIP
IF ERRORLEVEL == 4 GOTO PINGGOOGLE
IF ERRORLEVEL == 5 GOTO CLEANMGR
IF ERRORLEVEL == 6 GOTO PING0
IF ERRORLEVEL == 7 GOTO PING1
IF ERRORLEVEL == 8 GOTO STARTNOTE
:CHKDSK
CHKDSK C:
PAUSE
goto menu
:RENEW
IPCONFIG /RENEW
PAUSE
goto menu
:DISPLAYIP
IPCONFIG /ALL
PAUSE
goto menu
:PINGGOOGLE
PING HTTP://WWW.GOOGLE.CO.UK/
PAUSE
goto menu
:CLEANMGR
CLEANMGR
PAUSE
goto menu
:PING0
PING 192.168.0.1
PAUSE
goto menu
:PING1
PING 192.168.1.1
PAUSE
goto menu
:STARTNOTE
START NOTEPAD
PAUSE
goto menu

How can I tell if a certain IIS configuration key has been imported?

How can I tell if a certain IIS configuration key has been imported?

I'm building some configuration management scripts that need to be
idempotent. I need to check if the IIS keys for the web farm have been
imported on a server and if not import them.
I've got the commands to do the import, but I can't seem to find a
consistent way to check that a particular set of keys has been imported.

Setting mysqld to run at startup in MacOS

Setting mysqld to run at startup in MacOS

I using MacOS Machine for which every time I want to you mysql I have to
first start it using the following command
mysqld 2> /dev/null &
all seem great and thing work pleasantly after I run it but sure there is
way to avoid this as well has brought me over here I'm trying to find a
way to add it as script and run it in startup but I not sure how to
achieve
Another thing there is MySQL Server Status Application which look
something like this

Although I see something to display the status correctly but it Stop Mysql
server / Start Mysql server button did not work when try to use them
neither the check that states
Automatically Start MySql Server on Startup
Has any one got an idea how to fix this
Thanks

Monday, 30 September 2013

Fortigate bandwidth monitoring

Fortigate bandwidth monitoring

I have a Fortigate 200B with Forti OS 5.0.
How can I watch the total bandwidth being used by my unit both incoming
and outgoing?
Thanks

What seems wrong with this bash script?

What seems wrong with this bash script?

I found an initscript that for some reason insists on starting the
specified application as the root user. I can't wrap my head around why it
is doing this, any hints? The script runs on Redhat Enterprise Linux 5.9.
#!/bin/bash
#
# Start/Stop apfe.
#
# chkconfig: - 62 38
# description: apfe
# Start script for an apfe process.
# Apfe does not normally run as root, so we change user
# and call the real script in $USERDIR.
STARTUSER=apfe
USERDIR=/app/apfe/apps/apfeutils/bin
PROGNAME=apfe
su - $STARTUSER -c "$USERDIR/$PROGNAME $*"

How can I check if website is already opened in a webbrowser?

How can I check if website is already opened in a webbrowser?

I'm doing this:
Process.Start("http://www.google.com");
After the default webbrowser is opened the website i want to check somehow
that the website is opened by the webbrowser and close the specicif tab
with this website.
To make a button click event that will check that if the website is
already opened then close it.

What does y scaling mean in svm-scale

What does y scaling mean in svm-scale

Does it mean to scale the value of the target(class),which is the first
column of every instance?
Regards,
amber@cent64 libsvm-3.17]$ svm-scale Usage: svm-scale [options]
data_filename options: -l lower : x scaling lower limit (default -1) -u
upper : x scaling upper limit (default +1) -y y_lower y_upper : y scaling
limits (default: no y scaling) -s save_filename : save scaling parameters
to save_filename -r restore_filename : restore scaling parameters from
restore_filename

Sunday, 29 September 2013

responsive navigation links wont react to class

responsive navigation links wont react to class

I am working on a website simplemedia.dk
i have a responsive menu that works, but when i am trying to define the
in responsive mode the browsers does not recognize the style ..
in responsive mode i get a class called "responsified" and i tried adding
the class .responsified in front of my navigation style but it doesnt
react to it.
.responsive-menus .responsive-menus-0-0 .absolute .responsified
.responsive-toggled #navigation ul.menu{display:block; float:left; }
.responsive-menus .responsive-menus-0-0 .absolute .responsified
.responsive-toggled #navigation ul.menu li{display:block; float:left;}
In normal mode i want it to display table-cell which it does, but in
responsive i want it to show block.

How do I make a Time Conversion program on java?

How do I make a Time Conversion program on java?

![Its a Project im working on at school][1]
How do i make it go from Minutes-Hours? 135mins-2:15hours I just started
programming help me please!!

How remap CTRL-key to Alt right (tried everything)

How remap CTRL-key to Alt right (tried everything)

My specs: Xubuntu 13.04, which uses (what I believe) Xorf as X Window
Manager.
Intro: some weeks ago I switched to Linux (Xubuntu). I configured
everything to work only with my keyboard without ever using the mouse.
Works like a charm. But recent, I wanted to remap the [ctrl] to
[capslock]. ~/.xmodmap seems not working. I found the answer here:
**/usr/bin/setxkbmap -option "ctrl:nocaps"** does the trick. I putted the
command as autostart.
Works fine until I got RSI-like issues with my left pink the last days. My
pink tingles weird and causes much pain at the end of day (even I'm using
ergonomic keyboard!). I tried everything to avoid this, like the correct
posture and taking breaks, weight lifting. Nothing helps. Then I looked
closer to my keyboard flow. I noticed I use the spacebar most, on second
the [Capslock]-button that behaves like [ctrl]. But I have no pain in my
thumbs. I dont use the right [Alt], so it would be better if I remap the
[ctrl]-key to [alt-key], so I can activate [ctrl] with my thumb.
What have I done?
Tried this: /usr/bin/setxkbmap -option "ctrl:alt_R" Not working.
Tried this: /usr/bin/setxkbmap -option "ctrl:Meta_R" Not working.
Tried the .xmodmap configuration. I start xev, pressed the right [alt] key
and it gives me keycode 108. [ctrl] gives me 37. So i create up ~/.Xmodmap
and map: keycode 108 = Control_L and reboot. Not working.
I've searched through the forums a lot, but have not found a solution. Any
suggestions how manage the right Alt+key behave as [ctrl]-key?
Thanks in advance for your appreciated help.
================== Edit: found the answer! Without the open source spirit,
I would never able to find my way here. And everyone benefits too!
The answer is..... bumbumbrrrrr...
setxkbmap -option ctrl:ralt_rctrl :D

Text alignment issue in a quote banner

Text alignment issue in a quote banner

as you can see on this JSFiddle and on picture below, I'm struggling to
get the signature placed as I want in my banner (I want it at the bottom
right of the blue banner without interfering with the quote text
alignment). The issue that I have is that with my current code the second
line of the text is not perfectly aligned horizontally to the middle of
the block (there's more space to the right than to the left). How could I
fix this and have full control on the signature position? Many thanks,

HTML:
<div class="block blueback center">
<h2 class="white">dfjdsjdklj dsjfdslfjldsjf ldsjfdlsjflkdsfjdlskjf
dljfdslfjkldsj dljfsdljfdklsj lkdjflkdsjdlks dsfjsdlkfjkls
dsjflkdsfjdkl</h2><p class="signature">John Dupont</p>
</div>
CSS:
.block {
display: block;
margin-right: auto;
margin-left: auto;
clear: both;
box-sizing: border-box;
padding-left: 20px;
padding-right: 20px;
width: 100%;
overflow: hidden;
}
h2 {
color: #2165CB;
font-weight: 600;
font-size: 18px;
}
.white { color: #fff;
letter-spacing: 1px;
font-style: italic;
font-weight: 300;
display: inline;
}
.center {
vertical-align: middle;
text-align: center;
padding-bottom: 5px;
padding-top: 5px;
}
.signature {
display: inline;
margin-top: 20px;
margin-bottom: 0px;
padding-top: 0px;
font-size: 12px;
color: #fff;
float: right;
font-weight: 700;
}
.blueback {
background: #0064C4;
}

Saturday, 28 September 2013

In PHP would this be deemed correct?

In PHP would this be deemed correct?

I already wrote a post about an issue I had before about this but I had
that issue taken care of. Like my last post I have a form, text-box and a
button. I have everything done with this including Printing the original
word, Printing the number of characters in the word, Printing the word in
all caps and Printing the word in reverse order. My only issue I'm having
is trying to get whatever text I enter and then click the button to output
to Print the first letter of the word and Print the last letter of the
word. I've been doing a lot of looking around of PHP.net and I found that
substr is used to return a part of a string that I could use. The only
issue is when I write the code for it and try to execute my program it
errors out on that specific line. I'm not looking for the answer but could
someone just take a look and see what I'm doing wrong because I understand
everything completely but this is the only thing I'm hung up on.
$first = substr($_POST['entertext']);
echo "The first letter of the word is " . $first. "<br />\n";
$last = substr($_POST['entertext']);
echo "The first letter of the word is " . $last. "<br />\n";

Jersey framework override contoller methods or REST request filtering

Jersey framework override contoller methods or REST request filtering

I need to implement a controller for processing requests whith filter use
Jersey framework. For example:
.../myservice/book - display a list of all books.
.../myservice/book?chapter=1,5 - display 1 and 5 books chapters.
.../myservice/book?page=10,50 - display 10 and 50 books pages.
.../myservice/book?chapter=1,5&page=10,50 - display 1 and 5 books chapters
and only 10 and 50 book pages.
I can't use .../myservice/book/chapter/1,5/page/10,50, because possible
situation: .../myservice/book/7 - display book 7 and filters described
above can be applied here. Is it possible to implement it in this way:
public class TestController {
@Path("/book")
@GET
public Object getBook() {
// return a list of all books
}
public Object getBook(@QueryParam("chapter") String chapter) {
// return books chapters
}
public Object getBook(@QueryParam("chapter") String page) {
// return books pages
}
public Object getBook(@QueryParam("chapter") String page,
@QueryParam("page") String page) {
// return books chapters and pages
}
}
Or to add all kinds of filters in one method and verify the presence of a
large number of conditions?

How to make Intro Section visible on mobile device (Wordpress Responsive Theme)

How to make Intro Section visible on mobile device (Wordpress Responsive
Theme)

I need some help to custom my site. You can take a look to my site first
http://next.coupleshops.com
You can see the first intro section, "We proudly present, ...." (it's a
Image file)
The problem is when I open it from mobile device like iphone or samsung
galaxy, the intro section won't show up. it skipped to the "News" section.
Anyone know how to make it visible and responsive on mobile device?