Friday, 27 September 2013

Prevent prompting for PEM passphrase

Prevent prompting for PEM passphrase

I am building a Qt-based application that will communicate through https
with a webserver. The setup should allow client-authentication with a
local certificate and private key. The application must run without any
user interaction.
Now I have a problem when the private key file is protected by a passphrase:
OpenSSL will prompt for a password, blocking the whole application!
The openSSL API allows to pass a callback for getting the passphrase, but
this is not accessible though the Qt Wrapper. Is there another way to
prevent openSSL from prompting for a password? Or can this somehow be
interrupted?

VS displaying blue text despite being configured for black

VS displaying blue text despite being configured for black

I'm running Visual Studio 2010 on my tablet, which is configured for 125%
display scaling (Iconia W3; kind of necessary on an 8" screen). When
configured with default color settings, Visual Studio displays any text
that's supposed to be black normally with a blue tint. If I configure it
as black, it appears blue. If I configure it as red, it appears purple.
Anybody seen this before, and know a workaround, or should I report it on
MS Connect?

Getting virtual memory page size by java code

Getting virtual memory page size by java code

Is it possible to get virtual memory page size of the OS on which a java
application is running? If yes, how?

Thursday, 26 September 2013

Java Game - how to add enemies using Arraylist?

Java Game - how to add enemies using Arraylist?

I'm doing my first Java game using GdxLib, and i want to create enemies
using an ArrayList (but im not sure of how to do it), and that all of them
spawn in a random position, but i got few problems,
Im creating them wrong cause they are spawning like a 'line' because i
dont know how to spawn them randomly.
When any of my created enemies on Screen 'dies' (count == 20) if i shoot
any other enemy i can't kill it.
Here is the class code:
public class World {
gameMain game;
Ship ship;
ArrayList<Bullet> bullets = new ArrayList<Bullet>();
ArrayList<Follower> enemies = new ArrayList<Follower>(5);
WorldRenderer wr;
Iterator<Bullet> bIter;
Iterator<Follower> eIter;
Bullet b;
Enemy e;
int count = 0;
int shipCount = 0;
float x = 0;
float y = 0;
public World (gameMain game){
this.game = game;
ship = new Ship(new Vector2(20, 15), 1, 1, 0, 5f);//Ship Atributes
for (int i= 0;i<5; i++){ Creates 5 enemies
enemies.add(new Follower(5f, 0, 1, 1, new Vector2(x,y)));
x = x+2;
y = y+2;
}
Gdx.input.setInputProcessor(new InputHandler(this));
}
public Ship getShip(){
return ship;
}
public ArrayList<Follower> getEnemies(){
return enemies;
}
public void update(){
ship.update();
bIter = bullets.iterator();
while(bIter.hasNext()){
b = bIter.next();
b.update(ship);
}
eIter = enemies.iterator();
while(eIter.hasNext()){
e = eIter.next();
if(ship.getBounds().overlaps(e.getBounds()))
Gdx.app.log(gameMain.LOG, "ColisioN!");
shipCount = shipCount +1;
}
bIter = bullets.iterator();
while(bIter.hasNext()){
b = bIter.next();
eIter = enemies.iterator();
while(eIter.hasNext()){
e = eIter.next();
if(e.getBounds().overlaps(b.getBounds())){
Gdx.app.log(gameMain.LOG, "!");
bIter.remove();
count = count +1;
if (count == 20) {
eIter.remove();
}
}
}
}
public void addBullet(Bullet b){
bullets.add(b);
}
public ArrayList<Bullet> getBullets(){
return bullets;
}
public void setRenderer(WorldRenderer wr){
this.wr = wr;
}
public WorldRenderer getRenderer(){
return wr;
}
public void dispose(){
}
}
Also, i tried to put a Thread.sleep(2000) after an enemy creation to the
next creation, but when i run the game the Screen frezzes, but the thread
is working because i used a System.out.println to print in console after
each creation. There is another option to delay the bucle without using
Thread.sleep?`

Wednesday, 25 September 2013

C Infinite Pointer Loop (Caused By Duplicate Value?)

C Infinite Pointer Loop (Caused By Duplicate Value?)

Compiling with MinGW with -O3 -Wall -c -fmessage-length=0 -std=c99
Well, this is what I think the problem is... Here's the breakdown:
I have a linked list that I built using
typedef struct Coordinate{
int x;
int y;
struct Coordinate *next;
} Coordinate;
I am adding "valid moves" (in the game Reversi/Othello) on a 6x6 board
(matrix). My logic for checking whether or not a move is valid or not
works just fine - it's adding things to the list that gets me into
trouble.
For obvious reasons I want to avoid adding duplicate values to the list.
However, every function I attempt to code (that seems like it should work)
just crashes the application, segfaulting all the live long day.
So here's a function that I attempted to code:
int inList(Coordinate *list, int x, int y) {
if (list == NULL) return 0;
while (list != NULL) {
if (list->x == x && list->y == y) return 1;
else list = list->next;
}
return 0;
}
and called it like:
Coordinate *validMoves = createNewCoordinate(-1, -1); // Just so that
there is *something*
if (!inList(validMoves, 1, 1)) {
validMoves->next = createNewCoordinate(1, 1);
validMoves = validMoves->next;
}
So as far as I know, this should work perfectly. I've looked up examples
online and all my really convoluted uses of pointers in this particular
program have worked without a hitch thus far.
Anyway, the real problem is that if I don't prevent duplicates from being
entered into the same list (connected through pointers), then I get an
infinite loop (I imagine this is caused by two elements being considered
equal because their non-pointer types are equal).
I've posted all three parts of the code on pastebin for full reference (no
worries, open source, man!): othello.c othello_engine.c othello_engine.h
I've tried debugging but I'm not very good at that, I didn't really see
anything worth mentioning. Can anyone explain what might be happening
and/or give an example of how to avoid duplicates in a linked list? (I've
tried so many ways my brain hurts)

Thursday, 19 September 2013

Codeigniter - How to get values as array to use in next select with where_not_in

Codeigniter - How to get values as array to use in next select with
where_not_in

I have three tables; user, car and user_x_car. user_x_car holds users who
own car; user_id and car_id are stored. I want to get users who don't own
a car as follows:
$car_owner = $this->db->select()->from('user_x_car')->get()->result();
for ($i = 0; $i < count($car_owners); $i++)
$$car_owner_id[$i] = $car_owner[$i]->user_id;
$non_car_owner = $this->db->select()->from('user')->where_not_in('id',
$car_owner_id)->get()->result();
I get what I want, however, is there any way to bypass the for loop in the
middle which creates and array of id's selected in the first select. Is
there any way to get array of selected user_ids directly?

User defined Copy constructor

User defined Copy constructor

I'm getting compile errors for the below code but the same gets compiled
if I remove copy constructor statement.
Could anyone let me know about this behaviour?
class MyClass
{
private:
int i;
MyClass(MyClass &);
public:
MyClass():i(0){}
};
int main(){
MyClass obj = MyClass();
return 0;
}