Conditional operator successfully compiled in windows but gives error in
Linux
Please help me reason out for the error I am getting with this statement,
in Linux environment.
p_pAphErrorMessage->getSvc()?l_AphUpdateMessage->setSvc(p_pAphErrorMessage->getSvc()):0;
p_pAphErrorMessage->getObj()?l_AphUpdateMessage->setObj(p_pAphErrorMessage->getObj()):0;
This code is successfully compiled in windows but its giving error in
Linux enviroment.
src/aph.cpp:7320: error:
âl_AphUpdateMessage->AphMessage::setSvc(((AphUpdateMessage*)p_pAphErrorMessage)->AphUpdateMessage::<anonymous>.AphFidValuesMessage::<anonymous>.AphMessage::getSvc())â
has type âvoidâ and is not a throw-expression
src/aph.cpp:7321: error:
âl_AphUpdateMessage->AphMessage::setObj(((AphUpdateMessage*)p_pAphErrorMessage)->AphUpdateMessage::<anonymous>.AphFidValuesMessage::<anonymous>.AphMessage::getObj())â
has type âvoidâ and is not a throw-expression
I investigated this a bit and suspect returning 0; could be the reason for
it. Can we use conditional operator in such a way to use it just for if
not for else, eg,
c= a?a:/*DO NOTHING*/;
But, this way I am not getting any success in compilation. Any other
recommended way to achieve it.
Thursday, 3 October 2013
Wednesday, 2 October 2013
Switching workspaces with dual monitors
Switching workspaces with dual monitors
I'm working on Ubuntu 13.04 and have a second monitor connected with a
VGA. I currently have the second monitor as an extended screen. I was
wondering if there was a way that I could set it up so I could put a
window on my second monitor, switch workspaces on my main display and the
second monitor display wouldn't change?
I think it was a thing in the past, but I haven't found a solution. I just
want my second monitor to be consistent while my main workspace remains
dynamic.
I'm working on Ubuntu 13.04 and have a second monitor connected with a
VGA. I currently have the second monitor as an extended screen. I was
wondering if there was a way that I could set it up so I could put a
window on my second monitor, switch workspaces on my main display and the
second monitor display wouldn't change?
I think it was a thing in the past, but I haven't found a solution. I just
want my second monitor to be consistent while my main workspace remains
dynamic.
Excel VBA: How to obtain a reference to a Shape from the ChartObject
Excel VBA: How to obtain a reference to a Shape from the ChartObject
I am trying to obtain a reference to a Shape in a Worksheet, corresponding
to a ChartObject. I found no certain way of doing this. The only
approximation, by trial-and-error and simply tested in a few cases, is
assuming that the ZOrder of a ChartObject is the same as the
ZOrderPosition of the corresponding Shape:
Function chobj2shape(ByRef cho As ChartObject) As Shape
' It appears that the ZOrder of a ChartObject is the same as the
ZOrderPosition of the corresponding Shape
Dim zo As Long
Dim ws As Worksheet
Dim shc As Shapes
Dim sh As Shape
zo = cho.ZOrder
Set ws = cho.Parent
Set shc = ws.Shapes
Set sh = shc.Item(zo)
Set chobj2shape = sh
'Set sh = Nothing
End Function
(a slight excess of defined variables is used for debugging purposes).
Is there any more certain way of doing this?
I am trying to obtain a reference to a Shape in a Worksheet, corresponding
to a ChartObject. I found no certain way of doing this. The only
approximation, by trial-and-error and simply tested in a few cases, is
assuming that the ZOrder of a ChartObject is the same as the
ZOrderPosition of the corresponding Shape:
Function chobj2shape(ByRef cho As ChartObject) As Shape
' It appears that the ZOrder of a ChartObject is the same as the
ZOrderPosition of the corresponding Shape
Dim zo As Long
Dim ws As Worksheet
Dim shc As Shapes
Dim sh As Shape
zo = cho.ZOrder
Set ws = cho.Parent
Set shc = ws.Shapes
Set sh = shc.Item(zo)
Set chobj2shape = sh
'Set sh = Nothing
End Function
(a slight excess of defined variables is used for debugging purposes).
Is there any more certain way of doing this?
fluidsynth noteon doesn't produce sound
fluidsynth noteon doesn't produce sound
In a Linux terminal I am running:
fluidsynth -a alsa Tim.sf2
in the fluidsynth shell I try to play a note
noteon 0 60 30
But nothing plays. What am I missing?
In a Linux terminal I am running:
fluidsynth -a alsa Tim.sf2
in the fluidsynth shell I try to play a note
noteon 0 60 30
But nothing plays. What am I missing?
yGuard Obfuscate code in case insensitive file system as Windows
yGuard Obfuscate code in case insensitive file system as Windows
I try to obfuscase my JAR file in Windows by yGuard but classes in the
same package are renamed to the same name (ignored case).
Ex.: MyCookieUtils.class => A.class MyFormatterUtils.class => a.class
Windows can recognize only one file with name A.class or a.class in a
folder, the other is overrided. So it cannot run after obfuscation code :(
Anyone can help? Thanks
I try to obfuscase my JAR file in Windows by yGuard but classes in the
same package are renamed to the same name (ignored case).
Ex.: MyCookieUtils.class => A.class MyFormatterUtils.class => a.class
Windows can recognize only one file with name A.class or a.class in a
folder, the other is overrided. So it cannot run after obfuscation code :(
Anyone can help? Thanks
Tuesday, 1 October 2013
Slider Puzzle problems
Slider Puzzle problems
This is my slider puzzle game. So far it can only do 3x3 games. When I try
and pass the variables l and w (length and width) of the board it doesn't
work. It only works when i set the variables ROWS and COLS as finals. When
I try and change it I get errors. I'm not sure what to do, any help would
be appreciated.
Currently the user can input values that can't do anything at the moment.
When the game is started, a 3x3 board is generated. The user can restart
the game with a different scrambled board but the buttons that solve the
board and the buttons that reset the board to the original state do not
work yet.
public class SlidePuzzle {
public static void main(String[] args)
{
JFrame window = new JFrame("Slide Puzzle");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String length = JOptionPane.showInputDialog("Length");
String width = JOptionPane.showInputDialog("Width");
int l = Integer.parseInt(length);
int w = Integer.parseInt(width);
window.setContentPane(new SlidePuzzleGUI());
window.pack();
window.show();
window.setResizable(false);
}
}
public class SlidePuzzleGUI extends JPanel
{
private GraphicsPanel _puzzleGraphics;
private SlidePuzzleModel _puzzleModel = new SlidePuzzleModel();
This class contains the GUI for the Slider Puzzle
public SlidePuzzleGUI() {
JButton newGameButton = new JButton("New Game");
JButton resetButton = new JButton("Reset");
JButton solveButton = new JButton("I GIVE UP :(");
resetButton.addActionListener(new ResetAction());
newGameButton.addActionListener(new NewGameAction());
JPanel controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
controlPanel.add(newGameButton);
controlPanel.add(resetButton);
controlPanel.add(solveButton);
_puzzleGraphics = new GraphicsPanel();
this.setLayout(new BorderLayout());
this.add(controlPanel, BorderLayout.NORTH);
this.add(_puzzleGraphics, BorderLayout.CENTER);
}
This is the graphics panel
class GraphicsPanel extends JPanel implements MouseListener {
private static final int ROWS = 3;
private static final int COLS = 3;
private static final int CELL_SIZE = 80;
private Font _biggerFont;
public GraphicsPanel() {
_biggerFont = new Font("SansSerif", Font.BOLD, CELL_SIZE/2);
this.setPreferredSize(
new Dimension(CELL_SIZE * COLS, CELL_SIZE*ROWS));
this.setBackground(Color.black);
this.addMouseListener(this);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (int r=0; r<ROWS; r++) {
for (int c=0; c<COLS; c++) {
int x = c * CELL_SIZE;
int y = r * CELL_SIZE;
String text = _puzzleModel.getFace(r, c);
if (text != null) {
g.setColor(Color.gray);
g.fillRect(x+2, y+2, CELL_SIZE-4, CELL_SIZE-4);
g.setColor(Color.black);
g.setFont(_biggerFont);
g.drawString(text, x+20, y+(3*CELL_SIZE)/4);
}
}
}
}
public void mousePressed(MouseEvent e) {
int col = e.getX()/CELL_SIZE;
int row = e.getY()/CELL_SIZE;
if (!_puzzleModel.moveTile(row, col)) {
Toolkit.getDefaultToolkit().beep();
}
this.repaint();
}
public void mouseClicked (MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered (MouseEvent e) {}
public void mouseExited (MouseEvent e) {}
}
public class NewGameAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
_puzzleModel.reset();
_puzzleGraphics.repaint();
}
}
public class ResetAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
_puzzleModel.tryAgain();
_puzzleGraphics.repaint();
}
}
public class solveAction implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
_puzzleModel.solve();
_puzzleGraphics.repaint();
}
}
}
public class SlidePuzzleModel {
private static final int ROWS = 3;
private static final int COLS = 3;
private Tile[][] _contents;
private Tile[][] _solved;
private Tile _emptyTile;
public SlidePuzzleModel() {
_contents = new Tile[ROWS][COLS];
reset();
}
String getFace(int row, int col) {
return _contents[row][col].getFace();
}
public void reset() {
for (int r=0; r<ROWS; r++) {
for (int c=0; c<COLS; c++) {
_contents[r][c] = new Tile(r, c, "" + (r*COLS+c+1));
}
}
_emptyTile = _contents[ROWS-1][COLS-1];
_emptyTile.setFace(null);
for (int r=0; r<ROWS; r++) {
for (int c=0; c<COLS; c++) {
exchangeTiles(r, c, (int)(Math.random()*ROWS)
, (int)(Math.random()*COLS));
}
}
}
public void tryAgain()
{
}
public void solve()
{
for (int i = 1; i < ROWS+1;i++)
{
for(int j = 1; j < COLS+1;j++)
{
exchangeTiles(i, j, i, j);
}
}
}
public boolean moveTile(int r, int c) {
return checkEmpty(r, c, -1, 0) || checkEmpty(r, c, 1, 0)
|| checkEmpty(r, c, 0, -1) || checkEmpty(r, c, 0, 1);
}
private boolean checkEmpty(int r, int c, int rdelta, int cdelta) {
int rNeighbor = r + rdelta;
int cNeighbor = c + cdelta;
if (isLegalRowCol(rNeighbor, cNeighbor)
&& _contents[rNeighbor][cNeighbor] == _emptyTile) {
exchangeTiles(r, c, rNeighbor, cNeighbor);
return true;
}
return false;
}
public boolean isLegalRowCol(int r, int c) {
return r>=0 && r<ROWS && c>=0 && c<COLS;
}
private void exchangeTiles(int r1, int c1, int r2, int c2) {
Tile temp = _contents[r1][c1];
_contents[r1][c1] = _contents[r2][c2];
_contents[r2][c2] = temp;
}
public boolean isGameOver() {
for (int r=0; r<ROWS; r++) {
for (int c=0; c<ROWS; c++) {
Tile trc = _contents[r][c];
return trc.isInFinalPosition(r, c);
}
}
return true;
}
}
class Tile {
private int _row;
private int _col;
private String _face;
public Tile(int row, int col, String face) {
_row = row;
_col = col;
_face = face;
}
public void setFace(String newFace) {
_face = newFace;
}
public String getFace() {
return _face;
}
public boolean isInFinalPosition(int r, int c) {
return r==_row && c==_col;
}
}
How would I make it so that the user can specify dimensions of the game
board?
EDIT public class SlidePuzzle {
public static void main(String[] args)
{
JFrame window = new JFrame("Slide Puzzle");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String length = JOptionPane.showInputDialog("Length");
String width = JOptionPane.showInputDialog("Width");
int l = Integer.parseInt(length);
int w = Integer.parseInt(width);
window.setContentPane(new SlidePuzzleGUI());
window.pack();
window.show();
window.setResizable(false);
}
} public class SlidePuzzleGUI extends JPanel {
private GraphicsPanel _puzzleGraphics;
private SlidePuzzleModel _puzzleModel = new SlidePuzzleModel();
public SlidePuzzleGUI(int l, int w) {
JButton newGameButton = new JButton("New Game");
JButton resetButton = new JButton("Reset");
JButton solveButton = new JButton("I GIVE UP :(");
resetButton.addActionListener(new ResetAction());
newGameButton.addActionListener(new NewGameAction());
JPanel controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
controlPanel.add(newGameButton);
controlPanel.add(resetButton);
controlPanel.add(solveButton);
_puzzleGraphics = new GraphicsPanel(l,w);
this.setLayout(new BorderLayout());
this.add(controlPanel, BorderLayout.NORTH);
this.add(_puzzleGraphics, BorderLayout.CENTER);
}
class GraphicsPanel extends JPanel implements MouseListener {
private int ROWS;
private int COLS;
private static final int CELL_SIZE = 80;
private Font _biggerFont;
public GraphicsPanel(int l, int w) {
_biggerFont = new Font("SansSerif", Font.BOLD, CELL_SIZE/2);
this.setPreferredSize(
new Dimension(CELL_SIZE * COLS, CELL_SIZE*ROWS));
this.setBackground(Color.black);
this.addMouseListener(this);
ROWS = l;
COLS = w;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (int r=0; r<ROWS; r++) {
for (int c=0; c<COLS; c++) {
int x = c * CELL_SIZE;
int y = r * CELL_SIZE;
String text = _puzzleModel.getFace(r, c);
if (text != null) {
g.setColor(Color.gray);
g.fillRect(x+2, y+2, CELL_SIZE-4, CELL_SIZE-4);
g.setColor(Color.black);
g.setFont(_biggerFont);
g.drawString(text, x+20, y+(3*CELL_SIZE)/4);
}
}
}
}
public void mousePressed(MouseEvent e) {
int col = e.getX()/CELL_SIZE;
int row = e.getY()/CELL_SIZE;
if (!_puzzleModel.moveTile(row, col)) {
Toolkit.getDefaultToolkit().beep();
}
this.repaint();
}
public void mouseClicked (MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered (MouseEvent e) {}
public void mouseExited (MouseEvent e) {}
}
public class NewGameAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
_puzzleModel.reset();
_puzzleGraphics.repaint();
}
}
public class ResetAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
_puzzleModel.tryAgain();
_puzzleGraphics.repaint();
}
}
public class solveAction implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
_puzzleModel.solve();
_puzzleGraphics.repaint();
}
}
}
This is my slider puzzle game. So far it can only do 3x3 games. When I try
and pass the variables l and w (length and width) of the board it doesn't
work. It only works when i set the variables ROWS and COLS as finals. When
I try and change it I get errors. I'm not sure what to do, any help would
be appreciated.
Currently the user can input values that can't do anything at the moment.
When the game is started, a 3x3 board is generated. The user can restart
the game with a different scrambled board but the buttons that solve the
board and the buttons that reset the board to the original state do not
work yet.
public class SlidePuzzle {
public static void main(String[] args)
{
JFrame window = new JFrame("Slide Puzzle");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String length = JOptionPane.showInputDialog("Length");
String width = JOptionPane.showInputDialog("Width");
int l = Integer.parseInt(length);
int w = Integer.parseInt(width);
window.setContentPane(new SlidePuzzleGUI());
window.pack();
window.show();
window.setResizable(false);
}
}
public class SlidePuzzleGUI extends JPanel
{
private GraphicsPanel _puzzleGraphics;
private SlidePuzzleModel _puzzleModel = new SlidePuzzleModel();
This class contains the GUI for the Slider Puzzle
public SlidePuzzleGUI() {
JButton newGameButton = new JButton("New Game");
JButton resetButton = new JButton("Reset");
JButton solveButton = new JButton("I GIVE UP :(");
resetButton.addActionListener(new ResetAction());
newGameButton.addActionListener(new NewGameAction());
JPanel controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
controlPanel.add(newGameButton);
controlPanel.add(resetButton);
controlPanel.add(solveButton);
_puzzleGraphics = new GraphicsPanel();
this.setLayout(new BorderLayout());
this.add(controlPanel, BorderLayout.NORTH);
this.add(_puzzleGraphics, BorderLayout.CENTER);
}
This is the graphics panel
class GraphicsPanel extends JPanel implements MouseListener {
private static final int ROWS = 3;
private static final int COLS = 3;
private static final int CELL_SIZE = 80;
private Font _biggerFont;
public GraphicsPanel() {
_biggerFont = new Font("SansSerif", Font.BOLD, CELL_SIZE/2);
this.setPreferredSize(
new Dimension(CELL_SIZE * COLS, CELL_SIZE*ROWS));
this.setBackground(Color.black);
this.addMouseListener(this);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (int r=0; r<ROWS; r++) {
for (int c=0; c<COLS; c++) {
int x = c * CELL_SIZE;
int y = r * CELL_SIZE;
String text = _puzzleModel.getFace(r, c);
if (text != null) {
g.setColor(Color.gray);
g.fillRect(x+2, y+2, CELL_SIZE-4, CELL_SIZE-4);
g.setColor(Color.black);
g.setFont(_biggerFont);
g.drawString(text, x+20, y+(3*CELL_SIZE)/4);
}
}
}
}
public void mousePressed(MouseEvent e) {
int col = e.getX()/CELL_SIZE;
int row = e.getY()/CELL_SIZE;
if (!_puzzleModel.moveTile(row, col)) {
Toolkit.getDefaultToolkit().beep();
}
this.repaint();
}
public void mouseClicked (MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered (MouseEvent e) {}
public void mouseExited (MouseEvent e) {}
}
public class NewGameAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
_puzzleModel.reset();
_puzzleGraphics.repaint();
}
}
public class ResetAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
_puzzleModel.tryAgain();
_puzzleGraphics.repaint();
}
}
public class solveAction implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
_puzzleModel.solve();
_puzzleGraphics.repaint();
}
}
}
public class SlidePuzzleModel {
private static final int ROWS = 3;
private static final int COLS = 3;
private Tile[][] _contents;
private Tile[][] _solved;
private Tile _emptyTile;
public SlidePuzzleModel() {
_contents = new Tile[ROWS][COLS];
reset();
}
String getFace(int row, int col) {
return _contents[row][col].getFace();
}
public void reset() {
for (int r=0; r<ROWS; r++) {
for (int c=0; c<COLS; c++) {
_contents[r][c] = new Tile(r, c, "" + (r*COLS+c+1));
}
}
_emptyTile = _contents[ROWS-1][COLS-1];
_emptyTile.setFace(null);
for (int r=0; r<ROWS; r++) {
for (int c=0; c<COLS; c++) {
exchangeTiles(r, c, (int)(Math.random()*ROWS)
, (int)(Math.random()*COLS));
}
}
}
public void tryAgain()
{
}
public void solve()
{
for (int i = 1; i < ROWS+1;i++)
{
for(int j = 1; j < COLS+1;j++)
{
exchangeTiles(i, j, i, j);
}
}
}
public boolean moveTile(int r, int c) {
return checkEmpty(r, c, -1, 0) || checkEmpty(r, c, 1, 0)
|| checkEmpty(r, c, 0, -1) || checkEmpty(r, c, 0, 1);
}
private boolean checkEmpty(int r, int c, int rdelta, int cdelta) {
int rNeighbor = r + rdelta;
int cNeighbor = c + cdelta;
if (isLegalRowCol(rNeighbor, cNeighbor)
&& _contents[rNeighbor][cNeighbor] == _emptyTile) {
exchangeTiles(r, c, rNeighbor, cNeighbor);
return true;
}
return false;
}
public boolean isLegalRowCol(int r, int c) {
return r>=0 && r<ROWS && c>=0 && c<COLS;
}
private void exchangeTiles(int r1, int c1, int r2, int c2) {
Tile temp = _contents[r1][c1];
_contents[r1][c1] = _contents[r2][c2];
_contents[r2][c2] = temp;
}
public boolean isGameOver() {
for (int r=0; r<ROWS; r++) {
for (int c=0; c<ROWS; c++) {
Tile trc = _contents[r][c];
return trc.isInFinalPosition(r, c);
}
}
return true;
}
}
class Tile {
private int _row;
private int _col;
private String _face;
public Tile(int row, int col, String face) {
_row = row;
_col = col;
_face = face;
}
public void setFace(String newFace) {
_face = newFace;
}
public String getFace() {
return _face;
}
public boolean isInFinalPosition(int r, int c) {
return r==_row && c==_col;
}
}
How would I make it so that the user can specify dimensions of the game
board?
EDIT public class SlidePuzzle {
public static void main(String[] args)
{
JFrame window = new JFrame("Slide Puzzle");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String length = JOptionPane.showInputDialog("Length");
String width = JOptionPane.showInputDialog("Width");
int l = Integer.parseInt(length);
int w = Integer.parseInt(width);
window.setContentPane(new SlidePuzzleGUI());
window.pack();
window.show();
window.setResizable(false);
}
} public class SlidePuzzleGUI extends JPanel {
private GraphicsPanel _puzzleGraphics;
private SlidePuzzleModel _puzzleModel = new SlidePuzzleModel();
public SlidePuzzleGUI(int l, int w) {
JButton newGameButton = new JButton("New Game");
JButton resetButton = new JButton("Reset");
JButton solveButton = new JButton("I GIVE UP :(");
resetButton.addActionListener(new ResetAction());
newGameButton.addActionListener(new NewGameAction());
JPanel controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
controlPanel.add(newGameButton);
controlPanel.add(resetButton);
controlPanel.add(solveButton);
_puzzleGraphics = new GraphicsPanel(l,w);
this.setLayout(new BorderLayout());
this.add(controlPanel, BorderLayout.NORTH);
this.add(_puzzleGraphics, BorderLayout.CENTER);
}
class GraphicsPanel extends JPanel implements MouseListener {
private int ROWS;
private int COLS;
private static final int CELL_SIZE = 80;
private Font _biggerFont;
public GraphicsPanel(int l, int w) {
_biggerFont = new Font("SansSerif", Font.BOLD, CELL_SIZE/2);
this.setPreferredSize(
new Dimension(CELL_SIZE * COLS, CELL_SIZE*ROWS));
this.setBackground(Color.black);
this.addMouseListener(this);
ROWS = l;
COLS = w;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (int r=0; r<ROWS; r++) {
for (int c=0; c<COLS; c++) {
int x = c * CELL_SIZE;
int y = r * CELL_SIZE;
String text = _puzzleModel.getFace(r, c);
if (text != null) {
g.setColor(Color.gray);
g.fillRect(x+2, y+2, CELL_SIZE-4, CELL_SIZE-4);
g.setColor(Color.black);
g.setFont(_biggerFont);
g.drawString(text, x+20, y+(3*CELL_SIZE)/4);
}
}
}
}
public void mousePressed(MouseEvent e) {
int col = e.getX()/CELL_SIZE;
int row = e.getY()/CELL_SIZE;
if (!_puzzleModel.moveTile(row, col)) {
Toolkit.getDefaultToolkit().beep();
}
this.repaint();
}
public void mouseClicked (MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered (MouseEvent e) {}
public void mouseExited (MouseEvent e) {}
}
public class NewGameAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
_puzzleModel.reset();
_puzzleGraphics.repaint();
}
}
public class ResetAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
_puzzleModel.tryAgain();
_puzzleGraphics.repaint();
}
}
public class solveAction implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
_puzzleModel.solve();
_puzzleGraphics.repaint();
}
}
}
Oracle EXISTS clause Vs ROWNUM = 1
Oracle EXISTS clause Vs ROWNUM = 1
For a long time, I have been using the EXISTS clause to determine if at
least one record exists in a given table for a given condition. for
example - if I wanted to see if an employee by lastname = 'smith' exists
in the "employee" table, I used the following query
select 1 into v_exists_flag from dual where exists ( select 1 from
employee where lastname = 'smith' )
This is definitely more efficient than using the count(*) clause.
select count(*) into v_count from employee where lastname = 'smith'
if v_count > 0 then....
But, recently someone mentioned that using ROWNUM = 1 has better
performance than using the EXISTS clause as shown below
select 1 into v_count from employee where lastname = 'smith' and rownum = 1
Is this correct? Can someone confirm this.
Thanks in advance
For a long time, I have been using the EXISTS clause to determine if at
least one record exists in a given table for a given condition. for
example - if I wanted to see if an employee by lastname = 'smith' exists
in the "employee" table, I used the following query
select 1 into v_exists_flag from dual where exists ( select 1 from
employee where lastname = 'smith' )
This is definitely more efficient than using the count(*) clause.
select count(*) into v_count from employee where lastname = 'smith'
if v_count > 0 then....
But, recently someone mentioned that using ROWNUM = 1 has better
performance than using the EXISTS clause as shown below
select 1 into v_count from employee where lastname = 'smith' and rownum = 1
Is this correct? Can someone confirm this.
Thanks in advance
Find maximum number of egdes of a graph.
Find maximum number of egdes of a graph.
Find the maximum number of egdes in a graph with n vertices s.t.
(a)the graph has no odd cycle . (b)the graph has no even cycle .
Find the maximum number of egdes in a graph with n vertices s.t.
(a)the graph has no odd cycle . (b)the graph has no even cycle .
What's the coin in the curosity rover=?iso-8859-1?Q?=3F_=96_space.stackexchange.com?=
What's the coin in the curosity rover? – space.stackexchange.com
In the image below was taken from the curiosity rover(i hope). But there
is coin in the image. Is that really a coin or some kind of button. If so
what kind of function it has ? Is that really ...
In the image below was taken from the curiosity rover(i hope). But there
is coin in the image. Is that really a coin or some kind of button. If so
what kind of function it has ? Is that really ...
Monday, 30 September 2013
Uninstalled server 2008 now router won't handle DHCP
Uninstalled server 2008 now router won't handle DHCP
My set up is this. server behind router, router has a server and switch
connected to it with multiple computers. router used to serve DHCP and
DNS, a couple of days ago installed AD, DNS and DHCP on the server, and
the server gave out IP's.
For various reasons we had to uninstall the domain on our server. I
removed AD, DHCP and DNS from the roles and set the router back to serving
DHCP and DNS. Now I can't get computers on the network. I reset my router
back to factory defaults, and if I plug a computer directly into the
router I can get a IP address, but all the computers behind the switch
can't get an IP address and can't see the router. All my computers say
unidentified network, and if I ping the router it says host is
unreachable.
On the other hand, my wireless devices are just fine and connect no
problem. But for desktops, ipconfig /release doesn't release anything and
/renew can't find a server to renew on. My router log shows several FIN
scans but they are from innocuous websites (google, netgear) and it shows
a couple of smurf attacks but they are all from my external IP. Any ideas?
the server isn't even connected to the route right now, and all the
computers are set for dynamic IP addresses.. I don't know what else to
try? Any help?
My set up is this. server behind router, router has a server and switch
connected to it with multiple computers. router used to serve DHCP and
DNS, a couple of days ago installed AD, DNS and DHCP on the server, and
the server gave out IP's.
For various reasons we had to uninstall the domain on our server. I
removed AD, DHCP and DNS from the roles and set the router back to serving
DHCP and DNS. Now I can't get computers on the network. I reset my router
back to factory defaults, and if I plug a computer directly into the
router I can get a IP address, but all the computers behind the switch
can't get an IP address and can't see the router. All my computers say
unidentified network, and if I ping the router it says host is
unreachable.
On the other hand, my wireless devices are just fine and connect no
problem. But for desktops, ipconfig /release doesn't release anything and
/renew can't find a server to renew on. My router log shows several FIN
scans but they are from innocuous websites (google, netgear) and it shows
a couple of smurf attacks but they are all from my external IP. Any ideas?
the server isn't even connected to the route right now, and all the
computers are set for dynamic IP addresses.. I don't know what else to
try? Any help?
Guidelines for typesetting fractions tex.stackexchange.com
Guidelines for typesetting fractions – tex.stackexchange.com
I realize that this question is to some extent subjective. However, I
suspect that there are some common standards regarding how fractions ought
to be typeset in mathematics. The guide Mathematical …
I realize that this question is to some extent subjective. However, I
suspect that there are some common standards regarding how fractions ought
to be typeset in mathematics. The guide Mathematical …
Emmet plugin in Sublime Text 2 with Soy Templates
Emmet plugin in Sublime Text 2 with Soy Templates
Has anyone gotten the Emmet plugin to work with Soy Templates in Sublime
Text 2? I tried following the recommendation here:
http://docs.emmet.io/customization/syntax-profiles/ and added a
syntaxProfiles.json file with the following:
{ "SoyTemplate": "html" }
but that didn't do anything.
Any advice would be tremendously appreciated. Thank you.
Has anyone gotten the Emmet plugin to work with Soy Templates in Sublime
Text 2? I tried following the recommendation here:
http://docs.emmet.io/customization/syntax-profiles/ and added a
syntaxProfiles.json file with the following:
{ "SoyTemplate": "html" }
but that didn't do anything.
Any advice would be tremendously appreciated. Thank you.
UIPopoverViewController in ios7?
UIPopoverViewController in ios7?
In iOS 6 UIPopoverView have border with black translucent colour but iOS 7
do not have border because iOS 7 become transparent. how to add border
with black translucent in iOS 7.
Can anyone know please help me to solve this problem?
In iOS 6 UIPopoverView have border with black translucent colour but iOS 7
do not have border because iOS 7 become transparent. how to add border
with black translucent in iOS 7.
Can anyone know please help me to solve this problem?
Sunday, 29 September 2013
What is the convenience method to compare two NSNumbers with float values using limited precision?
What is the convenience method to compare two NSNumbers with float values
using limited precision?
What is the Objective-C convenience method for comparing a couple of
NSNumbers with float values to see if they are roughly equivalent (two
decimal places of precision is fine)?
I would use something other than floats if there was an option that did
not change the number around randomly. But anyway I'm already using floats
so... .
I imagine there must be something like:
[myNumber isEqualTo:myOtherNumber withPrecision:2];
But actually, amazingly I can't find such a convenience method. What am I
missing here?
Would it help to cast the two numbers to NSDecimal or something?
using limited precision?
What is the Objective-C convenience method for comparing a couple of
NSNumbers with float values to see if they are roughly equivalent (two
decimal places of precision is fine)?
I would use something other than floats if there was an option that did
not change the number around randomly. But anyway I'm already using floats
so... .
I imagine there must be something like:
[myNumber isEqualTo:myOtherNumber withPrecision:2];
But actually, amazingly I can't find such a convenience method. What am I
missing here?
Would it help to cast the two numbers to NSDecimal or something?
Connecting to host from Android via USB
Connecting to host from Android via USB
Okay so here is the background of this problem. I commute a lot on the
train and build a lot of PHP web apps optimized for mobile devices. I
would like to develop code on a netbook (Running Ubuntu Server) with no
GUI. All development done using Vim directly on the netbook.
I would like to connect up my Nexus 4 to the netbook via USB and "connect"
to the netbooks web server in the chrome browser. I can only use USB for
this since I won't be having any reliable internet access.
I understand that using adb from the Android SDK, you can forward a port
from the netbook to the phone. However, I need to do it the other way
around.
For example:
Run a web server on the netbook on port 4000
Connect phone via USB
Somehow forward port 4000 on the phone to port 4000 on the netbook
Open chrome browser on phone and go to localhost:4000.
I am aware of the "reverse port forwarding" method that is described in
the Google docs at
https://developers.google.com/chrome-developer-tools/docs/remote-debugging.
However, this requires an installation of chrome on the netbook. I don't
want to have to install an entire GUI just for this.
Okay so here is the background of this problem. I commute a lot on the
train and build a lot of PHP web apps optimized for mobile devices. I
would like to develop code on a netbook (Running Ubuntu Server) with no
GUI. All development done using Vim directly on the netbook.
I would like to connect up my Nexus 4 to the netbook via USB and "connect"
to the netbooks web server in the chrome browser. I can only use USB for
this since I won't be having any reliable internet access.
I understand that using adb from the Android SDK, you can forward a port
from the netbook to the phone. However, I need to do it the other way
around.
For example:
Run a web server on the netbook on port 4000
Connect phone via USB
Somehow forward port 4000 on the phone to port 4000 on the netbook
Open chrome browser on phone and go to localhost:4000.
I am aware of the "reverse port forwarding" method that is described in
the Google docs at
https://developers.google.com/chrome-developer-tools/docs/remote-debugging.
However, this requires an installation of chrome on the netbook. I don't
want to have to install an entire GUI just for this.
Python method with *args and **args
Python method with *args and **args
I am trying to understand a method that uses *args, **kwargs,
Here is the complete details of the method,
Help on method open in module pyaudio:
open(self, *args, **kwargs) method of pyaudio.PyAudio instance
Open a new stream. See constructor for
:py:func:`Stream.__init__` for parameter details.
:returns: A new :py:class:`Stream`
..
class pyaudio.Stream(PA_manager, rate, channels, format, input=False,
output=False, input_device_index=None, output_device_index=None,
frames_per_buffer=1024, start=True,
input_host_api_specific_stream_info=None,
output_host_api_specific_stream_info=None, stream_callback=None)
PortAudio Stream Wrapper.
Use PyAudio.open() to make a new Stream.
__init__(PA_manager, rate, channels, format, input=False, output=False,
input_device_index=None, output_device_index=None, frames_per_buffer=1024,
start=True, input_host_api_specific_stream_info=None,
output_host_api_specific_stream_info=None, stream_callback=None)
Initialize a stream; this should be called by PyAudio.open(). A stream can
either be input, output, or both.
What I want to do is to use
PyAudio.open()
method and set the value of input_device_index= to 1
But I couldn't understand how to pass the arguments in this function as I
have no idea how these *args and **kwargs works.
I am trying to understand a method that uses *args, **kwargs,
Here is the complete details of the method,
Help on method open in module pyaudio:
open(self, *args, **kwargs) method of pyaudio.PyAudio instance
Open a new stream. See constructor for
:py:func:`Stream.__init__` for parameter details.
:returns: A new :py:class:`Stream`
..
class pyaudio.Stream(PA_manager, rate, channels, format, input=False,
output=False, input_device_index=None, output_device_index=None,
frames_per_buffer=1024, start=True,
input_host_api_specific_stream_info=None,
output_host_api_specific_stream_info=None, stream_callback=None)
PortAudio Stream Wrapper.
Use PyAudio.open() to make a new Stream.
__init__(PA_manager, rate, channels, format, input=False, output=False,
input_device_index=None, output_device_index=None, frames_per_buffer=1024,
start=True, input_host_api_specific_stream_info=None,
output_host_api_specific_stream_info=None, stream_callback=None)
Initialize a stream; this should be called by PyAudio.open(). A stream can
either be input, output, or both.
What I want to do is to use
PyAudio.open()
method and set the value of input_device_index= to 1
But I couldn't understand how to pass the arguments in this function as I
have no idea how these *args and **kwargs works.
Entity Framework 5 Model first code generation
Entity Framework 5 Model first code generation
I'm using Entity Framwork 5.0 and visual studio 2010. The entities,
contexts codes are generated in one file, I saw so many tutorials with VS
2012 which the generated codes are separated. How could I do this with VS
2010?
I'm using Entity Framwork 5.0 and visual studio 2010. The entities,
contexts codes are generated in one file, I saw so many tutorials with VS
2012 which the generated codes are separated. How could I do this with VS
2010?
Saturday, 28 September 2013
Error 404 on Symfony2
Error 404 on Symfony2
I have 3 symfony2 apps, 2 wors fine, but the third just works for the
default page. The rest of the routes throw a 404 error. Environment is:
Ubunto 12.04 VirtualBox, apache 2, php 5.3.10, Mongobd.
This is de VHost content: DocumentRoot
/home/adminuser/webs/servergrove/web ServerName servergrove.local ErrorLog
/var/log/apache2/servergrove-error.log CustomLog
/var/log/apache2/servergrove-access.log combined AllowOverride All
This is the routing.yml:
homepage: pattern: / defaults: { _controller:
SGLiveChatBundle:Default:index }
sglc_chat_homepage: pattern: /sglivechat defaults: { _controller:
SGLiveChatBundle:Chat:index }
sglc_chat_invite: pattern: /sglivechat/{sessId}/invite defaults: {
_controller: SGLiveChatBundle:Chat:invite }
... and so on.
The following url works fine: http://servergrove.local/
The following (and any other) doesn't: http://servergrove.local/sglivechat
Not Found The requested URL /sglivechat was not found on this server.
Apache/2.2.22 (Ubuntu) Server at servergrove.local Port 80
I have very little experience with symfony. I'd think is related with
rewrite engine, but the other two projects works ok.
I've got the following on the command line:
adminuser@adminuser-VirtualBox-073n:~/webs/servergrove$ php app/console
router:debug [router] Current routes Name Method Pattern homepage ANY /
sglc_admin_index GET /admin/sglivechat prueba ANY /prueba
adminuser@adminuser-VirtualBox-073n:~/webs/servergrove$ php app/console
router:dump-apache RewriteCond %{PATH_INFO} ^/$ RewriteRule .* app.php
[QSA,L,E=ROUTING_route:homepage,E=ROUTING_controller:ServerGrove\SGLiveChatBundle\Controller\DefaultController::indexAction]
RewriteCond %{REQUEST_METHOD} ^(get) [NC] RewriteCond %{PATH_INFO}
^/admin/sglivechat$ RewriteRule .* app.php
[QSA,L,E=ROUTING_route:sglc_admin_index,E=ROUTING_controller:ServerGrove\SGLiveChatBundle\Controller\AdminController::indexAction]
RewriteCond %{PATH_INFO} ^/prueba$ RewriteRule .* app.php
[QSA,L,E=ROUTING_route:prueba,E=ROUTING_controller:ServerGrove\SGLiveChatBundle\Controller\DefaultController::pruebaAction]
Any idea of what can be wrong?
I have 3 symfony2 apps, 2 wors fine, but the third just works for the
default page. The rest of the routes throw a 404 error. Environment is:
Ubunto 12.04 VirtualBox, apache 2, php 5.3.10, Mongobd.
This is de VHost content: DocumentRoot
/home/adminuser/webs/servergrove/web ServerName servergrove.local ErrorLog
/var/log/apache2/servergrove-error.log CustomLog
/var/log/apache2/servergrove-access.log combined AllowOverride All
This is the routing.yml:
homepage: pattern: / defaults: { _controller:
SGLiveChatBundle:Default:index }
sglc_chat_homepage: pattern: /sglivechat defaults: { _controller:
SGLiveChatBundle:Chat:index }
sglc_chat_invite: pattern: /sglivechat/{sessId}/invite defaults: {
_controller: SGLiveChatBundle:Chat:invite }
... and so on.
The following url works fine: http://servergrove.local/
The following (and any other) doesn't: http://servergrove.local/sglivechat
Not Found The requested URL /sglivechat was not found on this server.
Apache/2.2.22 (Ubuntu) Server at servergrove.local Port 80
I have very little experience with symfony. I'd think is related with
rewrite engine, but the other two projects works ok.
I've got the following on the command line:
adminuser@adminuser-VirtualBox-073n:~/webs/servergrove$ php app/console
router:debug [router] Current routes Name Method Pattern homepage ANY /
sglc_admin_index GET /admin/sglivechat prueba ANY /prueba
adminuser@adminuser-VirtualBox-073n:~/webs/servergrove$ php app/console
router:dump-apache RewriteCond %{PATH_INFO} ^/$ RewriteRule .* app.php
[QSA,L,E=ROUTING_route:homepage,E=ROUTING_controller:ServerGrove\SGLiveChatBundle\Controller\DefaultController::indexAction]
RewriteCond %{REQUEST_METHOD} ^(get) [NC] RewriteCond %{PATH_INFO}
^/admin/sglivechat$ RewriteRule .* app.php
[QSA,L,E=ROUTING_route:sglc_admin_index,E=ROUTING_controller:ServerGrove\SGLiveChatBundle\Controller\AdminController::indexAction]
RewriteCond %{PATH_INFO} ^/prueba$ RewriteRule .* app.php
[QSA,L,E=ROUTING_route:prueba,E=ROUTING_controller:ServerGrove\SGLiveChatBundle\Controller\DefaultController::pruebaAction]
Any idea of what can be wrong?
jQuery: hide/ show + change text clicking the same class
jQuery: hide/ show + change text clicking the same class
I have a group of words that on click should show and hide elements. In
addition, I need to change that first group of words. So if it gets
clicked, it shows the container with content + gets changed to hide. In
alternative, when it is clicked again, it should hide the content and
become 'show' again.
<div class="hide-show-button">Click Here to <span
id="hide-show-changed">Show</span></div>
<div class="hide-show">
.... content
</div>
<script>
$('.hide-show').hide();
$('.hide-show-button').click(function(){
$('.hide-show').show();
$('#hide-show-changed').text('Hide');
}, function() {
$('.hide-show').hide();
$('#hide-show-changed').text('Show');
});
</script>
Thanks
I have a group of words that on click should show and hide elements. In
addition, I need to change that first group of words. So if it gets
clicked, it shows the container with content + gets changed to hide. In
alternative, when it is clicked again, it should hide the content and
become 'show' again.
<div class="hide-show-button">Click Here to <span
id="hide-show-changed">Show</span></div>
<div class="hide-show">
.... content
</div>
<script>
$('.hide-show').hide();
$('.hide-show-button').click(function(){
$('.hide-show').show();
$('#hide-show-changed').text('Hide');
}, function() {
$('.hide-show').hide();
$('#hide-show-changed').text('Show');
});
</script>
Thanks
Not able to use custom layout in ArrayAdapter
Not able to use custom layout in ArrayAdapter
I'm new to android, I want to use my custom layout file instead of
simple_list_item_1 but its not allowing to do so. I want to add an
backgroud image(which is defined in layout->custom_view.xml) to each items
in the list OR help me to set the backgroud for the whole page, In the
below code where should I use the setContentView Method. Also let me know
if any changes are to be made in the below .xml file.
public class Planet extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState)
{super.onCreate(savedInstanceState);
//setContentView(R.layout.custom_view); Tried to set the view from
here but the application is crashing...
String[] planet_names = new String[]
{"Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune","Sun"};
ArrayAdapter<String> adapter = new
ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
planet_names);
setListAdapter(adapter);
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View view,
int position, long id) {
if(position == 0)
{
Intent myIntent = new
Intent(Planet.this, Galaxy.class);
startActivityForResult(myIntent, 0);
}
}
});
}
custom_view.xml file is as follows,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF">
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
I'm new to android, I want to use my custom layout file instead of
simple_list_item_1 but its not allowing to do so. I want to add an
backgroud image(which is defined in layout->custom_view.xml) to each items
in the list OR help me to set the backgroud for the whole page, In the
below code where should I use the setContentView Method. Also let me know
if any changes are to be made in the below .xml file.
public class Planet extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState)
{super.onCreate(savedInstanceState);
//setContentView(R.layout.custom_view); Tried to set the view from
here but the application is crashing...
String[] planet_names = new String[]
{"Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune","Sun"};
ArrayAdapter<String> adapter = new
ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
planet_names);
setListAdapter(adapter);
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View view,
int position, long id) {
if(position == 0)
{
Intent myIntent = new
Intent(Planet.this, Galaxy.class);
startActivityForResult(myIntent, 0);
}
}
});
}
custom_view.xml file is as follows,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF">
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
Subscribe to:
Posts (Atom)