Wednesday, 11 September 2013

subsetting matrix with id from another matrix

subsetting matrix with id from another matrix

I am just beginning to learn R, so I apologize in advance for the
ambiguity of my syntax as well as the apparent simplicity. Also, if there
is a better way of doing the below, I really appreciate any suggestions
and recommendations.
I would like to subset the data of one matrix using data in a second
matrix. The columns of one matrix is labeled. For example,
area1 <-
c(9836374,635440,23018,833696,936079,1472449,879042,220539,870581,217418,552303,269359,833696,936079,1472449,879042,220539,870581,
833696,936079,1472449,879042,220539,870581)
id <- c(1,2,5,30,31,34,1,2,5,1,2,5,1,2,5,30,31,34,51,52,55,81,82,85)
mat1 <- matrix(area1, ncol=3, byrow=T)
mat2 <- matrix(id, ncol=3, byrow=T)
dimnames(mat1) <-list(NULL, c("a1","a2","a3"))
mat2 contains the ids for mat1, so the dimensions of the matrix are the
same (i.e., mat1[1,1] identifies mat2[1,1]. What I want is to create
submatrices of mat1 when the row with values c(1, 2, 5) shows up in mat2.
In this present mini example, submatrix 1 would have 2 rows of data,
submatrix 2 and 3 have 1 row each, and submatrix 4 would have 4 rows of
data from mat1. The number of rows between subsequent rows with 1,3,5
varies. Does this make sense?
Originally, the matrices were transformed from a dataframe, with id in one
column and area in a second column. I couldn't find a way to subset
variable rows between rows of 1 within a dataframe, which is why I
switched to a matrix.

C# out of memory exception in wpf application

C# out of memory exception in wpf application

I am creating an application where I am getting live images from camera
and trying to put that on image control of wpf. But after some time it
will start throwing out of memory exception.
here is the code
try
{
imgControl.Dispatcher.Invoke(DispatcherPriority.Normal,
(Action)(() =>
{
using (MemoryStream memory = new MemoryStream())
{
lastImage.Save(memory, ImageFormat.Png);
memory.Position = 0;
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = memory;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
ImageSource imageSource = bitmapImage;
imgControl.Source = imageSource;
}
}));
}
catch (Exception ex)
{
//exception handling
}
is there a way I can reduce memory consumption and find a work around for
this out of memory exception?
Thanks

How can I append a leading 0 in MVC 4 DateTime in an EditorFor HTMLHelper?

How can I append a leading 0 in MVC 4 DateTime in an EditorFor HTMLHelper?

I'm running into an issue in my MVC 4 application when using an input mask
in my edit view for a DateTime. The input mask that I'm using forces an
input to be formatted like: "MM/dd/yyyy HH:mm". This works great until an
edit it attempted.
An input of "09/11/2013 07:00" ends up looking like "91/12/0137 30:00" in
my EditorFor helper.
How can I force a "0" to append to a month and hour less than two digits?

Android:How to show Time Counter in Decimal Format

Android:How to show Time Counter in Decimal Format

This question may make confusion ,so i am explain it below.
I have already create a counter for counting the time(Like how much time
people works).Its working fine with single characters (like 0:0:0), but i
want to display it in decimal (like 00:00:00). I had tried the below code,
but it works like the before .No changes yet.
private void timer() {
int locSec = 0;
int locMin = 0;
int locHr = 0;
DecimalFormat format = new DecimalFormat("00");
String formatSecond = format.format(locSec);
String formatMinute = format.format(locMin);
String formatHour = format.format(locHr);
sec = Integer.parseInt(formatSecond);
min = Integer.parseInt(formatMinute);
hr = Integer.parseInt(formatHour);
Timer T = new Timer();
timeCounter = (TextView) findViewById(R.id.tvDisplayCountDown);
T.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
timeCounter.setText("time= " + hr + ":"+ min + ":"+ sec);
sec++;
if(sec > 59){
sec = 0;
min = min + 1;
}
}
});
}
}, 1000, 1000);
}
where hr, min and sec are global variables and assigned as 0. But the
output is same as before: 0:0:0
helps and suggestions are appreciable.
Thank You

Tuesday, 10 September 2013

Code conversion from MVC to C# asp.net webforms

Code conversion from MVC to C# asp.net webforms

I found a nice code to resize image on server, But code is for MCV.
I have no experience in C# would like to know what change i need to make
to this code so that it i can call from image object of webform it self.
<img src="@Url.Action("ResizeImage", "Controller", new { urlImage =
"<url_image>", width = 35 })" />
public ActionResult ResizeImage(string imageUrl, int width)
{
WebImage wImage = new WebImage(imageUrl);
wImage = WebImageExtension.Resize(wImage, width);
return File(wImage.GetBytes(), "image/png");
}
public static class WebImageExtension
{
private static readonly IDictionary<string, ImageFormat>
TransparencyFormats =
new Dictionary<string,
ImageFormat>(StringComparer.OrdinalIgnoreCase) { { "png",
ImageFormat.Png }, { "gif", ImageFormat.Gif } };
public static WebImage Resize(this WebImage image, int width)
{
double aspectRatio = (double)image.Width / image.Height;
var height = Convert.ToInt32(width / aspectRatio);
ImageFormat format;
if (!TransparencyFormats.TryGetValue(image.ImageFormat.ToLower(),
out format))
{
return image.Resize(width, height);
}
using (Image resizedImage = new Bitmap(width, height))
{
using (var source = new Bitmap(new
MemoryStream(image.GetBytes())))
{
using (Graphics g = Graphics.FromImage(resizedImage))
{
g.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(source, 0, 0, width, height);
}
}
using (var ms = new MemoryStream())
{
resizedImage.Save(ms, format);
return new WebImage(ms.ToArray());
}
}
}
}

how t o display image from url use pligg cms2.0

how t o display image from url use pligg cms2.0

the modifier $string =
preg_replace('/(http://|https://){1}.+?.(jpg|gif|bmp|bnp|png)$/is','<img
src="$0" alt="" />',$string);
return $string;
How can I write in the link_summary.tpl
thanks

I don't know how to install ThreeJSExporter.ms

I don't know how to install ThreeJSExporter.ms

I have no idea where I should place this script or how I should execute it?
My end goal is to be able to export 3ds files directly to JSON to be
imported into threejs.
I'm a noob with 3ds so please forgive my ignorance.