C# Typecast an Enum to a Struct
I'm using C#, and have manipulate an object one the screen. I setup a
struct to hold the coordinates, and then I setup an enum to restrict the
number of directions that could be moved.
private enum Direction
{
UpperLeft = new Coord(-1, -1), UpperCenter = new Coord(0, -1),
UpperRight = new Coord(1, -1),
Left = new Coord(-1, 0), Right = new Coord(1, 0),
LowerLeft = new Coord(-1, 1), LowerCenter = new Coord(0, 1),
LowerRight = new Coord(1, 1)
};
private struct Coord
{
public int row { get; private set; }
public int col { get; private set; }
public Coord(int r, int c) : this()
{
row = r;
col = c;
}
public static Coord operator +(Coord a, Coord b)
{
return new Coord(a.row + b.row, a.col + b.col);
}
}
Basically what I am aiming to do is to have the object I have on the
screen move based on the assigned enum.
So I'd like to hypothetically use it like this or something:
public class ThingThatMovesToTheLeft
{
Direction dir = Direction.Left;
Coord pos = new Coord(0,0);
public void Move()
{
this.pos = this.dir + this.pos;
}
}
Esentially my question is how do I typecast my enum back to my struct so I
can use it in this manor? I can't seem to be able to cast it back to the
struct. (Additionally, VisualStudios let me assign the enum to those Coord
structs without complaining so I assumed that it was okay to assign an
struct to an enum, is this acceptable practice or should this just not be
done?)
Thursday, October 3, 2013
Wednesday, October 2, 2013
C# Winform: Mouse Over Combobox Generate InvalidOperationException
C# Winform: Mouse Over Combobox Generate InvalidOperationException
This appears to be an error beyond my control. My WinForm application (C#
.NET Client Profile 4.0) is single threaded. By this, I mean the code I
wrote has only one thread. I understand that any WinForm GUI application
may have a background thread.
My application is used by about ten people, only two of them experience
the following exception.
When the users hoover their mouse over a combobox located on a standard
toolstrip, the correct behavior is that the combobox becomes in focus.
However, two users got the following exception:
System.InvalidOperationException: Object is currently in use elsewhere.
It looks that the exception is from background thread. Also, if I changed
the Widows 7 fancy themes to the Windows Classic theme, the error goes
away. But my user refuse to change his beloved theme.
Could you advise me on how to avoid this exception? I was thinking of
adding an event handler, handling move over event? I haven't try that yet.
Any advice is highly appreciated
This is the detailed exception message and stack trace.
***** Exception Text *******
System.InvalidOperationException: Object is currently in use elsewhere.
at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
at System.Drawing.Graphics.FillPolygon(Brush brush, Point[] points,
FillMode fillMode)
at System.Drawing.Graphics.FillPolygon(Brush brush, Point[] points)
at
System.Windows.Forms.ToolStripComboBox.ToolStripComboBoxControl.ToolStripComboBoxFlatComboAdapter.DrawFlatComboDropDown(ComboBox
comboBox, Graphics g, Rectangle dropDownRect)
at
System.Windows.Forms.ComboBox.FlatComboAdapter.DrawFlatCombo(ComboBox
comboBox, Graphics g)
at System.Windows.Forms.ComboBox.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
This appears to be an error beyond my control. My WinForm application (C#
.NET Client Profile 4.0) is single threaded. By this, I mean the code I
wrote has only one thread. I understand that any WinForm GUI application
may have a background thread.
My application is used by about ten people, only two of them experience
the following exception.
When the users hoover their mouse over a combobox located on a standard
toolstrip, the correct behavior is that the combobox becomes in focus.
However, two users got the following exception:
System.InvalidOperationException: Object is currently in use elsewhere.
It looks that the exception is from background thread. Also, if I changed
the Widows 7 fancy themes to the Windows Classic theme, the error goes
away. But my user refuse to change his beloved theme.
Could you advise me on how to avoid this exception? I was thinking of
adding an event handler, handling move over event? I haven't try that yet.
Any advice is highly appreciated
This is the detailed exception message and stack trace.
***** Exception Text *******
System.InvalidOperationException: Object is currently in use elsewhere.
at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
at System.Drawing.Graphics.FillPolygon(Brush brush, Point[] points,
FillMode fillMode)
at System.Drawing.Graphics.FillPolygon(Brush brush, Point[] points)
at
System.Windows.Forms.ToolStripComboBox.ToolStripComboBoxControl.ToolStripComboBoxFlatComboAdapter.DrawFlatComboDropDown(ComboBox
comboBox, Graphics g, Rectangle dropDownRect)
at
System.Windows.Forms.ComboBox.FlatComboAdapter.DrawFlatCombo(ComboBox
comboBox, Graphics g)
at System.Windows.Forms.ComboBox.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
YouTube API - playlist returning invalid hangout videos
YouTube API - playlist returning invalid hangout videos
Using the standard/example code provided by Google for the YouTube API in
order to display the list of videos found on a channel, I am getting lots
of invalid and non-existent videos returned back. They appear to have been
created by On Air Hangout events (for which, the "Start Broadcast" button
was never pressed and instead the event was just cancelled).
$channelsResponse = $youtube->channels->listChannels("contentDetails", array(
"mine" => "true", ));
foreach ($channelsResponse["items"] as $channel) {
$uploadsListId = $channel["contentDetails"]["relatedPlaylists"]["uploads"];
$playlistItemsResponse =
$youtube->playlistItems->listPlaylistItems("snippet", array(
"playlistId" => $uploadsListId,
"maxResults" => 50
));
echo "<h3>Videos in list $uploadsListId</h3><ul>";
foreach ($playlistItemsResponse["items"] as $playlistItem) {
echo $playlistItem["snippet"]["title"] . " (" .
$playlistItem["snippet"]["resourceId"]["videoId"] . ")<br>";
echo "<img src=" .
$playlistItem["snippet"]["thumbnails"]["default"]["url"] . "><br>";
echo "<br><br>";
}
echo "</ul>";
}
The invalid videos being returned do NOT show up when actually going into
my YouTube account in the Video Manager. It's like they are ghost
listings. Of course, actually conducting an On Air Hangout will cause the
video to be archived in YouTube and show up on the list as normal. But it
appears there is a bug that's causing cancelled events to show up to...
with no way to filer for them, delete them, or prevent them from being
returned. Help!!!
Using the standard/example code provided by Google for the YouTube API in
order to display the list of videos found on a channel, I am getting lots
of invalid and non-existent videos returned back. They appear to have been
created by On Air Hangout events (for which, the "Start Broadcast" button
was never pressed and instead the event was just cancelled).
$channelsResponse = $youtube->channels->listChannels("contentDetails", array(
"mine" => "true", ));
foreach ($channelsResponse["items"] as $channel) {
$uploadsListId = $channel["contentDetails"]["relatedPlaylists"]["uploads"];
$playlistItemsResponse =
$youtube->playlistItems->listPlaylistItems("snippet", array(
"playlistId" => $uploadsListId,
"maxResults" => 50
));
echo "<h3>Videos in list $uploadsListId</h3><ul>";
foreach ($playlistItemsResponse["items"] as $playlistItem) {
echo $playlistItem["snippet"]["title"] . " (" .
$playlistItem["snippet"]["resourceId"]["videoId"] . ")<br>";
echo "<img src=" .
$playlistItem["snippet"]["thumbnails"]["default"]["url"] . "><br>";
echo "<br><br>";
}
echo "</ul>";
}
The invalid videos being returned do NOT show up when actually going into
my YouTube account in the Video Manager. It's like they are ghost
listings. Of course, actually conducting an On Air Hangout will cause the
video to be archived in YouTube and show up on the list as normal. But it
appears there is a bug that's causing cancelled events to show up to...
with no way to filer for them, delete them, or prevent them from being
returned. Help!!!
Logging to JettyLogger(null)
Logging to JettyLogger(null)
when I run my application as an app engine web application, in the log
console I have that line:
INFO: Logging to JettyLogger(null) via
com.google.apphosting.utils.jetty.JettyLogger
console waits about 5-7 second on this line. may be because of "null",
what do you think? what is this, and how can I fix that?
when I run my application as an app engine web application, in the log
console I have that line:
INFO: Logging to JettyLogger(null) via
com.google.apphosting.utils.jetty.JettyLogger
console waits about 5-7 second on this line. may be because of "null",
what do you think? what is this, and how can I fix that?
Integer variable is zero when is it null in database
Integer variable is zero when is it null in database
I have declared variable as
private Integer projectId;
//with getters and setters
While retrieving values from database, if projectId is null in database
table, it is shown as 0 e.g.
log.info("?? "+projectList.get(1).getProjectId());
the result of the above is 0.
Why it is shown as 0 although it is null in table and how can I make this
is as null when it is null in table?
I have declared variable as
private Integer projectId;
//with getters and setters
While retrieving values from database, if projectId is null in database
table, it is shown as 0 e.g.
log.info("?? "+projectList.get(1).getProjectId());
the result of the above is 0.
Why it is shown as 0 although it is null in table and how can I make this
is as null when it is null in table?
Tuesday, October 1, 2013
How to use mysqli_query - PHP
How to use mysqli_query - PHP
Okay so I have a file that contains all the information for my database,
then I have a file that uses this information and a separate function that
calls the database. I have a function that is suppose to gather
information from the database but I need to use mysqli_query, how do I do
this? Because mysqli_query expects to things, the query and the connection
to the database. But my connection to the database is a separate function.
private $db;
//put your code here
// constructor
function __construct() {
require_once 'DB_Connect.php';
// connecting to database
$this->db = new DB_Connect();
$this->db->connect();
}
// destructor
function __destruct() {
}
public function isUserExisted($email) {
$result = mysqli_query($WHAT GOES HERE??,"SELECT email from users
WHERE email = '$email'");
$no_of_rows = mysqli_num_rows($result);
if ($no_of_rows > 0) {
// user existed
return true;
} else {
// user not existed
return false;
}
}
Okay so I have a file that contains all the information for my database,
then I have a file that uses this information and a separate function that
calls the database. I have a function that is suppose to gather
information from the database but I need to use mysqli_query, how do I do
this? Because mysqli_query expects to things, the query and the connection
to the database. But my connection to the database is a separate function.
private $db;
//put your code here
// constructor
function __construct() {
require_once 'DB_Connect.php';
// connecting to database
$this->db = new DB_Connect();
$this->db->connect();
}
// destructor
function __destruct() {
}
public function isUserExisted($email) {
$result = mysqli_query($WHAT GOES HERE??,"SELECT email from users
WHERE email = '$email'");
$no_of_rows = mysqli_num_rows($result);
if ($no_of_rows > 0) {
// user existed
return true;
} else {
// user not existed
return false;
}
}
Amazon EMR questions
Amazon EMR questions
I have to feed output from custom Linux application to Hadoop and it seems
as Amazon EMR is a great way to experiment. I am really just beginning to
look into Hadoop and Amazon documentation, so some advise would be
appreciated...
Would I be able to run my application in SELinux environment?
Would I be able to deploy/execute my app (written in C++) on Amazon EMR
nodes? What would be the approach to get the output of app (string, double
pair) into Hadoop in this environment?
Thank you.
I have to feed output from custom Linux application to Hadoop and it seems
as Amazon EMR is a great way to experiment. I am really just beginning to
look into Hadoop and Amazon documentation, so some advise would be
appreciated...
Would I be able to run my application in SELinux environment?
Would I be able to deploy/execute my app (written in C++) on Amazon EMR
nodes? What would be the approach to get the output of app (string, double
pair) into Hadoop in this environment?
Thank you.
Will the foot print of Neil Armstrong erode=?iso-8859-1?Q?=3F_=96_space.stackexchange.com?=
Will the foot print of Neil Armstrong erode? – space.stackexchange.com
The Moon has a very thin (practically non-existent) atmosphere so the foot
print left by Neil Armstrong won't be eroded for centuries. But there are
solar winds. Is it possible that solar wind would …
The Moon has a very thin (practically non-existent) atmosphere so the foot
print left by Neil Armstrong won't be eroded for centuries. But there are
solar winds. Is it possible that solar wind would …
Poisson distribution of independent variable [on hold]
Poisson distribution of independent variable [on hold]
N is a RV with a Poisson distribution with parameter ë. A coin has
probability p of heads. We flip the coin N times. Let X and Y be the
number of heads and tails respectively. Assume that the process which
generates N is independent of the coin. (a) Find the distributions of X
and Y . (b) Show that X and Y are independent.
N is a RV with a Poisson distribution with parameter ë. A coin has
probability p of heads. We flip the coin N times. Let X and Y be the
number of heads and tails respectively. Assume that the process which
generates N is independent of the coin. (a) Find the distributions of X
and Y . (b) Show that X and Y are independent.
Subscribe to:
Comments (Atom)