Thursday, 3 October 2013

How to refer to figure I clicked to change its properties and move it?

How to refer to figure I clicked to change its properties and move it?

I have a figure in canvas in WPF application. This figure is generated by
program (I click a button and then a figure appears). How to order the
Figure_MouseLeftButtonDown function to change some properties of THIS
figure? Also I want to move this figure by dragging. Now I have something
like this: var ell = new Ellipse() { Name = "FirstEllipse", Width = 150,
Height = 100, Margin = new Thickness(200, 150, 0, 0), Fill = Brushes.Red
}; ell.MouseLeftButtonDown += Ellipse_MouseLeftButtonDown;
canvas.Children.Add(ell); private void Figure_MouseLeftButtonDown(object
sender, MouseButtonEventArgs e) { sender.SetValue(Ellipse.FillProperty,
Brushes.Aquamarine);}

Wednesday, 2 October 2013

needed to remove image extension using htaccess

needed to remove image extension using htaccess

I need to change or redirect the "example.com/photos/logo.jpg" to
"example.com/photos/logo" when user comes from google image search.
Therefore I've used RewriteCond %{REQUEST_URI}
photos/.*.(gif|jpg|jpeg|png)$ [NC] RewriteCond %{HTTP_REFERER}
^http://www.google.[a-z]{2,4}(.[a-z]{2,4})?/url\?.*$ [NC,OR] RewriteCond
%{HTTP_REFERER} ^http://www.bing.com/images/search?q=\?.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} !^http://example.com/.*$ [NC] RewriteCond
%{HTTP_USER_AGENT} !(.bot.|slurp) [NC] RewriteRule ^gallery/(.*) /$1
[L,R=301]
Thank you.

Approach while learning Algorithms

Approach while learning Algorithms

I am learning algorithms and came to this Hanoi Tower. I know how to do
that practically. But I am unable to code it. I haven't read the given
code yet. I am trying it first myself. What should be my approach-keep
trying or read the given code or something else?
Should this approach be followed with all the algorithms?

FFmpeg on Android - Unable to find a suitable output format

FFmpeg on Android - Unable to find a suitable output format

I want to reduce the resolution of a video before edit it, so I´m using
ffmpeg on android. I´m using the executable/binary file of ffmpeg and I´m
calling my ffmpeg commands like that:
./ffmpeg -i /sdcard/dcim/video.mp4 -s 320x240 -r 10 -y /sdcard/output.mp4
But when I try this command I get this error:
Unable to find a suitable output format for /sdcard/output.mp4
This is the output when I use the adb shell:
The only action I have been able to do is to extract the audio of a video
and save it as a mp3 using this command:
./ffmpeg -i /sdcard/dcim/video.mp4 -y /sdcard/output.mp3
That works well but this is the only action I can do... Any idea of why I
can´t convert a video? (I can´t copy it too) Thanks!!

Collect a specific text string from a very large text string in SQL Server

Collect a specific text string from a very large text string in SQL Server

I have a very large text string in a column (column name: path) of a table
(table name: KYC_Path). The table basically contains very large text
string of image paths from which I need to extract a specific number (file
number). The text strings look like this:
F:\Original\15561 done\sohan1
15561\output_after_name_mapping\01710043429(1).jpg
T:\ALL BACKUP\BACK UP 1TB(SERVER)\ALL SCANNED FILES(sohan)\01832876657
(1).JPG
T:\ALL BACKUP\form 2TB passport HDD\All backup\Afren\24313\24313
Nupur_1box 651\output_after_name_mapping\01918082763(1).jpg
T:\ALL BACKUP\zaman all scan\16830 noboni1
box548\output_after_name_mapping\01823152145(1).jpg
I need to collect just following numbers (file name with out the (1).jpg
part), so that my new column will look like this:
01710043429
01832876657
01918082763
01823152145
I have already devised a method where use following formula:
select (right ([path],18)) as 'wallet_path', [path] into KYCPathNew
from [dbo].[KYCPath]
select (left ([wallet_path],11)) as 'wallet_path_new', [path] into
KYCPathNew2
from [dbo].[KYCPathNew]
However that gives some issues to some rows where file name do not come
correctly due to spaces between numbers (01823152145) and file extension
((1).jpg). And misses one or two characters from the file name.
Is there any other way so that I can collect all the file names more
efficiently? Can I make SQL Server find the last back slash and then take
11 digits from there? How?

Tuesday, 1 October 2013

About SQL SERVER LEFT JOIN and Group by

About SQL SERVER LEFT JOIN and Group by

I have two tables,Blog table has a FK BlogTagID column point to BlogTag
table:
Blog table:
BlogID BlogTagID BlogTitle
1 2 test1
2 1 test2
3 2 test3
BlogTag table:
BlogTagID BlogTagName
1 JAVA
2 .NET
3 PHP
I would like to get the result:
BlogTagName count
JAVA 1
.NET 2
PHP 0
How to get this?Thank you very much!

Hide/unhide table row given the row index and table ID

Hide/unhide table row given the row index and table ID

Currently I have this code to delete a table row:
var remove = document.getElementById(rid);
if(remove!=null){
var v = remove.parentNode.parentNode.rowIndex;
document.getElementById(tid).deleteRow(v);
}
However, instead of delete it, I'd just like to hide it. What's a good way
to do this?
Also, in the future, I'm going to want to 'unhide' it at user request, so
how can I check if it has been hidden? The if(remove!=null) is what
checked if a row was already removed, so I'd need something similar. If
the row is hidden, I would unhide it.
Thank you for your time.

PS6000 showing packet errors but no errors appear on the switch

PS6000 showing packet errors but no errors appear on the switch

We have a loaned PS6000E SAN that we are using to relocate our iSCSI LUNs
off our current PS4000E SAN to upgrade it from Seagate Moose drives under
a proactive replacement plan by Dell. We've connected it up to our stack
of Dell PowerConnect 6248 switches that make up our client stack (because
our Cisco stack is currently full - another is on order so we can extend
it and give our server network room to grow) and while it connects to our
existing stack and we've successfully moved a LUN across, there are
numerous errors on the Ethernet connectors that are giving us cause for
concern.
Our other two SANs are connected to our Cisco stack and show no errors at
all. They connect to the Dell stack via a fibre link which does not have
jumbo frames turned on.
We are not particularly keen on moving across the remainder of the LUNs
until we resolve this issue. Is there something on the switch we need to
configure that I'm missing? Should I not be using the PC6248s for this and
should I wait for our new Cisco switch to arrive? Am I getting myself into
a fuss over nothing?
EDIT: I noticed spanning tree was turned on for the ports and turned off
for the SAN ports on the Cisco switch. Turning it off has done nothing to
stem the errors coming from this thing. I ensured that the MTU was 9000
across the board and it hasn't made a difference. All cables are CAT6.
Turning off LLDP made no difference. Someone requested a diagram, which is
below.

What does the second index mean in probability distribution in finite events space definition – math.stackexchange.com

What does the second index mean in probability distribution in finite
events space definition – math.stackexchange.com

In one of the books I have found such definition: Let $\Omega$ be
countable space $$\Omega=\{ \omega_1, \omega_2,... \}$$ For single element
events function P is defined as follows: $$ P(\{ ...

Monday, 30 September 2013

Why is there no "remainder" in multiplication – math.stackexchange.com

Why is there no "remainder" in multiplication – math.stackexchange.com

With division, you can have a remainder (such as $5/2=2$ remainder $1$).
Now my six year old son has asked me "Why is there no remainder with
multiplication"? The obvious answer is "because it ...

How much has "True North" shifted in the last few years and would this affect aeronautics=?iso-8859-1?Q?=3F_=96_skeptics.stackexchange.com?=

How much has "True North" shifted in the last few years and would this
affect aeronautics? – skeptics.stackexchange.com

I was talking to a contractor at a major U.S. airport, a Project Manager
who told that they were moving the runways due to the shifting of 'True
North'. I have heard that the poles have shifted even …

Training/skills to become a good QA engineer

Training/skills to become a good QA engineer

I've done a search for similar questions before but it seems they only
mention a few books or talk about soft skills, they seem to like training
resources for becoming a tester and there is little to no mention of
training resources for test automation.
So for background I'm a CS grad who doesn't seem to have a great ability
to develop, at least not yet. I went into finance and worked for two years
in support/development and got on very well, unfortunately my application
got quite popular and therefore the team was heavily regulated, this meant
I went to strictly support and low level so I wasn't happy with the lack
of complexity.
As a result I decided to try a different industry and have went back to
technology and got a job as a QA engineer. I am fully aware I cannot rely
solely on my employer to provide the skills necessary to become a good QA
Engineer.
Therefore I wish to firstly cement soft skills as a good QA tester which I
believe I already have. i.e. an eye for detail, enjoy a good puzzle. What
technical skills do people feel are required to be a good 'manual' tester?
Lastly the main reason I took this jump was to get into automated testing
as I believe it will allow a jump in complexity and perhaps a side move to
development when I'm good enough. Where do I start in becoming good at
automated testing?
The standard advice for a dev is to start developing personal projects?
What about a tester? Is it the same so then you can test your project
thoroughly? I've often seen it said you should be testing OTHER peoples
code mainly. So how can I get this exposure?
Just for additional info, I've been researching a bit myself and have come
across a few products like selenium to play with and reading the google
testing blog. On top of this I've started two udacity classes, one for
software testing and one for debugging. Any further suggestions? Any
decent books to help me feel a little less lost in my current situation?
Thanks for any advice you can provide

Clean IOS xcode target in command line

Clean IOS xcode target in command line

I am building/running an IOS app from command line with following commands:
xcodebuild -sdk "${TARGET_SDK}" -xcconfig "${CONFIG_FILE_PATH}"
-configuration Release
/usr/bin/xcrun -sdk "${TARGET_SDK}" PackageApplication -v
"${PROJECT_BUILD_DIR}/${APPLICATION_NAME}.app" -o
"${OUTPUT_DIR}/${APPLICATION_NAME}.ipa"
Is there any command to clean the targets. or these commands take care of
cleaning themselves.

Sunday, 29 September 2013

Using Lisp's CFFI defcstruct with OpenCV's cvSize and CvSize struct?

Using Lisp's CFFI defcstruct with OpenCV's cvSize and CvSize struct?

I have half successfully wrapped the OpenCV cvSize function
CV_INLINE CvSize cvSize( int width, int height )
and I would like to acces the slots of the defctruct cv-size but could use
help here are my steps:
i created a cl-opencv-glue.c file and adding this
CvSize cvSize_glue(int width, int height)
{
return cvSize(width, height);
}
then created cl-opencv-glue.h file and adding this:
/* CvSize cvSize(int width, int height) */
CvSize cvSize_glue(int width, int height);
then builded a
/usr/local/lib/libcl-opencv-glue.so
which builds successfully
then created a wrapper for the glue function like this:
;; CvSize cvSize(int width, int height)
(cffi:defcfun ("cvSize_glue" size) (:pointer (:struct cv-size))
"Constructs CvSize structure."
(width :int)
(height :int))
then i can run this program successfully:
(defun init-image-header-example (&optional (width 640)
(height 480))
"Initializes an image header that was previously allocated."
(let* ((img-size (size width height))
(image (create-image img-size +ipl-depth-8u+ 3))
(image-re-init (init-image-header image img-size
+ipl-depth-8u+ 3
+ipl-origin-tl+ 4))
(window-name "INIT-IMAGE-HEADER Example"))
(named-window window-name +window-normal+)
(move-window window-name 702 285)
(create-data image-re-init)
(show-image window-name image-re-init)
(loop while (not (= (wait-key 0) 27)))
(release-image image-re-init)
(destroy-window window-name)))
the
(img-size (size width height))
line successfully creates a size structure for the:
(create-image img-size +ipl-depth-8u+ 3)
which is wrapped like this
;; IplImage* cvCreateImage(CvSize size, int depth, int channels)
(cffi:defcfun ("cvCreateImage" create-image) (:pointer (:struct ipl-image))
(size (:pointer (:struct cv-size)))
(depth :int)
(channels :int))
now for testing i create a size struct at the repl(w/ output):
CL-OPENCV> (defparameter size (size 1280 1024))
SIZE
CL-OPENCV> size
#.(SB-SYS:INT-SAP #X40000000500)
CL-OPENCV>
now id like to access slots of the size pointer so i can get size.width
and size.height so i can create a size-width and size-height function in
lisp
so i attempt to get at the slots by running at the repl(w/ output)
CL-OPENCV> (cffi:with-foreign-object (size '(:struct cv-size))
;; Initialize the slots
;; Return a list with the coordinates
(cffi:with-foreign-slots ((width height) size (:struct cv-size))
(list width height)))
Output > (754484 0)
and get this
(754484 0)
my defcstruct created by swig is
(cffi:defcstruct cv-size
(width :int)
(height :int))
and the defined Opencv struct is this(along with the CV_INLINE for
reference):
here is how they are defined in
/home/w/Downloads/opencv-2.4.6.1/modules/core/include/opencv2/core/types_c.h:
typedef struct CvSize
{
int width;
int height;
}
CvSize;
CV_INLINE CvSize cvSize( int width, int height )
{
CvSize s;
s.width = width;
s.height = height;
return s;
}
so i change my glue.c to(and rebuild .so)
CvSize cvSize_glue(int width, int height)
{
cvSize(width, height);
}
i re-open emacs and run the (init-image-header-example) function above and
it runs so i rerun the above repl test(shown below w/ output)
(cffi:with-foreign-object (size '(:struct cv-size))
;; Initialize the slots
;; Return a list with the coordinates
(cffi:with-foreign-slots ((width height) size (:struct cv-size))
(list width height)))
Output > (338509 0)
compared to above test of
(754484 0)
it is similar but different the 754484 changes evertime regardless of
whether return is there or not I tried every variation of the defcstruct
cv-size parameter i/e replacing the cv-size in
(cffi:defcstruct cv-size
(width :int)
(height :int))
with all the below:
:struct cv-size, (:struct cv-size), (:pointer (:struct cv-size)), :struct
cv-size
and get errors for all....(didnt include errors for sake of length of
post(but will if neccesary)) i then try the below to access the slots
(shown /w output)
CL-OPENCV> (defparameter size (size 1280 1024))
SIZE
CL-OPENCV> size
#.(SB-SYS:INT-SAP #X40000000500)
CL-OPENCV> (cffi:with-foreign-slots ((width height)
size (:struct cv-size))
(format t "width = ~a~%height = ~a~%"
width height ))
but get a
[Condition of type SB-SYS:MEMORY-FAULT-ERROR]
after last entry
Any help on this would be much appreciated...

PHP File request from url directory

PHP File request from url directory

This is probably a very easy question. Anyway how do you use variables
from a url without requests. For example:
www.mysite.com/get.php/id/123
Then the page retrieves id 123 from a database.
How is this done? Thanks in advance!

Generate multipart/mixed HTTP request

Generate multipart/mixed HTTP request

I would like to POST a multipart/mixed request, where one part is of type
application/json and the other of type video/mp4 (Content-Type: video/mp4;
charset=binary). How can I easily build such POST request in python?

Ensuring a transaction within a method with ActiveRecord

Ensuring a transaction within a method with ActiveRecord

I have a situation in which I would like a method to work within a
transaction, but only if a transaction has not already been started.
Here's a contrived example to distill what I'm talking about:
class ConductBusinessLogic
def initialize(params)
@params = params
end
def process!
ActiveRecord::Base.transaction do
ModelA.create_multiple(params[:model_a])
ModelB.create_multiple(params[:model_a])
end
end
end
class ModelA < ActiveRecord::Base
def self.create_multiple(params)
# I'd like the below to be more like "ensure_transaction"
ActiveRecord::Base.transaction do
params.each { |p| create(p) }
end
end
end
class ModelB < ActiveRecord::Base
def self.create_multiple(params)
# Again, a transaction here is only necessary if one has not already
been started
ActiveRecord::Base.transaction do
params.each { |p| create(p) }
end
end
end
Basically, I don't want these to act as nested transactions. I want the
.create_multiple methods to only start transactions if they are not
already called within a transaction, such as through
ConductBusinessLogic#process!. If the model methods are called by
themselves, they should start their own transaction, but if they are
already being called inside a transaction, as through
ConductBusinessLogic#process!, they should not nest a sub-transaction.
I don't know of a way in which Rails provides this out of the box. If I
run the above code as-is and a rollback is triggered by one of the model
methods, the whole transaction will still go through because the
sub-transaction swallows the ActiveRecord::Rollback exception. If I use
the requires_new option on the sub-transactions, savepoints will be used
to simulate nested transactions, and only that sub-transaction will
actually be rolled back. The behavior I would like would be something to
the effect of ActiveRecord::Base.ensure_transaction, such that a new
transaction is started only if there isn't already an outer transaction,
so that any sub-transaction can trigger a rollback on the entire outer
transaction. This would allow these methods to be transactional on their
own, but defer to a parent transaction if there is one.
Is there a built-in way to achieve this behavior, and if not, is there a
gem or patch that will work?

Saturday, 28 September 2013

Issue with PDO select query: unknown error

Issue with PDO select query: unknown error

I'm trying to get comfortable with PDO but can't get this to work.
Below is a script for a basic search box:
<?php
$sth= new connection();
if (isset($_GET['search'])) {
$search_query = $_GET['search'];
$search_query = htmlentities($search_query)
$result=$sth->con->prepare("SELECT firstname, lastname FROM users WHERE
firstname LIKE '%" . $search_query . "%' OR
lastname LIKE '%" . $search_query . "%' OR
LIMIT 25");
$result->bindParam(1, $search_query, PDO::PARAM_STR, 12);
foreach ($result as $row) {
$firstname = $row["firstname"];
$lastname = $row["lastname"];
if (!($result) == 0) {
?>
<div="foo">Here are your results:</div>
<?php
} else {
?>
<div="bar">No results!</div>
<?php
}
}
?>
Here's the error that I get:
fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[]:
<<Unknown error>>
What am I doing wrong ?
ps: $sth works fine with other queries.

declaring a variable within conditional expressions (ternary operator)

declaring a variable within conditional expressions (ternary operator)

Is it possible to declare the variable within a conditional expression?
for example: The code below return a syntax error (because I've declared
the variable x within the conditional expression?).
var a = document.getElementById("userData");
var d = a.value;
function() {
(d.length>15)?(
alert("your input was too long")):(
var x = parseInt(d).toString(2),
a.value=x
);
}
obviously this can be fixed by simply adding var x; outside the statement,
but is it possible for variables to be declared here?

Why files creatied with Java FileOutputStream on Android are visible on my pc throught USB after few ubs reconnectonions (+up to few...

Why files creatied with Java FileOutputStream on Android are visible on my
pc throught USB after few ubs reconnectonions (+up to few...

I have code like this: File file = new
File(Environment.getExternalStorageDirectory(), fileName);
FileOutputStream os = null; try { os = new FileOutputStream(file); } catch
(FileNotFoundException e) { System.err.println("Error while creating
FileOutputStream"); e.printStackTrace(); }
os.write("something".getBytes());
and when i create file on my HTC desire x i have to disconnect usb, wait
few minutes, connect it again to see it in windows explorer. Why it's like
that? And how can i prevent it?