Adding XCTest unit tests to existing app doesn't work
I've added tests (XCTests) to an existing C++ command line app in Xcode 5
via Test Navigator > (+),
changed the extension of the test class to .mm,
added the XCTest framework to the project.
All compiles fine. Now running the tests just gives me a 'Test failed'
message, nothing in the console and neither green nor red lights in the
Navigator (i.e. no tests executed).
Starting with a fresh Xcode 5 project and changing the extension of the
test class to .mm just works fine so I'd assume it's not just about
lacking support for Objective-C++ in XCTest.
Even with a plain, vanilla test target added to the existing C++ project
the tests fail before ever running.
Any more gotchas to watch out for when adding XCTests to existing
(Objective-)C++ targets?
Thursday, 3 October 2013
Wednesday, 2 October 2013
C, error: control reaches end of non-void function [-Werror,-Wreturn-type]
C, error: control reaches end of non-void function [-Werror,-Wreturn-type]
struct quad {
int a;
int b;
int c;
}
int f(const int a, const int b, const int c, const int x){
const int l = a*x*x + b*x + c;
return l;
}
int safe_quad_eval(const struct quad q, const int x){
(f(q.a,q.b,q.c,x)>INT_MAX)||(f(q.a,q.b,q.c,x)<(-INT_MAX)) ? INT_MIN :
f(q.a,q.b,q.c,x);
}
I'm not sure what does this error mean? and how to solve it?
struct quad {
int a;
int b;
int c;
}
int f(const int a, const int b, const int c, const int x){
const int l = a*x*x + b*x + c;
return l;
}
int safe_quad_eval(const struct quad q, const int x){
(f(q.a,q.b,q.c,x)>INT_MAX)||(f(q.a,q.b,q.c,x)<(-INT_MAX)) ? INT_MIN :
f(q.a,q.b,q.c,x);
}
I'm not sure what does this error mean? and how to solve it?
Need help cleaning up fibonacci sequence using C++ please
Need help cleaning up fibonacci sequence using C++ please
I'm still very new to C++ still and decided to make a fibonacci sequence.
It worked (Woo!) but it doesn't work as well as I would like it to.
what I mean by that is say for example I told my program to count the
first 10 terms of the sequence I will get
"0, 1, 1" and then I have to press enter for each additional number until
it hits ten in which case the program returns 0 and ends.
How do I get the program to display all the numbers I want to without
hitting enter for each additional one?
Here is my script:
#include <iostream>
using namespace std;
int main()
{
int FibNum;
cout << "How many numbers of the Fibonacci Sequence would you like to
see? \n\n";
cin>> FibNum;
cin.ignore();
int a = 0;
int b = 1;
int c = 2;
cout << "Fibonacci Sequence up to " << FibNum << " terms.\n\n";
cout << a << "\n" << b << "\n";
for (int c = 2; c < FibNum; c++) {
int d = a + b;
cout << d;
cin.ignore();
a = b;
b = d;
}
}
Thanks in advance for any help!
P.s. Also if you notice anything terrible I'm doing please feel free to
correct me, I'm very aware I'm probably doing a lot wrong, I'm just trying
to learn. :]
I'm still very new to C++ still and decided to make a fibonacci sequence.
It worked (Woo!) but it doesn't work as well as I would like it to.
what I mean by that is say for example I told my program to count the
first 10 terms of the sequence I will get
"0, 1, 1" and then I have to press enter for each additional number until
it hits ten in which case the program returns 0 and ends.
How do I get the program to display all the numbers I want to without
hitting enter for each additional one?
Here is my script:
#include <iostream>
using namespace std;
int main()
{
int FibNum;
cout << "How many numbers of the Fibonacci Sequence would you like to
see? \n\n";
cin>> FibNum;
cin.ignore();
int a = 0;
int b = 1;
int c = 2;
cout << "Fibonacci Sequence up to " << FibNum << " terms.\n\n";
cout << a << "\n" << b << "\n";
for (int c = 2; c < FibNum; c++) {
int d = a + b;
cout << d;
cin.ignore();
a = b;
b = d;
}
}
Thanks in advance for any help!
P.s. Also if you notice anything terrible I'm doing please feel free to
correct me, I'm very aware I'm probably doing a lot wrong, I'm just trying
to learn. :]
Linq To Entities 5 re-use Expression in another entity
Linq To Entities 5 re-use Expression in another entity
I've been trying to find this, but I've not had luck. Say I have a
database with 2 tables, person and address.
table person
id int
name varchar(50)
addressId int
table address
id int
street varchar(50)
country varchar(50)
In my data layer, I have a business object for Address, which is exposed
to external callers. I found an expression that I could use to centralize
my creation code at the SQL level. This way I don't have to write:
db.Address.Select( x => new Biz.Address{ street = x.street} ).ToList();
//and all the other properties etc
everywhere. Instead I can now do:
db.Address.Select(AddressDto.ToDto).ToList();
Using this code:
internal static class AddressDto
{
internal static readonly Expression<Func<Address, Biz.Address>> ToDto =
src => new Biz.Address
{
Id = src.id,
Street = src.street,
Country = src.country
};
}
The problem is now that I am trying to do the same thing for the Person
object, and I want to re-use this method to fill in the address. However I
can't seem to utilize an expression in it.
class Person
{
int Id;
string Name;
Address address;
}
internal static class PersonDto
{
internal static readonly Expression<Func<Person, Biz.Person>> ToDto =
src => new Biz.Person
{
Id = src.id,
Name = src.name,
address = src.Address //How do i set this to an
expression?
};
}
The reason I ask for the expression, is because while it compiles fine if
I use a normal method, it blows up at runtime, because it can't translate
that to the object store. However, if I do:
address = AddressDto.ToDto(src.Address)
the compiler rejects that, as it wants a method, delegate, or event. I'd
love to find a way to do this. the idea I'm trying to implement is to
basically centralize the code that maps the Entity to the business object,
so that my other code is kept clean and maintenance is easier when the
schema changes. If there is a different method signature I have to create
and maintain, that'd be fine, as I'd place it in the same file and live
with it. I just can't seem to find the magic combination that'll make this
work.
Thanks!
I've been trying to find this, but I've not had luck. Say I have a
database with 2 tables, person and address.
table person
id int
name varchar(50)
addressId int
table address
id int
street varchar(50)
country varchar(50)
In my data layer, I have a business object for Address, which is exposed
to external callers. I found an expression that I could use to centralize
my creation code at the SQL level. This way I don't have to write:
db.Address.Select( x => new Biz.Address{ street = x.street} ).ToList();
//and all the other properties etc
everywhere. Instead I can now do:
db.Address.Select(AddressDto.ToDto).ToList();
Using this code:
internal static class AddressDto
{
internal static readonly Expression<Func<Address, Biz.Address>> ToDto =
src => new Biz.Address
{
Id = src.id,
Street = src.street,
Country = src.country
};
}
The problem is now that I am trying to do the same thing for the Person
object, and I want to re-use this method to fill in the address. However I
can't seem to utilize an expression in it.
class Person
{
int Id;
string Name;
Address address;
}
internal static class PersonDto
{
internal static readonly Expression<Func<Person, Biz.Person>> ToDto =
src => new Biz.Person
{
Id = src.id,
Name = src.name,
address = src.Address //How do i set this to an
expression?
};
}
The reason I ask for the expression, is because while it compiles fine if
I use a normal method, it blows up at runtime, because it can't translate
that to the object store. However, if I do:
address = AddressDto.ToDto(src.Address)
the compiler rejects that, as it wants a method, delegate, or event. I'd
love to find a way to do this. the idea I'm trying to implement is to
basically centralize the code that maps the Entity to the business object,
so that my other code is kept clean and maintenance is easier when the
schema changes. If there is a different method signature I have to create
and maintain, that'd be fine, as I'd place it in the same file and live
with it. I just can't seem to find the magic combination that'll make this
work.
Thanks!
Add "Black right-pointing pointer" HTML entitiy in css content
Add "Black right-pointing pointer" HTML entitiy in css content
I'm trying to add a "Black right-pointing pointer" html entity into my css
:after content but to no avail.
I know you need to use a unicode value but I can't find one that works for
this. This is the unicode number U+25BA and this is the HTML code ►
I'm trying to add a "Black right-pointing pointer" html entity into my css
:after content but to no avail.
I know you need to use a unicode value but I can't find one that works for
this. This is the unicode number U+25BA and this is the HTML code ►
Tuesday, 1 October 2013
Dynamically change only one element in tooltip title using tooltipster
Dynamically change only one element in tooltip title using tooltipster
I have a set of options in a tooltipster title element, like follow:
<i class="icon-cog settings" title="
<div class='div1' onclick='follow(1,2)'>Content 1</div>
<div class='div2' ...>Content 2</div>
<div class='div3' ...>Content 3</div>
">
</i>
When the div1 is clicked, the content is dinamically updated by a ajax
result based on the following function:
function follow(f1,f2) {
$.get('/exe/add_followers.php?f1=' + f1 + '&f2=' + f2, function (result) {
$('.div'+f2).html('content 1 is updated to' + result.newcontent);
}, 'json');
}
The problem is that when the tooltip is closed and the page has not been
refreshed, the content returns to the initial value instead of showing the
updated value.
I tried to use a configuration option as described Here:
function follow(f1,f2) {
$.get('/exe/add_followers.php?f1=' + f1 + '&f2=' + f2, function
(result) {
// $('.div'+f2).html('content 1 is updated to' + result.newcontent);
$('.setting').tooltipster('update', 'content 1 is updated to' +
result.newcontent);
}, 'json');
}
However, this change the div1's content but removes the content of other
divs. How can I update only the content of div1 and leave the other
unchanged?
I have a set of options in a tooltipster title element, like follow:
<i class="icon-cog settings" title="
<div class='div1' onclick='follow(1,2)'>Content 1</div>
<div class='div2' ...>Content 2</div>
<div class='div3' ...>Content 3</div>
">
</i>
When the div1 is clicked, the content is dinamically updated by a ajax
result based on the following function:
function follow(f1,f2) {
$.get('/exe/add_followers.php?f1=' + f1 + '&f2=' + f2, function (result) {
$('.div'+f2).html('content 1 is updated to' + result.newcontent);
}, 'json');
}
The problem is that when the tooltip is closed and the page has not been
refreshed, the content returns to the initial value instead of showing the
updated value.
I tried to use a configuration option as described Here:
function follow(f1,f2) {
$.get('/exe/add_followers.php?f1=' + f1 + '&f2=' + f2, function
(result) {
// $('.div'+f2).html('content 1 is updated to' + result.newcontent);
$('.setting').tooltipster('update', 'content 1 is updated to' +
result.newcontent);
}, 'json');
}
However, this change the div1's content but removes the content of other
divs. How can I update only the content of div1 and leave the other
unchanged?
How to write into Cassandra with Byte Array following Big Endian Byte Order?
How to write into Cassandra with Byte Array following Big Endian Byte Order?
I need to write Byte Array value into Cassandra using Java code. Then I
will be having my C++ program which will retrieve that Byte Array data
from Cassandra and then it will deserialize it.
That Byte Array which I will be writing into Cassandra is made up of three
Byte Arrays as described below-
short schemaId = 32767;
long lastModifiedDate = "1379811105109L";
byte[] avroBinaryValue = os.toByteArray();
Now, I will write schemaId , lastModifiedDate and avroBinaryValue together
into a single Byte Array and that resulting Byte Array I will write into
Cassandra and then I will be having my C++ program which will retrieve
that Byte Array data from Cassandra and then deserialize it to extract
schemaId , lastModifiedDate and avroBinaryValue from it.
I am not sure whether I should use Big Endian here in my Java code while
writing to Cassandra so that C++ code get simplified while reading it
back? I have given a try on the Java side to make sure it is following
certain format (Big Endian) while writing into Byte Array but not sure
whether this is right or not?
public static void main(String[] args) throws Exception {
String os = "Byte Array Test";
byte[] avroBinaryValue = os.getBytes();
long lastModifiedDate = 1379811105109L;
short schemaId = 32767;
ByteArrayOutputStream byteOsTest = new ByteArrayOutputStream();
DataOutputStream outTest = new DataOutputStream(byteOsTest);
outTest.writeShort(schemaId);
outTest.writeLong(lastModifiedDate);
outTest.writeInt(avroBinaryValue.length);
outTest.write(avroBinaryValue);
byte[] allWrittenBytesTest = byteOsTest.toByteArray();
ByteBuffer bb =
ByteBuffer.wrap(allWrittenBytesTest).order(ByteOrder.BIG_ENDIAN);
// now what value I should write into Cassandra?
// or does this even looks right?
// And now how to deserialize it?
}
Can anyone help me with this ByteBuffer thing here? Thanks..
I need to write Byte Array value into Cassandra using Java code. Then I
will be having my C++ program which will retrieve that Byte Array data
from Cassandra and then it will deserialize it.
That Byte Array which I will be writing into Cassandra is made up of three
Byte Arrays as described below-
short schemaId = 32767;
long lastModifiedDate = "1379811105109L";
byte[] avroBinaryValue = os.toByteArray();
Now, I will write schemaId , lastModifiedDate and avroBinaryValue together
into a single Byte Array and that resulting Byte Array I will write into
Cassandra and then I will be having my C++ program which will retrieve
that Byte Array data from Cassandra and then deserialize it to extract
schemaId , lastModifiedDate and avroBinaryValue from it.
I am not sure whether I should use Big Endian here in my Java code while
writing to Cassandra so that C++ code get simplified while reading it
back? I have given a try on the Java side to make sure it is following
certain format (Big Endian) while writing into Byte Array but not sure
whether this is right or not?
public static void main(String[] args) throws Exception {
String os = "Byte Array Test";
byte[] avroBinaryValue = os.getBytes();
long lastModifiedDate = 1379811105109L;
short schemaId = 32767;
ByteArrayOutputStream byteOsTest = new ByteArrayOutputStream();
DataOutputStream outTest = new DataOutputStream(byteOsTest);
outTest.writeShort(schemaId);
outTest.writeLong(lastModifiedDate);
outTest.writeInt(avroBinaryValue.length);
outTest.write(avroBinaryValue);
byte[] allWrittenBytesTest = byteOsTest.toByteArray();
ByteBuffer bb =
ByteBuffer.wrap(allWrittenBytesTest).order(ByteOrder.BIG_ENDIAN);
// now what value I should write into Cassandra?
// or does this even looks right?
// And now how to deserialize it?
}
Can anyone help me with this ByteBuffer thing here? Thanks..
Ubuntu Button is too slow
Ubuntu Button is too slow
When I push Ubuntu Button, it sometimes takes the menu up to 10 seconds to
appear. Or at least 4 seconds in average.
How do I make it faster?
When I push Ubuntu Button, it sometimes takes the menu up to 10 seconds to
appear. Or at least 4 seconds in average.
How do I make it faster?
Describe explicitly the $M$-measurable functions in case $M$ is one of the following $\sigma$-algebras:
Describe explicitly the $M$-measurable functions in case $M$ is one of the
following $\sigma$-algebras:
Describe explicitly the $M$-measurable functions in case $M$ is one of the
following $\sigma$-algebras:
(a) $M=\{\emptyset,X\}$
(b) $M=2^{X}$
(c) For certain disjoint sets $E_1,...,E_N$, $X=\cup_{k=1}^N E_k$, and $M$
is the algebra (in fact, $\sigma$-algebra) generated by the collection of
sets $\{E_1,...,E_N\}$.
Here's my book's definition of $M$-measurable:
Suppose $f:X\to[-\infty,\infty]$. Then $f$ is $M$-measurable if for all
$t\in[-\infty,\infty]$ the set $f^{-1}([-\infty,t])$ belongs to $M$. Inn
other words, $\{x\in X|f(x)\le t\}\in M$.
Of course, the form of the inequality $f(x)\le t$ is arbitrary.
Thanks.
following $\sigma$-algebras:
Describe explicitly the $M$-measurable functions in case $M$ is one of the
following $\sigma$-algebras:
(a) $M=\{\emptyset,X\}$
(b) $M=2^{X}$
(c) For certain disjoint sets $E_1,...,E_N$, $X=\cup_{k=1}^N E_k$, and $M$
is the algebra (in fact, $\sigma$-algebra) generated by the collection of
sets $\{E_1,...,E_N\}$.
Here's my book's definition of $M$-measurable:
Suppose $f:X\to[-\infty,\infty]$. Then $f$ is $M$-measurable if for all
$t\in[-\infty,\infty]$ the set $f^{-1}([-\infty,t])$ belongs to $M$. Inn
other words, $\{x\in X|f(x)\le t\}\in M$.
Of course, the form of the inequality $f(x)\le t$ is arbitrary.
Thanks.
Monday, 30 September 2013
Static IPv6 address in Windows unused for outgoing connections
Static IPv6 address in Windows unused for outgoing connections
I'm running a Windows server and trying to get it to use a static IPv6
address for outgoing connections to other IPv6 hosts (such as Gmail). I
need this because Gmail requires a ptr record, and I can't set one for
random addresses.
The static address is configured on the host, but it also has a temporary
privacy address as well as a random address from the router it seems. By
default Windows uses the privacy address; it seems this is the expected
behavior (and it makes perfect sense for people/users that did not set a
static address, but I did!).
I've tried disabling the privacy address with:
netsh int ipv6 set privacy disabled
This indeed gets rid of the privacy address, but I still have the random
address that the router assigned. To disable this, it was said I needed to
disable "router discovery" using this command:
net interface ipv6 set interface 14 routerdiscovery=disabled
Upon doing this, all IPv6 connectivity is lost. If I do this while pinging
Gmail, it will report "Destination host unreachable" as soon as I enter
the command. In the static IPv6 configuration, I did configure the default
gateway and prefix length, so I don't see why it's unable to connect.
Probably has something to do with the lack of ARP in IPv6 and somehow
being unable to resolve the router's MAC, but I wouldn't know how to fix
this.
Finally I've tried disabling the DHCPv6 lease with these commands:
netsh interface ipv6 set interface "IDMZ Team" managedaddress=disabled
netsh interface ipv6 set interface "IDMZ Team" otherstateful=disabled
Which was to no avail; the host continues to obtain and use the
router-assigned IPv6 address.
The router is a FritzBox 7340, which shows me all the IPv4 and IPv6
addresses that the host (identified by MAC) utilizes, but I'm unable to
change the assigned address. Maybe this could be done over the telnet
interface of the router somehow, but again, I wouldn't know how to do this
even if it's the way to go.
In short, any of the following would probably solve my problem:
Change Windows' source address selection behavior.
Have Windows not get an address from the router and not generate a privacy
address;
Have the router hand out a static address and make Windows use that as
source address.
Recover connectivity after disabling router discovery on Windows.
Alternatively I might use some (batch, perl, ...) script to throw away all
IPv6 addresses except the desired one, but this feels rather hacky. If
it's the only way (or less hacky than another hacky solution), it might be
an option though.
Thanks!
I'm running a Windows server and trying to get it to use a static IPv6
address for outgoing connections to other IPv6 hosts (such as Gmail). I
need this because Gmail requires a ptr record, and I can't set one for
random addresses.
The static address is configured on the host, but it also has a temporary
privacy address as well as a random address from the router it seems. By
default Windows uses the privacy address; it seems this is the expected
behavior (and it makes perfect sense for people/users that did not set a
static address, but I did!).
I've tried disabling the privacy address with:
netsh int ipv6 set privacy disabled
This indeed gets rid of the privacy address, but I still have the random
address that the router assigned. To disable this, it was said I needed to
disable "router discovery" using this command:
net interface ipv6 set interface 14 routerdiscovery=disabled
Upon doing this, all IPv6 connectivity is lost. If I do this while pinging
Gmail, it will report "Destination host unreachable" as soon as I enter
the command. In the static IPv6 configuration, I did configure the default
gateway and prefix length, so I don't see why it's unable to connect.
Probably has something to do with the lack of ARP in IPv6 and somehow
being unable to resolve the router's MAC, but I wouldn't know how to fix
this.
Finally I've tried disabling the DHCPv6 lease with these commands:
netsh interface ipv6 set interface "IDMZ Team" managedaddress=disabled
netsh interface ipv6 set interface "IDMZ Team" otherstateful=disabled
Which was to no avail; the host continues to obtain and use the
router-assigned IPv6 address.
The router is a FritzBox 7340, which shows me all the IPv4 and IPv6
addresses that the host (identified by MAC) utilizes, but I'm unable to
change the assigned address. Maybe this could be done over the telnet
interface of the router somehow, but again, I wouldn't know how to do this
even if it's the way to go.
In short, any of the following would probably solve my problem:
Change Windows' source address selection behavior.
Have Windows not get an address from the router and not generate a privacy
address;
Have the router hand out a static address and make Windows use that as
source address.
Recover connectivity after disabling router discovery on Windows.
Alternatively I might use some (batch, perl, ...) script to throw away all
IPv6 addresses except the desired one, but this feels rather hacky. If
it's the only way (or less hacky than another hacky solution), it might be
an option though.
Thanks!
Biggest ellipse included in a convex polygon
Biggest ellipse included in a convex polygon
Considering a N edges convex 2D polygon called P. Let's name its vertices
$\{p_1, p_2, ..., p_N\}$ described in a counter-clockwise order, with $p_i
= (x_i, y_i)$
What would be, and how would one compute(preferably without optimization
algorithm) the ellipse of biggest area E included in this polygon?
Considering a N edges convex 2D polygon called P. Let's name its vertices
$\{p_1, p_2, ..., p_N\}$ described in a counter-clockwise order, with $p_i
= (x_i, y_i)$
What would be, and how would one compute(preferably without optimization
algorithm) the ellipse of biggest area E included in this polygon?
Why and when we should use arugment.length in ember.js
Why and when we should use arugment.length in ember.js
Below code is taken from here. But I do not understand, why at the time
that the author use fullName as computed property, he did the check for
setter with argument.length instead of value.length, which may more
related to the value variable that is assigned to the function. I wonder
what is the difference and why he is using arugment.length in this case?
App.Person = Ember.Object.extend({
firstName: null,
lastName: null,
fullName: function(key, value) {
// setter
if (arguments.length > 1) {
var nameParts = value.split(/\s+/);
this.set('firstName', nameParts[0]);
this.set('lastName', nameParts[1]);
}
// getter
return this.get('firstName') + ' ' + this.get('lastName');
}.property('firstName', 'lastName')
});
var captainAmerica = App.Person.create();
captainAmerica.set('fullName', "William Burnside");
captainAmerica.get('firstName'); // William
captainAmerica.get('lastName'); // Burnside
Below code is taken from here. But I do not understand, why at the time
that the author use fullName as computed property, he did the check for
setter with argument.length instead of value.length, which may more
related to the value variable that is assigned to the function. I wonder
what is the difference and why he is using arugment.length in this case?
App.Person = Ember.Object.extend({
firstName: null,
lastName: null,
fullName: function(key, value) {
// setter
if (arguments.length > 1) {
var nameParts = value.split(/\s+/);
this.set('firstName', nameParts[0]);
this.set('lastName', nameParts[1]);
}
// getter
return this.get('firstName') + ' ' + this.get('lastName');
}.property('firstName', 'lastName')
});
var captainAmerica = App.Person.create();
captainAmerica.set('fullName', "William Burnside");
captainAmerica.get('firstName'); // William
captainAmerica.get('lastName'); // Burnside
why textchanged and selectedindexchange events don't post correct values in asp.net?
why textchanged and selectedindexchange events don't post correct values
in asp.net?
how to use selected index changed event of drop down list in asp.net??when
I set auto post back ==true, dropdown reload again and select value
changed to first index. i have problems like this problem in text changed
event of textbox that I know only auto post property. but auto post back
not correct solution.
in asp.net?
how to use selected index changed event of drop down list in asp.net??when
I set auto post back ==true, dropdown reload again and select value
changed to first index. i have problems like this problem in text changed
event of textbox that I know only auto post property. but auto post back
not correct solution.
Sunday, 29 September 2013
Stack level too Deep - Rspec
Stack level too Deep - Rspec
I've seen tons of these questions, but none of their solutions are working
for me. I have a single test like so:
describe RolesController do
describe "#delet" do
context "When the user is logged in" do
let(:user) {FactoryGirl.create(:user)}
let(:admin) {FactoryGirl.create(:admin)}
let(:adminRole) {FactoryGirl.create(:adminRole)}
it "Should allow admins to delete roles" do
sign_in admin
put :destroy, :id => adminRole.id
end
end
end
end
Simple, simple, simple. Yet I get the typical error:
1) RolesController#delet When the user is logged in Should allow admins
to delete roles
Failure/Error: Unable to find matching line from backtrace
SystemStackError:
stack level too deep
#
/home/adam/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/notifications/instrumenter.rb:23
and I'm all like ... what? Again I have read dozens of questions on this
and it seems to be something with factory girl but I cannot see what the
issue here would be. I have tons of other tests that instantiate factory
girl based object like this with no issue.
I've seen tons of these questions, but none of their solutions are working
for me. I have a single test like so:
describe RolesController do
describe "#delet" do
context "When the user is logged in" do
let(:user) {FactoryGirl.create(:user)}
let(:admin) {FactoryGirl.create(:admin)}
let(:adminRole) {FactoryGirl.create(:adminRole)}
it "Should allow admins to delete roles" do
sign_in admin
put :destroy, :id => adminRole.id
end
end
end
end
Simple, simple, simple. Yet I get the typical error:
1) RolesController#delet When the user is logged in Should allow admins
to delete roles
Failure/Error: Unable to find matching line from backtrace
SystemStackError:
stack level too deep
#
/home/adam/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/notifications/instrumenter.rb:23
and I'm all like ... what? Again I have read dozens of questions on this
and it seems to be something with factory girl but I cannot see what the
issue here would be. I have tons of other tests that instantiate factory
girl based object like this with no issue.
Download PDF file android
Download PDF file android
i have An Error while download PDF file From Server and save it on SD i
have permission To Access internet and external storage .. It`s working
fine on android 2.3.6 But on Tab 4.1.1 its create the file with 0 byte
URL url = new URL("https://docs.google.com/"+direct);
//create the new connection
HttpURLConnection urlConnection = (HttpURLConnection)
url.openConnection();
//set up some things on the connection
urlConnection.setRequestMethod("GET");
urlConnection.setRequestProperty("Connection", "Keep-Alive");
urlConnection.setRequestProperty("Content-Type",
"application/xml");
urlConnection.setDoOutput(true);
//and connect!
urlConnection.connect();
//set the path where we want to save the file
//in this case, going to save it on the root directory of the
//sd card.
File SDCardRoot = new
File(Environment.getExternalStorageDirectory().getAbsoluteFile()+"/folder/");
//create a new file, specifying the path, and the filename
//which we want to save the file as.
File file = new File(SDCardRoot,book.getBook_name()+".pdf");
//this will be used to write the downloaded data into the file
we created
FileOutputStream fileOutput = new FileOutputStream(file);
//this will be used in reading the data from the internet
InputStream inputStream = urlConnection.getInputStream();
//this is the total size of the file
totalSize = urlConnection.getContentLength();
//variable to store total downloaded bytes
//create a buffer...
byte[] buffer = new byte[1024];
int bufferLength = 0; //used to store a temporary size of the
buffer
//now, read through the input buffer and write the contents to
the file
while ( (bufferLength = inputStream.read(buffer)) > 0 ) {
//add the data in the buffer to the file in the file
output stream (the file on the sd card
fileOutput.write(buffer, 0, bufferLength);
//add up the size so we know how much is downloaded
downloadedSize += bufferLength;
//this is where you would do something to report the
prgress, like this maybe
publishProgress((downloadedSize*100)/totalSize);
}
//close the output stream when done
fileOutput.close();
//catch some possible errors...
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
i have An Error while download PDF file From Server and save it on SD i
have permission To Access internet and external storage .. It`s working
fine on android 2.3.6 But on Tab 4.1.1 its create the file with 0 byte
URL url = new URL("https://docs.google.com/"+direct);
//create the new connection
HttpURLConnection urlConnection = (HttpURLConnection)
url.openConnection();
//set up some things on the connection
urlConnection.setRequestMethod("GET");
urlConnection.setRequestProperty("Connection", "Keep-Alive");
urlConnection.setRequestProperty("Content-Type",
"application/xml");
urlConnection.setDoOutput(true);
//and connect!
urlConnection.connect();
//set the path where we want to save the file
//in this case, going to save it on the root directory of the
//sd card.
File SDCardRoot = new
File(Environment.getExternalStorageDirectory().getAbsoluteFile()+"/folder/");
//create a new file, specifying the path, and the filename
//which we want to save the file as.
File file = new File(SDCardRoot,book.getBook_name()+".pdf");
//this will be used to write the downloaded data into the file
we created
FileOutputStream fileOutput = new FileOutputStream(file);
//this will be used in reading the data from the internet
InputStream inputStream = urlConnection.getInputStream();
//this is the total size of the file
totalSize = urlConnection.getContentLength();
//variable to store total downloaded bytes
//create a buffer...
byte[] buffer = new byte[1024];
int bufferLength = 0; //used to store a temporary size of the
buffer
//now, read through the input buffer and write the contents to
the file
while ( (bufferLength = inputStream.read(buffer)) > 0 ) {
//add the data in the buffer to the file in the file
output stream (the file on the sd card
fileOutput.write(buffer, 0, bufferLength);
//add up the size so we know how much is downloaded
downloadedSize += bufferLength;
//this is where you would do something to report the
prgress, like this maybe
publishProgress((downloadedSize*100)/totalSize);
}
//close the output stream when done
fileOutput.close();
//catch some possible errors...
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Transition gesture to a modal UIViewController
Transition gesture to a modal UIViewController
I am using a UIPinchGestureRecognizer to trigger the appearance of a modal
UIViewController, that allows zooming and panning around an image. It
essentially lets you isolate one image and explore it in more detail.
The new UIViewController has its own pinch and pan gesture recognizers.
The one downside I have noticed is that once the new UIViewController
appears, the user has to take their fingers off the screen and start
pinching again before the new gesture recognizer identifies the touch
events.
Ideally, I would like the pinching to be seamless, so the user could
continue to pinch and/or pan once the modal UIViewController appears. Is
there any way to transition the touch events from the previous view
controller into the modal one, in such a way the gesture recognizers in
the new UIViewController are triggered?
The code that I use to trigger the modal zoom view controller:
- (IBAction)zoomImage:(UIPinchGestureRecognizer *)sender
{
// if the gesture was released while the scale factor is sufficiently
big, show the modal view
if ( sender.state == UIGestureRecognizerStateEnded && sender.scale >
1.6f ) {
// prepare the modal view controller
ZoomViewController *viewControllerZoom = [[ZoomViewController
alloc] initWithNibName:nil bundle:nil];
[viewControllerZoom setImage:self.imageViewImage.image
andScale:sender.scale];
// present the modal view controller
[self presentViewController:viewControllerZoom animated:YES
completion:nil];
// gracefully transition the image back to its original size
[UIView animateWithDuration:0.5f animations:^{
self.imageViewImage.transform = CGAffineTransformIdentity;
}];
}
else if ( sender.state == UIGestureRecognizerStateEnded ||
sender.state == UIGestureRecognizerStateCancelled ) {
// revert to normal size on end
[UIView animateWithDuration:0.5f animations:^{
self.imageViewImage.transform = CGAffineTransformIdentity;
}];
}
else if ( sender.scale >= 1.0f ) {
// scale in place
CGFloat scale = sender.scale;
self.imageViewImage.transform =
CGAffineTransformScale(CGAffineTransformIdentity, scale, scale);
}
}
I am using a UIPinchGestureRecognizer to trigger the appearance of a modal
UIViewController, that allows zooming and panning around an image. It
essentially lets you isolate one image and explore it in more detail.
The new UIViewController has its own pinch and pan gesture recognizers.
The one downside I have noticed is that once the new UIViewController
appears, the user has to take their fingers off the screen and start
pinching again before the new gesture recognizer identifies the touch
events.
Ideally, I would like the pinching to be seamless, so the user could
continue to pinch and/or pan once the modal UIViewController appears. Is
there any way to transition the touch events from the previous view
controller into the modal one, in such a way the gesture recognizers in
the new UIViewController are triggered?
The code that I use to trigger the modal zoom view controller:
- (IBAction)zoomImage:(UIPinchGestureRecognizer *)sender
{
// if the gesture was released while the scale factor is sufficiently
big, show the modal view
if ( sender.state == UIGestureRecognizerStateEnded && sender.scale >
1.6f ) {
// prepare the modal view controller
ZoomViewController *viewControllerZoom = [[ZoomViewController
alloc] initWithNibName:nil bundle:nil];
[viewControllerZoom setImage:self.imageViewImage.image
andScale:sender.scale];
// present the modal view controller
[self presentViewController:viewControllerZoom animated:YES
completion:nil];
// gracefully transition the image back to its original size
[UIView animateWithDuration:0.5f animations:^{
self.imageViewImage.transform = CGAffineTransformIdentity;
}];
}
else if ( sender.state == UIGestureRecognizerStateEnded ||
sender.state == UIGestureRecognizerStateCancelled ) {
// revert to normal size on end
[UIView animateWithDuration:0.5f animations:^{
self.imageViewImage.transform = CGAffineTransformIdentity;
}];
}
else if ( sender.scale >= 1.0f ) {
// scale in place
CGFloat scale = sender.scale;
self.imageViewImage.transform =
CGAffineTransformScale(CGAffineTransformIdentity, scale, scale);
}
}
andEngine alertdialog error
andEngine alertdialog error
error java.lang.RuntimeException: Can't create handler inside thread that
has not called Looper.prepare() =(
if I call showDialog (id) into GameActivity - works If the calling
activity.showDialog from another class - a mistake
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case 1:
Log.d("Dialog", "Dialog 1");
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Help");
alert.setMessage("Help");
WebView wv = new WebView(this);
wv.loadUrl("http:\\www.google.com");
wv.setWebViewClient(new WebViewClient()
{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String
url)
{
view.loadUrl(url);
return true;
}
});
alert.setView(wv);
AlertDialog ALERT = alert.create();
return ALERT;
default:
return null;
}
}
I want to call a dialog with any other class
error java.lang.RuntimeException: Can't create handler inside thread that
has not called Looper.prepare() =(
if I call showDialog (id) into GameActivity - works If the calling
activity.showDialog from another class - a mistake
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case 1:
Log.d("Dialog", "Dialog 1");
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Help");
alert.setMessage("Help");
WebView wv = new WebView(this);
wv.loadUrl("http:\\www.google.com");
wv.setWebViewClient(new WebViewClient()
{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String
url)
{
view.loadUrl(url);
return true;
}
});
alert.setView(wv);
AlertDialog ALERT = alert.create();
return ALERT;
default:
return null;
}
}
I want to call a dialog with any other class
Saturday, 28 September 2013
How to make Online iPhone "Card Game" with HTML5
How to make Online iPhone "Card Game" with HTML5
What are the necessary things for creating card game on iPhone??
The purpose of this app is to share the ideas by using cards. Each player
will draw a card and do what the cards order to do such as write the
comments on those topics and so on.
I'm quite new for the programing. I don't want to learn Objective-C. It is
quite hard for me. I have searched on google that PhoneGab can port
HTML5,CSS&JavaScript to be an iPhone app. So the things that I must learn
are HTML5,CSS & JavaScript only?
This app must have many players to play for sharing the ideas. Therefore,
must I learn other programing languages? such as, php.. to manage each
player data (profile).
Moreover, I would like to use points, badges, leader board in this app, too
How about and SDK or any software to help me write code easier?
(p.s. Sorry for my bad English)
What are the necessary things for creating card game on iPhone??
The purpose of this app is to share the ideas by using cards. Each player
will draw a card and do what the cards order to do such as write the
comments on those topics and so on.
I'm quite new for the programing. I don't want to learn Objective-C. It is
quite hard for me. I have searched on google that PhoneGab can port
HTML5,CSS&JavaScript to be an iPhone app. So the things that I must learn
are HTML5,CSS & JavaScript only?
This app must have many players to play for sharing the ideas. Therefore,
must I learn other programing languages? such as, php.. to manage each
player data (profile).
Moreover, I would like to use points, badges, leader board in this app, too
How about and SDK or any software to help me write code easier?
(p.s. Sorry for my bad English)
Regex issue - asterisk after \d
Regex issue - asterisk after \d
I'm using http://gskinner.com/RegExr/ to test my regex:
[+-]?\d+\.?\d*(e[+-]?\d+)?. It's supposed to match floating point numbers.
Currently it doesn't match .x, but I want to make it do that.
I tried changing it to [+-]?\d*\.?\d*(e[+-]?\d+)? (changed + to *) but
that's an error. What's going wrong here?
Update: is it because everything is optional?
I'm using http://gskinner.com/RegExr/ to test my regex:
[+-]?\d+\.?\d*(e[+-]?\d+)?. It's supposed to match floating point numbers.
Currently it doesn't match .x, but I want to make it do that.
I tried changing it to [+-]?\d*\.?\d*(e[+-]?\d+)? (changed + to *) but
that's an error. What's going wrong here?
Update: is it because everything is optional?
playback time between mediaplayers
playback time between mediaplayers
I'm using several mediaplayers in my code that is played in sequence. I
wonder if it is possible to reduce the time between a reproduction and
other. audios use no space at the beginning or end.
I've searched but have not found any answers.
appreciate any help
thanks and regards
I'm using several mediaplayers in my code that is played in sequence. I
wonder if it is possible to reduce the time between a reproduction and
other. audios use no space at the beginning or end.
I've searched but have not found any answers.
appreciate any help
thanks and regards
Subscribe to:
Posts (Atom)