Thursday, 3 October 2013

algorithm complexity , solving recursive equation

algorithm complexity , solving recursive equation

I am a student at University of Tehran and this semester I've taken a Data
Structures and Algorithm course . anyway not to bore you with details ,
for solving complexity for an algorithm , I'm stuck in this recursive
equation :
T(n) = logn*T(logn) + n
obviously this cant be handled with the use of the Master Theorem , so I
was wondering if anybody has any ideas for solving this recursive equation
. P.S. : I'm pretty sure that it should be solved with a change in the
parameters , like considering n to be 2^m , but I couldn't manage to find
any good fix . anyways , thanks for your help in advance

Wednesday, 2 October 2013

Release bugs only show up when running EXE outside of Visual Studio

Release bugs only show up when running EXE outside of Visual Studio

I have an issue that I am trying to debug that only happens when I run the
release exe built directly outside of Visual Studio. When I am executing
it from within Visual Studio the program behaves normally, even when using
specific project properties to debug a "release" build, such as turning on
optimizations, explained on the following page.
http://msdn.microsoft.com/en-us/library/fsk896zz%28v=vs.100%29.aspx
I experience no issues using those settings and running/debugging from
withing VS, but when I copy the exe and required files (images and some
dll) to it's own directory and run the exe directly instead of through
VS2010 I experience a couple errors. This is making it hard to debug as I
can't get the issue to occur inside VS no matter what settings I use.
Am I missing some settings or is there still more things that happen
differently outside of VS2010 that I can't simulate from within VS 2010?
I am not using any arguments or environment variables that could be
affecting it and the file structure from the working directory is
identical to the way it is in the source code directory.

How to create a kernel thread in atomic context and use it multiple times [BUG: Scheduling while atomic]

How to create a kernel thread in atomic context and use it multiple times
[BUG: Scheduling while atomic]

I need to kthread_run in a driver kernel code. This thread tends to turns
an LED on/OFF where the device is transmitting data. So basically I won't
want the transmission be slowed down be cause of the LED blinking delay
time. I would like to create a thread somewhere around packet transmission
code so the thread will do the LED blinking process based on the rate of
transmission. But apparently creating a thread there requires interaction
with the thread scheduler, which is not allowed at interrupt/atomic
context and will generate the BUG:Scheduling while atomic. according to my
research,an approach could be to create the kernel thread elsewhere, and
queue interrupt request processing to it. Can someone please elaborate
this a bit more? So this is not a case where we have interruption thread.
I basically need a Function that has it's own thread away from my main
thread. And I will call this function anytime! Please let me know if this
is still unclear. Thanks.

Popup message after redirect OR message after user visits from a particular site

Popup message after redirect OR message after user visits from a
particular site

I'd like to show a popup welcome message AFTER a visitor has been
redirected from my old site to the new one.
I'm going to set up the old site with 301 redirects to the new content -
and only people coming from the old site should see the welcome message.
Users who access the new site directly should not see the message.
I know that I can set up a message before redirect on the old site - but I
currently only have access to my client's new site.
I can't find anything anywhere about doing something like this. Is it
possible?

How to use variables in Java?

How to use variables in Java?

This question may seem dumb at first, but after having worked with
different person, I see everyone seems to have their own, different
knowledge about it, so here's my question.
So now I'm wondering what is the best way to do it, and why (why is more
important for me):
I'm wondering about two methods to write Java code:
Do you always pass Object or can you pass primitive data type ?
Do you call variables using this.name, name or getName() inside your class
instance ?
public class MyClass {
private String someStr;
private int someNumber;
private Integer someOtherNumber; // int, Integer ? which one to choose ?
public MyClass(String someStr, int someNumber, int someOtherNumber) {
// int someNumber ? Integer someNumber ? why ?
this.someStr = someStr; // Here, it's clearly this.{name} = {name}
because of the variable name conflict
this.someNumber = someNumber;
this.someOtherNumber = someOtherNumber;
}
public int someMethod(boolean first) { // Boolean ? boolean ?
if (first) {
return someNumber;
} else {
return this.someOtherNumber; // this.{name} ? just {name} or
even this.get{name}() or get{name}() ? (supposing getters
exists)
}
}
}
I hope I'm clear about it and I hope someone will provide me with a great
explanation about which to use in order for me to write better code (and
maybe help others too ! :))
Thanks for your help.

Tuesday, 1 October 2013

Is it a common/good practice to save/update the session *after* sending the response?

Is it a common/good practice to save/update the session *after* sending
the response?

I started updating the session after sending the response and it seems
like a good way to get a little more speed, since it's now a non-blocking
task.
But I'm worried that a minimal slow down in the database could cause
problems when updating the session this way.
Imagine I want to set a session flash message for the next request, but
the next request/response happen before the session is updated. The user
won't see it, or he will see it in a different request.
And the worst case is when you need to regenerate the session ID. If the
update is slow and the next request comes faster than that, the user will
get logged out because he will be asking for a non-existent or expired
session (he received the new session ID in the cookie as part of the
response).
So what I wanna know is whether this has already been studied, whether
people are using it, when should I do it, when I shouldn't, if there is a
fix for it, etc.

spring security bean not found exception

spring security bean not found exception

I'm trying to set up spring security for an mvc project, and I'm having a
hard time. I'm using the spring security 3.1.4.Release. I have a
spring-security.xml file set up along with and mvc-dispatcher-servlet file
set up for configuration. Right now I'm getting a bean not found exception
for my User Details Bean.
In intellij I get a "cannot resolve bean" message for the
myUserDetailService. I also cannot resolve the package "controller". The
root error when I run the project is:
Caused by: org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0':
Cannot resolve reference to bean 'myUserDetailService' while setting bean
property 'userDetailsService'; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean
named 'myUserDetailService' is defined
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)
[spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
[spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]
Here is my spring-security.xml file:
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- Enabling Spring beans auto-discovery -->
<context:component-scan base-package="controller, com.company.admin" />
<http auto-config="true">
<intercept-url pattern="/admin/*" access="ROLE_USER" />
<form-login login-page="/login" default-target-url="/admin/welcome"
authentication-failure-url="/loginfailed" />
<logout logout-success-url="/logout" />
</http>
<authentication-manager>
<authentication-provider user-service-ref="myUserDetailService"/>
</authentication-manager>
</beans:beans>
Here is my mvc-dispatcher-servlet.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- Enabling Spring beans auto-discovery -->
<context:component-scan base-package="com.company.admin" />
<!-- Enabling Spring MVC configuration through annotations -->
<mvc:annotation-driven />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
Here is my web.xml:
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring MVC Application</display-name>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/mvc-dispatcher-servlet.xml,
/WEB-INF/spring-security.xml
</param-value>
</context-param>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
</web-app>
I'm basically trying to follow this tutorial:
http://kh-yiu.blogspot.com/2012/12/spring-mvc-security-custom.html and the
UserDetailServiceImpl is pretty identical to that, but I do have it in a
different folder in my main/java directory. It's important to note I use
annotations to declare the class:
@Service("myUserDetailService")
public class UserDetailsServiceImpl implements UserDetailsService{
Any ideas? I'm having a very hard time finding tutorials with the same
spring version that I'm using, so it's quite possible I've messed up xsd
refs. Thanks.

upper bound of sequence of functions

upper bound of sequence of functions

What function will be an upper bound of the sequence
$f_{n}(x)=\Bigl(1-\frac{x}{n}\Bigr)^{n}\ln(x)$
since $\displaystyle\lim_{n\to\infty}\Bigl(1-\frac{x}{n}\Bigr)^{n}=e^{-x}$
so we should probably bound above by the exponential function.
Someone knows how to do that?

can some tell me that my answer is right or wrong

can some tell me that my answer is right or wrong

If $\mathbb R$^5be a vector space .and
$$W_1={(0,x_2,x_3,x_4,x_5)/x_2,x_3,x_4,x_5\in R}$$and
$$W2={(x_1,0,x_3,x_4,x_5)/x_1,x_3,x_4,x_5\in R}$$be two subspaces of $R^5$
then the dimension of $W1\cap$W_2 is according two me its dimension is 3
as then $W_1\cap W_2$ have elements of the form $$(0,0,x_3,x_4,x_5)$$
hence $W_1\cap W_2$ will be isomorphic to $ R^3$.

Monday, 30 September 2013

LDAP query doesn't return all accounts with specific login

LDAP query doesn't return all accounts with specific login

I have a Windows 2008 domain that I am querying via ldapsearch and if I
use a domain administrator account I get all the users I would expect, but
if I use the service account I created for this purpose I miss random
objects.
For example:
#> ldapsearch -LLL -H ldap://domain-controller.my-domain.com:389 -b
'dc=MY-DOMAIN,dc=COM' -D 'MY-DOMAIN\administrator' -W
'(&(objectClass=Person)(sAMAccountName=*)(memberof=cn=StashTeam,ou=MyTeams,ou=MyDomainUsers,dc=MY-DOMAIN,dc=COM)(!(userAccountControl=514)))'
| grep cn:
I get a list of:
cn: Homer Simpson
cn: Marge Simpson
cn: Bart Simpson
cn: Lisa Simpson
cn: Maggie Simpson
However if I run (using my Service Account):
#> ldapsearch -LLL -H ldap://domain-controller.my-domain.com:389 -b
'dc=MY-DOMAIN,dc=COM' -D 'MY-DOMAIN\ServiceUser' -W
'(&(objectClass=Person)(sAMAccountName=*)(memberof=cn=StashTeam,ou=MyTeams,ou=MyDomainUsers,dc=MY-DOMAIN,dc=COM)(!(userAccountControl=514)))'
| grep cn:
I get a list like:
cn: Homer Simpson
cn: Lisa Simpson
cn: Maggie Simpson

An abelian subgroup of a group of order 32:

An abelian subgroup of a group of order 32:

I know that a group of order 32 has an abelian subgroup of order 16 using
GAP (Groups, Algorithms, Programming). Is there a way without using
programming to show this. Any help will be highly appreciated.

iOS 7 adding UIView to UITableView

iOS 7 adding UIView to UITableView

I am trying to add a UIView to UITableView in iOS 7 to display and "Not
Results" view.
My code works fine in iOS 6, but getting white page in iOS 7.
[self.tableView insertSubview:_nomatchesView
belowSubview:self.tableView];
Anyone run into this issue?
Thanks.

Passing data from C# to unmanaged C++ (using COM Interop)

Passing data from C# to unmanaged C++ (using COM Interop)

I'm using Com Interop method to communicate with unmanaged C++ and C#.
I need to send data to unmanaged C++ from C#.
Im already sending "bool" values values from C# & accessing it through
"VARIANT_BOOL*" in c++.
I need to send a integer from C#. How can i access that integer value in
unmanaged c++ side ?
for example:
C#
public int myValue()
{
return 5;
}
Unmanaged C++
CoInitialize(NULL);
hRes = IMyPointer.CreateInstance(MyNSpace::CLSID_MyClass);
if (hRes == S_OK)
{
//// ??? define x type
IMyPointer->myValue(x);
}

Sunday, 29 September 2013

Regex "greedy" check

Regex "greedy" check

I'm trying to use a simple Regex to match a patttern but get some
unexpected results...
The search pattern and results are given below,
public class Test {
public static void main(String[] args) throws IOException {
Pattern p = Pattern.compile(".*xx");
Matcher m = p.matcher("yyxxxyxx");
while (m.find()){
System.out.println("match start");
System.out.println("Start = " + m.start());
System.out.println("End = " + m.end());
System.out.println("Group = " + m.group());
}
}
}
Result:
match start Start = 0 End = 8 Group = yyxxxyxx
Expected Result:
match start Start = 0 End = 4 Group = yyxx match start Start = 4 End = 8
Group = xyxx
Can someone explain how the regex operates ?

wpf Converter with Combobox

wpf Converter with Combobox

lets say i have a class address
public partial class Address
{
public int Id { get; set; }
public Nullable<int> CountryId { get; set; }
public Nullable<int> CityId { get; set; }
public string Details { get; set; }
public Nullable<bool> IsDefault { get; set; }
public Nullable<int> PersonId { get; set; }
}
i want to know how can i use converter with a combobox inside the grid to
show cities in that combobox based on selected country in another combobox
inside the grid. i need to now the syntax how can i use the countryID to
pass it to converter to get list of cities and binding it to CityCombobox
in datagrid and on changing the Country this list is updated according to
the selected country.. Thanks

Implementation of DDA Line Algorithm

Implementation of DDA Line Algorithm

I have tested all the cases of how a line could be 1. vertically 2.
horizontally 3. has a positive or less than 1 slope. The function works,
but I would like to review it, if there are overflows, lost test
cases..etc. I just read the algorithm in wikipedia, and tried to implement
it out of the wikipedia article.
// Draw line using DDA Algorithm
void Graphics::DrawLine( int x1, int y1, int x2, int y2, Color&color )
{
float xdiff = x1-x2;
float ydiff = y1-y2;
int slope = 1;
if ( y1 == y2 )
{
slope = 0;
}
else if ( x1 == x2 )
{
slope = 2; // vertical lines have no slopes...
}
else
{
slope = (int)xdiff/ydiff;
}
if ( slope <= 1 )
{
int startx = 0;
int endx = 0;
if ( x1 > x2 )
{
startx = x2;
endx = x1;
}
else
{
startx = x1;
endx = x2;
}
float y = y1; // initial value
for(int x = startx; x <= endx; x++)
{
y += slope;
DrawPixel(x, (int)abs(y), color);
}
}
else if ( slope > 1 )
{
float x = x1; // initial value
int starty = 0;
int endy = 0;
if ( y1 > y2 )
{
starty = y2;
endy = y1;
}
else
{
starty = y1;
endy = y2;
}
for(int y = starty; y <= endy; y++)
{
x += 1/slope;
DrawPixel((int)x, y, color);
}
}
}

mysql get data from three tables using one id

mysql get data from three tables using one id

I have three different tables, which have following structure:
Food
ID | title
---+----------
1 | sandwich
2 | spaghetti
Ingridients
ID | food_reference | type | location | bought
----+----------------+------+----------+----------
100 | 1 | ham | storeA | 11-1-2013
101 | 1 | jam | storeB | 11-1-2013
102 | 2 | tuna | storeB | 11-6-2013
Tags
ID | food_reference | tag
----+----------------+-----
1000| 1 | Tag
1001| 1 | Tag2
1002| 2 | fish
and using one select I want to get all information from these three tables
(title,type,location,bought,tag) for one specific ID. I have tried
something like
SELECT food.*,ingridients.*,tags.* FROM food
JOIN ingridients
ON :id=ingridients.food_reference
JOIN tags
ON :id=tags.food_reference
WHERE id=:id
BUT this query returns for id=1 only one row from ingridients and tags
even though there are two matching rows (ham and jam, Tag and Tag2). Could
you tell me what am I doing wrong?

Saturday, 28 September 2013

In PHP would this be deemed correct?

In PHP would this be deemed correct?

I already wrote a post about an issue I had before about this but I had
that issue taken care of. Like my last post I have a form, text-box and a
button. I have everything done with this including Printing the original
word, Printing the number of characters in the word, Printing the word in
all caps and Printing the word in reverse order. My only issue I'm having
is trying to get whatever text I enter and then click the button to output
to Print the first letter of the word and Print the last letter of the
word. I've been doing a lot of looking around of PHP.net and I found that
substr is used to return a part of a string that I could use. The only
issue is when I write the code for it and try to execute my program it
errors out on that specific line. I'm not looking for the answer but could
someone just take a look and see what I'm doing wrong because I understand
everything completely but this is the only thing I'm hung up on.
$first = substr($_POST['entertext']);
echo "The first letter of the word is " . $first. "<br />\n";
$last = substr($_POST['entertext']);
echo "The first letter of the word is " . $last. "<br />\n";

WPF: How to bind object to ComboBox

WPF: How to bind object to ComboBox

Trying to learn how to bind objects to various types of controls. In this
instance, I want to get sample data in my object to appear in ComboBox.
The code runs but what appears instead of values (David, Helen, Joe) is
text "TheProtect.UserControls.Client")
XAML: (ucDataBindingObject.xaml)
<UserControl x:Class="TheProject.UserControls.ucDataBindingObject"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Width="Auto"
Height="Auto"
mc:Ignorable="d">
<Grid Width="130"
Height="240"
Margin="0">
<ComboBox Width="310"
HorizontalAlignment="Left"
VerticalAlignment="Top"
ItemsSource="{Binding Path=Clients}" />
</Grid>
</UserControl>
C#: ucDataBindingObject.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Controls;
namespace TheProject.UserControls
{
public partial class ucDataBindingObject : UserControl
{
public List<Client> Clients { get; set; }
public ucDataBindingObject()
{
Clients = new List<Client>();
Clients.Add(new Client(1, "David")); // sample data
Clients.Add(new Client(2, "Helen"));
Clients.Add(new Client(3, "Joe"));
InitializeComponent();
this.DataContext = this;
}
}
C# Client.cs
using System;
using System.Linq;
namespace TheProject.UserControls
{
public class Client
{
public int ID { get; set; }
public string Name { get; set; }
public Client(int id, string name)
{
this.ID = id;
this.Name = name;
}
}
}

Installing Gnuradio on ubuntu

Installing Gnuradio on ubuntu

Im trying to install Gnuradio, i need this to be able to install gqrx to
use my software defined radio dongle.
I have folloewd the guide at
https://www.jeroennijhof.nl/wiki/index.php/Software-Defined_Radio_on_Ubuntu
but the installation aborts because cheetah isnt installed. Python-cheetah
is in fact installed in its latest version, running sudo apt-get install
python-cheetah only states that it is already installed.
Does anyone know why gnuradio doesnt accept that Cheetah is installed?
Output from installation atempt:
-- Python checking for Cheetah >= 2.0.0
-- Python checking for Cheetah >= 2.0.0 - not found
CMake Error at volk/CMakeLists.txt:62 (message):
Cheetah templates required to build VOLK
-- Configuring incomplete, errors occurred!