Sunday, 1 September 2013

Cannot attach file using Proxy

Cannot attach file using Proxy

I'm develop my own csharp proxy (using Socket), everything going fine
except for two things: 1. even on HTTP WebMail user cannot doing file
attachment (other email function is ok, including download attachment) 2.
It cannot handle HTTPS (443)
The 1st problem I'm very concern with, the 2nd problem if there is
solution is also great, do you guys have suggestion what it's all about?

What the function calcHist() give us

What the function calcHist() give us

My question is when we normalize the histogram , is there any build-in
function for that , if not than obviously we can calculate the histogram
of the image using the function calcHist() , but the formula of
normalizing histogram is Nk/N so what calcHist return us is N in this
formula , or we have to calculate N on our own , and whats its role in
entropy formula

jquery issue with dynamicaly selected elements

jquery issue with dynamicaly selected elements

i am making a game, and im trying to display healthLost on whichever
javascript object lost that health. here is the relevant part of my
objects code for player
function Player(id) {
this.id = id;
this.displayText = "<img src =
'https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiwYSsdi_9pipA3_zFprzM5st4vi-z8_HgHoVaq5s2b7QvIMk94Q6sl7kGk-R4YExYJag3rRuNc-5lT6CnpjM9gHYPGjHO8L3vzBW_ohP-IU18iwzzYJeSDxnCR_5HkxXKmDal9t4QDaY/s1600/smileys_001_01.png'"
+
"class='onTop' id='" + this.id + "' alt='you' border='0' />" +
"<div id = '" + this.id + "health' class = 'healthLost hide'></div>";}
and for monsters ( a array of objects)
function createMonster(name,startingPoint,level) {
this.id = "monsters[" + monsterIdPlacholder++ + "]";
this.displayText = "<img
src='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6ab_R-iEDkgXQCpzILFqp2JDCKc8jbjThZcCFWDQyo2R58VgdOIzXX2Qqagqmv0xAl24BE25a0M53tMt-a0sedFmzbvIMXgKdXIhhQ7_KSwj_1GKPKA4w9S7YIZ50jVcIa7ddPW2fUQo/s1600/712324538.png'"
+
"alt='bad guy' border='0' id = '" + this.id + "' />" +
"<div id = '" + this.id + "health' class = 'healthLost hide'></div>";
}
CSS for hide:
.hide{
display:none;
}
and in my function attack() i wrote like this
function attack( attacker, defender ) {
//code to calculate healthLost
var displayHealthDivId = defender.id + "health";
console.log( displayHealthDivId );
$( "#" + displayHealthDivId ).removeClass("hide");
$( "#" + displayHealthDivId ).html( healthLost );
});
}
}
now the above jquery works for my player object, but not for my monster
object's, the console.log returns what i expect. so why doesnt it work for
the monsters? and how do i fix this?
what i really want is for the divs to appear then fade upwards, but i will
do that later. however if you could include that in your answer tthat
would be neat.
link here
sorry i wasent able to create a fiddle, too much code, and bugs
(reference-error's since i didnt put in all my code) kept coming up.

Saturday, 31 August 2013

Invalid read of size 8

Invalid read of size 8

I have written a class for a sequence of doubles in c++ using a
dynamically allocated array.. When running the program, it completes
successfully, but valgrind is finding an error. I receive Invalid read of
size 8 when my resize function is called.
void sequence::resize(size_type new_capacity){
if (new_capacity == capacity){
return;
}else {
if (new_capacity < capacity)
used = new_capacity;
capacity = new_capacity;
value_type* new_vals;
new_vals = new value_type[capacity];
for (int i=0;i<used;i++){
new_vals[i] = data[i];
}
cout<<endl;
data = new_vals;
}
}
Here is the error I am receiving in my test program:
==1919== Invalid read of size 8
==1919== at 0x400DB3: main_savitch_4::sequence::resize(unsigned long)
(sequence2.cxx:44)
==1919== by 0x401091: main_savitch_4::sequence::attach(double const&)
(sequence2.cxx:95)
==1919== by 0x403232: test5() (sequence_exam2.cxx:538)
==1919== by 0x40414E: run_a_test(int, char const*, int (*)(), int)
(sequence_exam2.cxx:744)
==1919== by 0x404321: main (sequence_exam2.cxx:775)
==1919== Address 0x5a1ae50 is 0 bytes after a block of size 240 alloc'd
==1919== at 0x4C2C037: operator new[](unsigned long) (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==1919== by 0x400C33: main_savitch_4::sequence::sequence(unsigned long)
(sequence2.cxx:17)
==1919== by 0x4030AC: test5() (sequence_exam2.cxx:520)
==1919== by 0x40414E: run_a_test(int, char const*, int (*)(), int)
(sequence_exam2.cxx:744)
==1919== by 0x404321: main (sequence_exam2.cxx:775)
==1919==
I have tried running valgrind with --leak-check=full and
--read-var-info=yes and cannot determine why I am getting this error. Line
45 of resize is the one that reads: new_vals[i] = data[i];
Thanks!!!

Is there an overhead on parallel_for (Inter TBB) similar to the overhead we see on std::function?

Is there an overhead on parallel_for (Inter TBB) similar to the overhead
we see on std::function?

In this link std::function vs template there is a nice discussion about
the overhead of std::function. Basically, to avoid the 10x overhead caused
by heap allocation of the functor you pass to the std::function
constructor, you must use std::ref or std::cref.
Example taken from @CassioNeri answer that shows how pass lambdas to
std::function by reference.
float foo(std::function<float(float)> f) { return -1.0f * f(3.3f) + 666.0f; }
foo(std::cref([a,b,c](float arg){ return arg * 0.5f; }));
Now, Intel Thread Building Block library gives you the ability to parallel
evaluate loops using lambda/functors, as shown in the example below.
Example code:
#include "tbb/task_scheduler_init.h"
#include "tbb/blocked_range.h"
#include "tbb/parallel_for.h"
#include "tbb/tbb_thread.h"
#include <vector>
int main() {
tbb::task_scheduler_init init(tbb::tbb_thread::hardware_concurrency());
std::vector<double> a(1000);
std::vector<double> c(1000);
std::vector<double> b(1000);
std::fill(b.begin(), b.end(), 1);
std::fill(c.begin(), c.end(), 1);
auto f = [&](const tbb::blocked_range<size_t>& r) {
for(size_t j=r.begin(); j!=r.end(); ++j) a[j] = b[j] + c[j];
};
tbb::parallel_for(tbb::blocked_range<size_t>(0, 1000), f);
return 0;
}
So my question is: does Intel TBB parallel_for have the same kind of
overhead (heap allocation of the functors) that we see on std::function?
Should I pass my functors/lambdas by reference to parallel_for using
std::cref to speed up the code?

Why does PHP have 2 password hashing functions?

Why does PHP have 2 password hashing functions?

I've been doing some reading on password hashing lately, and I've found
that PHP has 2 password hashing funcitons: password_hash() and crypt()
crypt() looks more versatile and configurable and is what I personally
use, but I've read that password_hash() is better even though it only
takes 2 arguments and only uses 1 algorithm.
Can someone please inform me of any major differences between these 2
functions, or if one is more secure than the other when used correctly? If
there's no real difference, then can someone explain to me why there are 2
functions that appear to do the same thing, only one is better at it?

Ajax load in Wordpress theme for webcomic

Ajax load in Wordpress theme for webcomic

I'm trying to create a theme in Wordpress for my webcomics. The problem is
about a few usability features and good practices:
Ajax load in next/prev navigation
Keyboard navigation
URL changing
You can see all this features in a Wordpress.com theme:
http://paneldemo.wordpress.com/, but is no available for download.
My code now is static:
<div id="content">
<?php query_posts('showposts=1'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="post">
<?php //content here ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
<div class="post-nav">
<?php previous_post_link('<div class="prev-post">Next post:
<span>%link</span></div>'); ?>
<?php next_post_link('<div class="next-post">Previous post:
<span>%link</span></div>'); ?>
</div>
Any ideas? Thanks!