Wednesday, May 23, 2012

filtering non referenced member nodes using XSLT

An OpenStreetMap xml document is composed (among other things) of a set of "node" elements and a set of "way" elements.



The "node" elements can (optionally) nest "tag" elements.



The "way" elements are composed by an ordered list of "node" elements, referenced by the nested elements "nd", with their attribute "ref" pointing to the attribute "id" at the "node" elements.



Here an example:



<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="CGImap 0.0.2">
<node id="1726631203" lat="50.8500083" lon="4.3553223" visible="true" version="6" changeset="9938190" timestamp="2011-11-24T22:05:32Z"/>
...
<way id="160611697" user="toSc" uid="246723" visible="true" version="1" changeset="11385198" timestamp="2012-04-22T14:57:19Z">
<nd ref="1726631203"/>
<nd ref="1726631223"/>
<nd ref="1726631213"/>
<nd ref="1726631205"/>
<nd ref="1726631185"/>
<nd ref="1726631203"/>
</way>
...
</osm>


My question is how, using XSLT, could I do the following transformation ?




  • Filtering all the node elements that are not referenced by any way element.

  • Filtering the way elements that reference node elements not included in the source xml document.

  • Changing the attribute "visible" to "false", to any "node" element not having "tag" children elements.



Any other elements should remain in the generated xml.





SQL Compact Edition (CE) and password complexity requirements

In Windows 7 we have group policies enforcing password complexity requirements which demands "better" password for SQL server express.



Does this impact SQL CE as well?





PHPass implementation in java

I want to use PHPass encryption technique in java. Is there any way we can achieve it?





How to sum two lists element-wise

I want to parse a file line by line, each of which containing two integers, then sum these values in two distinct variables. My naive approach was like this:



my $i = 0;
my $j = 0;
foreach my $line (<INFILE>)
{
($i, $j) += ($line =~ /(\d+)\t(\d+)/);
}


But it yields the following warning:




Useless use of private variable in void context




hinting that resorting to the += operator triggers evaluation of the left-hand side in scalar instead of list context (please correct me if I'm wrong on this point).



Is it possible to achieve this elegantly (possibly in one line) without resorting to arrays or intermediate variables?






Related question: How can I sum arrays element-wise in Perl?





Non capturing group issue

Why following return ["vddv"] instead of ["dd"]:



"aaavddv".match(/(?:v).*(?:v)/)




jquery rounded corners on first and last li

How do i create rounded top left and bottom left corners of the first LI and rounded top right and bottom right of the last li using jquery?



I understand that i could use border-radius but that wont be a cross browser solution.



Here is what i have started: http://jsfiddle.net/c7NyZ/1/



If you can add a resource to the jsfiddle and update it id be greatful.



HTML:



<div id="new-menu-upper">
<ul id="top-nav">
<li><a href="/t-topnavlink.aspx">menu item 1</a></li>
<li><a href="/t-topnavlink.aspx">menu item 2</a></li>
<li><a href="/t-topnavlink.aspx">menu item 3</a></li>
<li><a href="/t-topnavlink.aspx">menu item 4</a></li>
<li><a href="/t-topnavlink.aspx">menu item 5</a></li>
<li><a href="/t-topnavlink.aspx">menu item 6</a></li>
</ul>
</div>


CSS:



div#new-menu-upper {
border: 0 solid red;
height: 40px;
margin: 0 5px 10px;
padding-top: 63px;
}
ul#top-nav li {
background-image: url("http://i47.tinypic.com/21nqxjc.png");
background-repeat: repeat;
border-right: 2px solid lightgrey;
float: left;
height: 41px;
width: 156px;
}
ul#top-nav li a {
color: White;
display: inline-block;
font-family: Arial;
font-size: 12px;
font-weight: bold;
letter-spacing: 1px;
padding-left: 38px;
padding-top: 12px;
text-transform: uppercase;
}


EDIT: IT HAS TO BE A CROSS BROWSER SOLUTION, MEANING IT HAS TO WORK WITH MIN IE7
*EDIT: ADDED JQUERY.CORNERS RESOURCE TO JSFIDDLE AND TRIED TO MAKE FIRST LI RENDER WITH CORNER BUT ITS NOT WORKING - PLEASE CAN YOU HELP - http://jsfiddle.net/c7NyZ/4/ *





Using "libs" and "lib" directories?

I use the directory "libs" for a native libs, and "lib" for jars. Ant compilation works fine, if to override the property "jar.libs.dir=lib" in local.properties file. looks good. But a jars from "lib" directory was not included into APK file.



You can see base build.xml (android_sdk/tools/ant/build.xml)



            <classpath>
<fileset dir="${extensible.libs.classpath}" includes="*.jar" />
</classpath>


where extensible.libs.classpath - is jar.libs.dir.



How to fix it? I can't to use only one "libs" dir.



I saw the log file (classes.dex.d), my jars are not included. but if I use "jar.libs.dir=lib" AND move the jars into "libs" - works fine! I don't understand this regularity





Is this thread safe code when I receive multiple client connections?

I am using this code for receiving log messages from my clients I receive more than 1000 connections per minute. I want to increase my log handling. I did with java threading. I have a doubt if it receive multiple client connection what happens. Is this thread safe? Can you give your suggestions. It will help to improve this code.



  public class CentralizedLogging implements Runnable {

/**
* Field logDir - Where the plugin logs can be stored .
*/
public static String logDir;

/**
* Field server - Server Socket .
*/
ServerSocket server = null;
/**
* Field LOGGER.
*/
public static final Logger LOGGER = Logger.getLogger(CentralizedLogging.class.getName());

/**
* @param port - Port which the server is binds .
* @param logDir String
*/
public CentralizedLogging(String logDir , int port){
try {
this.logDir = logDir;
server = new ServerSocket(port);
} catch (IOException e) {
LOGGER.log(Level.SEVERE,"It may be due to given port already binds with another process , reason {0}",new Object[]{e});
}
}

/**
* Extension point for central log server . To start receiving connections from remote end .
*/
public void run(){
while(true){
try{
new LogWriter(server.accept());
}catch (Exception e) {
LogWriter.log("Interrupted exception " + e.getMessage());
}
}
}

/**
* args[0] - logging location .
* args[1] - which port the server can start. It must be a integer.
* @param args
*/
public static void main(String[] args) {
try{
CentralizedLogging logServer = new CentralizedLogging(args[0], Integer.parseInt(args[1]));
}catch(Exception e){
LOGGER.log(Level.SEVERE,"Unable to start log server from this location : {0} , port : {1} , This may be due to given port is not a number or this port is not free exception trace {2}", new Object[]{args[0],args[1],e});
}
}


}



/**
* Used for writing client packets into logs Dir .
*/
class LogWriter implements Runnable{

/**
* Field client - Socket Client .
*/
Socket client;

/**
* Constructor for LogWriter.
* @param client Socket
* @throws IOException
*/
public LogWriter(Socket client) {
this.client = client;
}

public void run(){
write();
try{
this.client.close();
}catch(IOException io){
System.out.println("Error while closing connection , reason "+io);
}
}

/**
* Method write.
*/
public void write(){
try{
String date = new SimpleDateFormat("yyyy_MM_dd").format(new Date());
File file = new File(CentralizedLogging.logDir+client.getInetAddress().getHostName() + "_"+ date+".log");
write(client.getInputStream(),file);
}catch(Exception e){
log("Error in writing logs :: Host Name "+client.getInetAddress().getHostName() +" , Occured Time "+System.currentTimeMillis()+", Reason "+e.getMessage()+"\n\n");
}
}

/**
* Method write.
* @param in InputStream
* @param file File
* @throws Exception
*/
public synchronized static void write(InputStream in , File file) throws Exception{
RandomAccessFile writer = new RandomAccessFile(file, "rw");
writer.seek(file.length()); //append the file content to the existing file or creates a new one .
writer.write(read(in));
writer.close();
}

/**
* This method is used for monitoring errors that will be occured on writing plugin logs .
* @param msg
*/
public static void log(String msg){
File file = new File(CentralizedLogging.logDir+"plugin_error_"+new SimpleDateFormat("yyyy_MM_dd").format(new Date())+".log");
try {
write(new ByteArrayInputStream(msg.getBytes()),file);
} catch (Exception e) {
}
}

/**
* Method read.
* @param in InputStream
* @return byte[]
* @throws IOException
*/
public static byte[] read(InputStream in) throws IOException{
ByteArrayOutputStream out = new ByteArrayOutputStream();
int read = -1;
byte[] buffer = new byte[1024];
while((read = in.read(buffer)) > -1){
out.write(buffer,0,read);
}
return out.toByteArray();
}

/**
* Method close.
* @param stream Object
*/
public static void close(Object stream){
try{
if(stream instanceof Writer){
((Writer)stream).close();
}else if(stream instanceof Reader){
((Reader)stream).close();
}
}catch (Exception e) {
}
}


}





Adding capability to convert html into a msword document

I am adding capability in my application to convert html into a msword document.



I am trying to use Apache POI to integrate in my application but I didn't find anything related that help me to integrate the Apache-POI with Ruby ( Ruby-On-Rails application).



If you have any idea or source, then please let me know .



Any help will be really appreciated .





Adding a Google Map marker with Javascript from within <body>

I am trying to add a marker from within the tags and not between the tags. My map is created (succesfully) into the head.Same for markers IF i put the code within .



Problem is that i am using a CMS and need tags to be related pages.



The code below is within the usual tags.



<% control ChildrenOf(montreal) %>
<img ..... (this is the Google Icon whose number is called via $NoOfMarker texfield)
$NameOfVendor
. . .

<script type="application/javascript">
<!-- PROBLEM IS HERE -->
<!-- I want to add a marker specific to that child page using $Latitude and $Longitude textfields in the CMS (this works i checked) -->

marqueurX=new google.maps.LatLng($Latitude, $Longitude);
// go get $Latitude and $Longitude of the child page
myMarkerX = new google.maps.Marker({
position: marqueurX,
map: map,
title: '$Nom',
clickable: true,
icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld={$NoOfMarker}|bebe00|000000',
shadow: ombre
});

<!--
this code if placed into the <head> of the mother page, is working
but once placed inside <% control ... %> (or outside or out of <head>
this code does nothing - No errors, no markers either
i suspect a SCOPE or CLOSURE issues
-->
</script>
<% end_control %>


Thanks!





ADO.NET how to use parameter in dataset?

dbDataSet



Where i need initialize parameter, for when form will open, to make it work?



Query:



SELECT id, id_work, name FROM ttz WHERE (id_work = @idwork)


I want @idwork value = textBox1.Text





CSS written after pseudo-element not working

I'm working on Ruby-on-Rails 3.2.1. I've following DOM structure.



UPDATE: removed the </img> tag as mentioned by Gaby. Problem still persists.



<div class="frame">
<img src='SOME_PATH' class="frame-image">
</div>?


And following CSS



.frame { position:relative;border:1px solid #CCC;border-radius:2px;-moz-border-radius:2px; }
.frame:before
{
position:absolute;
content:'';
border:2px solid #F2F2F2;
height:100%;width:100%;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
}
img.frame-image /* IT WON't BE APPLIED?! */
{
min-width:30px;min-height:30px;
max-width:200px;max-height:200px;
}?


The problem I'm facing is, CSS applied to img.frame-image is not working/not getting applied. I tried on Chrome 18 and FireFox 12. I don't see the style in Chrome's element inspector or in FireBug. It is also not getting overridden by any other CSS.



For demo I tried to create jsfiddle for this. It works there!



But surprisingly when I write img.frame-image CSS above .frame:before CSS, it works!!



.frame { position:relative;border:1px solid #CCC;border-radius:2px;-moz-border-radius:2px; }
img.frame-image /* NOW IT WILL BE APPLIED */
{
min-width:30px;min-height:30px;
max-width:200px;max-height:200px;
}?
.frame:before
{
position:absolute;
content:'';
border:2px solid #F2F2F2;
height:100%;width:100%;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
}


Any idea why is it happening? is it framework (RoR) related issue or CSS semantics?





Ajax request not working (asp.net-mvc)

View:



@{
AjaxOptions ajax = new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "sub_id" };
Layout = null;
}
<div id="sub_id">
</div>
@using (Ajax.BeginForm(ajax))
{
@Html.TextBox("email");
<input type="submit" value="???????????" />
}


controller:



[HttpPost]
public ContentResult LeftMenuSubscription(string email)
{
return new ContentResult(){Content = "<script>alert('Thanks')</script>"};
}


"Thanks" alert show.



but in div 'sub_id' set all page(...).



<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script> 


- connected.



html:



<html>
<head>
<title>??????? ????????</title>
<link href="/Content/Site.css" rel="stylesheet" type="text/css">
<script src="/Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>
<script src="/Scripts/jQueryFixes.js" type="text/javascript"></script>
</head>
<body>
....
<form action="/" data-ajax="true" data-ajax-method="POST" data-ajax-mode="replace" data-ajax-update="#sub_id" id="form0" method="post">
<input id="email" name="email" type="text" value="">
<input type="submit" value="???????????">
</form>
...
</body>
</html>


what could be the problem?





Patenting a Control Scheme for Touch Screen Game?

I am working on a platform game for ios/android and I've developed a control scheme that allows for precise directional movement and jumping, as well as four action inputs. The control scheme takes advantage of the multi-touch capabilities of ios and android devices. I haven't seen a control scheme like this used in any other games or apps. The concept centers around the a group of icons in fixed positions on the screen and takes up very little screen real estate.



The design is unique and would be effective in other types of games like fps shooters or fighting games, which is has got me thinking; Is it possible to patent a control scheme? The design and implementation is unique and specific, but it uses an multi-touch, a concept I didn't invent on a device I didn't invent. However, I've never seen this particular type of input used to achieve this particular type of character movement.



Would a control scheme be patentable in a circumstance like this?





security risk with setup.exe file

i exract my project setup file with setup factory. But windows internet explorer and Symentec Endpoint Protection acts like a harmful application. What can i do for solve this problem?



enter image description here



enter image description here





C# 3.0 book suggestions

I am learning c# 3.0.



I need books that give a lot of examples in advanced concepts in c#. I currently study using Wrox c# books. They are not sufficient for me. If you are a c# developer, you would know what advanced concepts I would expect. So please suggest a book, you have read and used.





How many levels of pointers can we have?

How many pointers (*) are allowed in a single variable?



Let's consider the following example.



int a = 10;
int *p = &a;


Similarly we can have



int **q = &p;
int ***r = &q;


and so on.



For example,



int ****************zz;




can not generate necessary file when compile IDL file in visual studio 2010

i'm learning about COM through an internet tutorial(http://www.codeguru.com/cpp/com-tech/activex/tutorials/article.php/c5567/Step-by-Step-COM-Tutorial.htm). The first thing is creating a IDL file and compile it to create another 5 files. The detail is after:




  1. Open VS2010

  2. Create Win32 DLL project name AddObj

  3. Add IAdd.idl file with the content




    import "unknwn.idl";



    [
    object,
    uuid(1221db62-f3d8-11d4-825d-00104b3646c0),
    helpstring("interface IAdd is used for implementing a super-fast addition Algorithm")
    ]



    interface IAdd : IUnknown
    {
    HRESULT SetFirstNumber(long nX1);



    HRESULT SetSecondNumber(long nX2);
    HRESULT DoTheAddition([out,retval] long *pBuffer);
    };



    [
    uuid(3ff1aab8-f3d8-11d4-825d-00104b3646c0),
    helpstring("Interfaces for Code Guru algorithm implementations .")
    ]
    library CodeGuruMathLib
    {
    importlib("stdole32.tlb");
    importlib("stdole2.tlb");



    interface IAdd;
    }





After that, follow the tutorial, if i compile IAdd.idl file, it will generate:



--IAdd.h Contains the C++ style interface declarations.



--dlldata.c Contains code for proxy DLL. Useful when invoking the object on a different process/computer.



--IAdd.tlb Binary file , with a well defined format that completely describes our interface IAdd along with all it's methods. This file is to be distributed to all the clients of our COM component.



--IAdd_p.c Contains marshalling code for proxy DLL. Useful while invoking the object on a different process/computer.



--IAdd_i.c Contains the interface IIDs



but when i compile IAdd by right click it and choose compile in shortcut menu, there is no file being generate. But when open view class, i can see IAdd interface with some method.



I also try it by compile it manually by download midl.exe from internet and run in command line but it failed.



I fine a lot of material by google and all said that i can compile idl file by visual studio but i try many time, on my both computer but no file being generate after i compile idl file. I also install new Win7, new visual studio 2010 ultimate but nothing change.





how to find address from lat long in android

Please Help me in finding address from given lat long in android.



As I have put the lat long values from gps service I need to find the user location where the user is standing.





Resizing Silverlight MediaElement Crashes Plugin

I'm building a Silverlight option in my HTML5 video player (using the JavaScript API). Traditionally, with the Flash player and the HTML5 video I would just resize the video to whatever the container size is.



However, with Silverlight, if I resize certain MP4 videos up, it crashes the plugin. Some videos don't do this, but the ones that do, do it every time. I experimented with an even size factor like 1.5x or 2x but that didn't help. Sizing it down has no problems.



Has anyone experienced this? Is it a known bug? Are there workarounds? Besides, "don't do that", for which I'm aware MS recommends not resizing the video at all. I can accept a performance degradation, but crashing is a concern.