How to catch argv null exception?
In my program I pass an argument from console and save it to a variable.
Let's say
const string FileName= argv[1];
If there is no argument passing I get this
terminate called throwing an exception
How can I catch an exception and show proper error to user that there is
no arguments passed?
Friday, 13 September 2013
Thursday, 12 September 2013
How to exit SurfaceView?
How to exit SurfaceView?
I draw something on canvas using SurfaceView. How can I define a way to
cancelling the surfaceView once the user is done? Below is my SurfaceView
implementation. The DrawOnTop class has the onDraw() but I initialize all
the variables in Preview class.
public class Preview extends SurfaceView implements SurfaceHolder.Callback {
SurfaceHolder mHolder;
DrawOnTop mDrawOnTop;
boolean mFinished;
Preview(Context context, DrawOnTop drawOnTop) {
super(context);
mDrawOnTop = drawOnTop;
mFinished = false;
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void surfaceCreated(SurfaceHolder holder) {
//I set the bitmaps etc here
mDrawOnTop.mBitmap = Bitmap.createBitmap(mDrawOnTop.mImageWidth,
mDrawOnTop.mImageHeight, Bitmap.Config.ARGB_8888);
mDrawOnTop.mBitmap.setPixels(mDrawOnTop.mRGBData, 0,
mDrawOnTop.mImageWidth, 0, 0, mDrawOnTop.mImageWidth,
mDrawOnTop.mImageHeight);
mDrawOnTop.invalidate();
}
public void surfaceDestroyed(SurfaceHolder holder) {
mFinished = true;
}
public void surfaceChanged(SurfaceHolder holder, int format, int w,
int h) {
}
}
I draw something on canvas using SurfaceView. How can I define a way to
cancelling the surfaceView once the user is done? Below is my SurfaceView
implementation. The DrawOnTop class has the onDraw() but I initialize all
the variables in Preview class.
public class Preview extends SurfaceView implements SurfaceHolder.Callback {
SurfaceHolder mHolder;
DrawOnTop mDrawOnTop;
boolean mFinished;
Preview(Context context, DrawOnTop drawOnTop) {
super(context);
mDrawOnTop = drawOnTop;
mFinished = false;
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void surfaceCreated(SurfaceHolder holder) {
//I set the bitmaps etc here
mDrawOnTop.mBitmap = Bitmap.createBitmap(mDrawOnTop.mImageWidth,
mDrawOnTop.mImageHeight, Bitmap.Config.ARGB_8888);
mDrawOnTop.mBitmap.setPixels(mDrawOnTop.mRGBData, 0,
mDrawOnTop.mImageWidth, 0, 0, mDrawOnTop.mImageWidth,
mDrawOnTop.mImageHeight);
mDrawOnTop.invalidate();
}
public void surfaceDestroyed(SurfaceHolder holder) {
mFinished = true;
}
public void surfaceChanged(SurfaceHolder holder, int format, int w,
int h) {
}
}
Matching numbers inside nested numbered groups
Matching numbers inside nested numbered groups
I am trying to find and capture all numbers inside ( and ) separately in
my data, ignoring the rest of the numbers.
My data looks like this
21 [42] (12) 19 25 [44] (25 26 27) 17 (14 3) 8 1 6 (19)
So I want to find matches for 12, 25, 26, 27, 14, 3 and 19
I tried doing \((\d+)\)* but this only gives me 12, 25, 14, 19
Any help is appreciated.
I am trying to find and capture all numbers inside ( and ) separately in
my data, ignoring the rest of the numbers.
My data looks like this
21 [42] (12) 19 25 [44] (25 26 27) 17 (14 3) 8 1 6 (19)
So I want to find matches for 12, 25, 26, 27, 14, 3 and 19
I tried doing \((\d+)\)* but this only gives me 12, 25, 14, 19
Any help is appreciated.
How many times does this code run?
How many times does this code run?
I'm testing some code and I assume the code below will run the
'somefunction()' every 2 seconds. However, it only runs once..... why is
this?
$(document).ready(function () {window.setInterval(somefuntion(),
2000);});
I'm testing some code and I assume the code below will run the
'somefunction()' every 2 seconds. However, it only runs once..... why is
this?
$(document).ready(function () {window.setInterval(somefuntion(),
2000);});
Apache/WordPress Cache Not Refreshing On My IP
Apache/WordPress Cache Not Refreshing On My IP
So I was trying out a caching plugin on my WP site. I had installed it
after my home page never changed (forever static). Uninstalled the plugin,
tried moving the WP files to another sub-domain, and my frontpage still
was static. Even on another sub-domain. This only had happened when I
changed some .htaccess settings for it, but I had already reverted these.
I've tried emptying my local cache. Page is still static. Does anyone know
what is going on?
I also figured out, it only is that page on my IP. And only that page.
Doesn't matter if the file exists, still makes the same old page show up.
Any help?
So I was trying out a caching plugin on my WP site. I had installed it
after my home page never changed (forever static). Uninstalled the plugin,
tried moving the WP files to another sub-domain, and my frontpage still
was static. Even on another sub-domain. This only had happened when I
changed some .htaccess settings for it, but I had already reverted these.
I've tried emptying my local cache. Page is still static. Does anyone know
what is going on?
I also figured out, it only is that page on my IP. And only that page.
Doesn't matter if the file exists, still makes the same old page show up.
Any help?
How to find n+n/2+n/3+.....+n/n in C efficiently?
How to find n+n/2+n/3+.....+n/n in C efficiently?
how to find sum n+n/2+n/3+....+n/n in C efficiently???
I need an algorithm better than O(n).
Can we calculate it better than ?
Any help is appreciated.
how to find sum n+n/2+n/3+....+n/n in C efficiently???
I need an algorithm better than O(n).
Can we calculate it better than ?
Any help is appreciated.
Micro-optimization of IF statement
Micro-optimization of IF statement
I always look into how to optimize the code more and more every day, and
how I can learn to code faster code.
Looking at some minified JS online I notice the change of a few IF into a
statement and I thought that it might be a very good idea to start using
it in PHP as well.
<?php
if(!isset($myVar) || $myVar == 'val'){
$myVar = 'oldVal';
}
if(isset($myVar) && $myVar == 'oldVal'){
$myVar = 'newVal';
}
?>
into
<?php
(!isset($myVar) || $myVar == 'val') && $myVar = 'oldVal';
isset($myVar) && $myVar == 'oldVal' && $myVar = 'newVal';
?>
As I like the new syntax, I started to use it more and more thinking to
save processing time, but do I really save any or there is no difference
internally between the two ?
(The example code is just an EXAMPLE to only show the technique)
I always look into how to optimize the code more and more every day, and
how I can learn to code faster code.
Looking at some minified JS online I notice the change of a few IF into a
statement and I thought that it might be a very good idea to start using
it in PHP as well.
<?php
if(!isset($myVar) || $myVar == 'val'){
$myVar = 'oldVal';
}
if(isset($myVar) && $myVar == 'oldVal'){
$myVar = 'newVal';
}
?>
into
<?php
(!isset($myVar) || $myVar == 'val') && $myVar = 'oldVal';
isset($myVar) && $myVar == 'oldVal' && $myVar = 'newVal';
?>
As I like the new syntax, I started to use it more and more thinking to
save processing time, but do I really save any or there is no difference
internally between the two ?
(The example code is just an EXAMPLE to only show the technique)
Subscribe to:
Posts (Atom)