How to set viewcontroller as rootview in cocoa?
I am very new to cocoa application this question may be asked or
something, My question is i have appdelegate and mainwindow.xib i created
another view controller and called from appdelegate and it is running
good. Now my doubt is whether its possible to make the view controller as
root with out adding it to main window.xib. Whether its must to load our
view with mainwindow.xib?
am calling view controller like this
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
self.view = [[ViewController alloc] initWithNibName:@"ViewController"
bundle:nil];
[self.window.contentView addSubview:self.view.view];
self.view.view.frame = ((NSView*)self.window.contentView).bounds;
}
Butrick
Sunday, 1 September 2013
Serialization issues while sending struct over socket
Serialization issues while sending struct over socket
I am developing a Client/Server based on UDP I want to send different
messages to the client from the server. There are different C structures
defined for each message.
I would like to understand what is wrong in the way I am serializing the
data.
struct Task
{
int mType;
int tType;
int cCnt;
int* cId;
char data[128];
};
Serialization/Deserialization functions
unsigned char * serialize_int(unsigned char *buffer, int value)
{
buffer[0] = value >> 24;
buffer[1] = value >> 16;
buffer[2] = value >> 8;
buffer[3] = value;
return buffer + 4;
}
unsigned char * serialize_char(unsigned char *buffer, char value)
{
buffer[0] = value;
return buffer + 1;
}
int deserialize_int(unsigned char *buffer)
{
int value = 0;
value |= buffer[0] << 24;
value |= buffer[1] << 16;
value |= buffer[2] << 8;
value |= buffer[3];
return value;
}
char deserialize_char(unsigned char *buffer)
{
return buffer[0];
}
Sender side code to serialize the structure
unsigned char* serializeTask(unsigned char* msg, const Task* t)
{
msg = serialize_int(msg,t->mType);
msg = serialize_int(msg,t->tkType);
msg = serialize_int(msg,t->cCnt);
for(int i=0; i<t->cCnt; i++)
msg = serialize_int(msg,t->cId[i*4]);
for(int i=0; i<strlen(data); i++)
msg = serialize_char(msg,t->data[i]);
return msg;
}
Receiver side code to de-serialize data
printf("Msg type:%d\n", deserialize_int(message) );
printf("Task Type:%d\n", deserialize_int(message+4) );
printf("Task Count:%d\n", deserialize_int(message+8));
Output
Msg type:50364598 //Expected value is 3
Task Type:-2013036362 //Expected value is 1
Task Count:1745191094 //Expected value is 3
Question 1:
Why is the de-serialized value not same as expected?
Question 2:
How is serialization/de-serialization method different from memcpy?
Task t;
memcpy(&t, msg, sizeof(t)); //msg is unsigned char* holding the struct data
I am developing a Client/Server based on UDP I want to send different
messages to the client from the server. There are different C structures
defined for each message.
I would like to understand what is wrong in the way I am serializing the
data.
struct Task
{
int mType;
int tType;
int cCnt;
int* cId;
char data[128];
};
Serialization/Deserialization functions
unsigned char * serialize_int(unsigned char *buffer, int value)
{
buffer[0] = value >> 24;
buffer[1] = value >> 16;
buffer[2] = value >> 8;
buffer[3] = value;
return buffer + 4;
}
unsigned char * serialize_char(unsigned char *buffer, char value)
{
buffer[0] = value;
return buffer + 1;
}
int deserialize_int(unsigned char *buffer)
{
int value = 0;
value |= buffer[0] << 24;
value |= buffer[1] << 16;
value |= buffer[2] << 8;
value |= buffer[3];
return value;
}
char deserialize_char(unsigned char *buffer)
{
return buffer[0];
}
Sender side code to serialize the structure
unsigned char* serializeTask(unsigned char* msg, const Task* t)
{
msg = serialize_int(msg,t->mType);
msg = serialize_int(msg,t->tkType);
msg = serialize_int(msg,t->cCnt);
for(int i=0; i<t->cCnt; i++)
msg = serialize_int(msg,t->cId[i*4]);
for(int i=0; i<strlen(data); i++)
msg = serialize_char(msg,t->data[i]);
return msg;
}
Receiver side code to de-serialize data
printf("Msg type:%d\n", deserialize_int(message) );
printf("Task Type:%d\n", deserialize_int(message+4) );
printf("Task Count:%d\n", deserialize_int(message+8));
Output
Msg type:50364598 //Expected value is 3
Task Type:-2013036362 //Expected value is 1
Task Count:1745191094 //Expected value is 3
Question 1:
Why is the de-serialized value not same as expected?
Question 2:
How is serialization/de-serialization method different from memcpy?
Task t;
memcpy(&t, msg, sizeof(t)); //msg is unsigned char* holding the struct data
merge arrays without reindexing keys
merge arrays without reindexing keys
I have two arrays that I want to merge recursively, so adding arrays is
not an option. This is simple example without multilevels to demonstrate
the problem:
$a1 = Array(
5 => 'pronoun'
)
$a2 = Array(
2 => 'verb',
3 => 'noun'
)
$r = array_merge_recursive($a1, $a2)
And I want to get that resulting array:
Array(
5 => 'pronoun'
2 => 'verb',
3 => 'noun'
)
My problem is that array_merge_recursive function reindixes keys, and I
get the following:
Array(
0 => 'pronoun'
1 => 'verb',
2 => 'noun'
)
I understand that's happening because all my keys are numeric. So I tried
to make them string when adding but it doesn't seem to be working
properly:
$a1[(string)7] = 'some value';
The key - 7 - is still number, or at least that's how it is displayed in
debugger - $a1[7] and not $a1['7']. Any advice?
I have two arrays that I want to merge recursively, so adding arrays is
not an option. This is simple example without multilevels to demonstrate
the problem:
$a1 = Array(
5 => 'pronoun'
)
$a2 = Array(
2 => 'verb',
3 => 'noun'
)
$r = array_merge_recursive($a1, $a2)
And I want to get that resulting array:
Array(
5 => 'pronoun'
2 => 'verb',
3 => 'noun'
)
My problem is that array_merge_recursive function reindixes keys, and I
get the following:
Array(
0 => 'pronoun'
1 => 'verb',
2 => 'noun'
)
I understand that's happening because all my keys are numeric. So I tried
to make them string when adding but it doesn't seem to be working
properly:
$a1[(string)7] = 'some value';
The key - 7 - is still number, or at least that's how it is displayed in
debugger - $a1[7] and not $a1['7']. Any advice?
TypeError: contactList3 is undefined in soy compilation
TypeError: contactList3 is undefined in soy compilation
I'm passing data to closure template(soy) via Javascript (json) but
getting the about error in firebug.
// Simple html that starts the whole process
<html lang="en">
<head>
<title>Gigya Social Demo - getContacs</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.lightbox_me.js"></script>
<!-- add the soy js here-->
<script type="text/javascript" src="emailcontacts.js"></script>
<script type="text/javascript"
src="invite_emailcontacts_view.js"></script>
<script type="text/javascript">
function openLightbox() {
var data =
[{"provider":"Yahoo","firstName":"myname","lastName":"mysurname","nickname":"mynick","email":"email@hotmail.com","photoURL":"http://l.yimg.com/dh/ap/social/profile/profile_b10.png"}];
var invite = new InviteContactEmailView();
console.log(invite);
invite.open(data);
return this;
}
</script>
<style>
#contactsOverlay {
-moz-border-radius: 6px;
background: #eef2f7;
-webkit-border-radius: 6px;
border: 1px solid #536376;
-webkit-box-shadow: rgba(0,0,0,.6) 0px 2px 12px;
-moz-box-shadow: rgba(0,0,0,.6) 0px 2px 12px;;
padding: 14px 22px;
width: 400px;
position: relative;
display: none;
}
</head>
<body onLoad="openLightbox()">
<div id="contactsOverlay">
</body>
</html>
// soy invoker in file invite_emailcontacts_view.js
function InviteContactEmailView() {
this.template = {};
this.template.element = $('#contactsOverlay');
this.elementSelector = this.template.element;
}
InviteContactEmailView.prototype.open = function(contacts) {
this.elementSelector.lightbox_me({destroyOnClose: true, centered:
true, onLoad: testme(this.elementSelector, contacts) });
return this;
};
var testme = function(ele, contacts) {
ele.append(jive.invite.emailcontacts.create(contacts));
$('fieldset div').bind('click', function() {
var checkbox = $(this).find(':checkbox');
checkbox.attr('checked', !checkbox.attr('checked'));
});
}
// soy template (on compile resides in file: emailcontacts.js)
{namespace jive.invite.emailcontacts}
/**
* @param contacts
* @depends path=/var/www/statics/js/invite_emailcontacts_view.js
**/
{template .create}
{foreach $contact in $contacts}
<fieldset>
<div>
<div class="data"></div>
<input type="checkbox" id="checkbox">
</div>
</fieldset>
{/foreach}
{/template}
Any kind of help is greatly appreciated.
REgards
I'm passing data to closure template(soy) via Javascript (json) but
getting the about error in firebug.
// Simple html that starts the whole process
<html lang="en">
<head>
<title>Gigya Social Demo - getContacs</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.lightbox_me.js"></script>
<!-- add the soy js here-->
<script type="text/javascript" src="emailcontacts.js"></script>
<script type="text/javascript"
src="invite_emailcontacts_view.js"></script>
<script type="text/javascript">
function openLightbox() {
var data =
[{"provider":"Yahoo","firstName":"myname","lastName":"mysurname","nickname":"mynick","email":"email@hotmail.com","photoURL":"http://l.yimg.com/dh/ap/social/profile/profile_b10.png"}];
var invite = new InviteContactEmailView();
console.log(invite);
invite.open(data);
return this;
}
</script>
<style>
#contactsOverlay {
-moz-border-radius: 6px;
background: #eef2f7;
-webkit-border-radius: 6px;
border: 1px solid #536376;
-webkit-box-shadow: rgba(0,0,0,.6) 0px 2px 12px;
-moz-box-shadow: rgba(0,0,0,.6) 0px 2px 12px;;
padding: 14px 22px;
width: 400px;
position: relative;
display: none;
}
</head>
<body onLoad="openLightbox()">
<div id="contactsOverlay">
</body>
</html>
// soy invoker in file invite_emailcontacts_view.js
function InviteContactEmailView() {
this.template = {};
this.template.element = $('#contactsOverlay');
this.elementSelector = this.template.element;
}
InviteContactEmailView.prototype.open = function(contacts) {
this.elementSelector.lightbox_me({destroyOnClose: true, centered:
true, onLoad: testme(this.elementSelector, contacts) });
return this;
};
var testme = function(ele, contacts) {
ele.append(jive.invite.emailcontacts.create(contacts));
$('fieldset div').bind('click', function() {
var checkbox = $(this).find(':checkbox');
checkbox.attr('checked', !checkbox.attr('checked'));
});
}
// soy template (on compile resides in file: emailcontacts.js)
{namespace jive.invite.emailcontacts}
/**
* @param contacts
* @depends path=/var/www/statics/js/invite_emailcontacts_view.js
**/
{template .create}
{foreach $contact in $contacts}
<fieldset>
<div>
<div class="data"></div>
<input type="checkbox" id="checkbox">
</div>
</fieldset>
{/foreach}
{/template}
Any kind of help is greatly appreciated.
REgards
Saturday, 31 August 2013
install karmasphere plugin in netbeans
install karmasphere plugin in netbeans
I want to run a hadoop mapreduce program (for example WordCount) with
netbeans. I found that there is "karmasphere studio for hadoop" that is a
plugin in netbeans. I follow the bellow instruction to install the plugin
: http://www.hadoopstudio.org/home/installation-guide/ but when I add the
plugin name and url, the "karmasphere studio" does not appearnce in my
available plugins, so I can not download and install it. I have netbeans
7.3.1 with jdk7. anybody know what should I do?
I want to run a hadoop mapreduce program (for example WordCount) with
netbeans. I found that there is "karmasphere studio for hadoop" that is a
plugin in netbeans. I follow the bellow instruction to install the plugin
: http://www.hadoopstudio.org/home/installation-guide/ but when I add the
plugin name and url, the "karmasphere studio" does not appearnce in my
available plugins, so I can not download and install it. I have netbeans
7.3.1 with jdk7. anybody know what should I do?
Website not loading jQuery
Website not loading jQuery
I'm a new web developer, and at the suggestion of Richard Bovell at
JavaScript is Sexy, I've decided to test my skills by making a... well,
test!
I did the basic HTML, and I've written a function to display any given
question, and it works perfectly in JSFiddle.
However when I test it with PHPStorm (run it with my browser), it seems
like the JavaScript/jQuery is not loading.
In fact, when I use Chrome's error console, jQuery.min says, "failed to
load resources."
I'm using this code in my source:
<script
src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
I've also tried using this source:
<script type='text/javascript'
src='//code.jquery.com/jquery-1.10.1.js'></script>
but also not loading resource.
As a result, my entire JavaScript code is not working since it was jQuery
based.
If I load the link into my web browser it works perfectly fine, so it
doesn't seem like a network error.
Edit:
Here is my fiddle: http://jsfiddle.net/abustamam/3CY7g/
And the error reads:
Uncaught ReferenceError: $ is not defined script.js:2 (anonymous function)
script.js:2 Failed to load resource
file://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
Can anyone give me some pointers as to why jQuery isn't loading? Thanks!
Edit 2: Got the answer. http: is required! Thanks!
I'm a new web developer, and at the suggestion of Richard Bovell at
JavaScript is Sexy, I've decided to test my skills by making a... well,
test!
I did the basic HTML, and I've written a function to display any given
question, and it works perfectly in JSFiddle.
However when I test it with PHPStorm (run it with my browser), it seems
like the JavaScript/jQuery is not loading.
In fact, when I use Chrome's error console, jQuery.min says, "failed to
load resources."
I'm using this code in my source:
<script
src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
I've also tried using this source:
<script type='text/javascript'
src='//code.jquery.com/jquery-1.10.1.js'></script>
but also not loading resource.
As a result, my entire JavaScript code is not working since it was jQuery
based.
If I load the link into my web browser it works perfectly fine, so it
doesn't seem like a network error.
Edit:
Here is my fiddle: http://jsfiddle.net/abustamam/3CY7g/
And the error reads:
Uncaught ReferenceError: $ is not defined script.js:2 (anonymous function)
script.js:2 Failed to load resource
file://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
Can anyone give me some pointers as to why jQuery isn't loading? Thanks!
Edit 2: Got the answer. http: is required! Thanks!
What hash function should I use for a bloom-filter with +128-bit keys?
What hash function should I use for a bloom-filter with +128-bit keys?
https://github.com/joeyrobert/bloomfilter uses Random class for the hash
function which is a performance killer.
What I'm trying to do is input the class with byte[]s instead of a generic
argument(T) and get rid of
private int Hash(T item) {
return item.GetHashCode();
}
I know there is a huge performance benefit but I have no idea how to replace
_bitArray[_random.Next(_bitSize)] = true;
With some non-retarded line of code that doesn't take thousands of CPU
cycles for every single bit.
I know there are lots of other problems with the code that can make it
faster/safer.I have them(mostly) fixed and just got stuck on the last one
before pushing my changes.
Any help is really appreciated.
https://github.com/joeyrobert/bloomfilter uses Random class for the hash
function which is a performance killer.
What I'm trying to do is input the class with byte[]s instead of a generic
argument(T) and get rid of
private int Hash(T item) {
return item.GetHashCode();
}
I know there is a huge performance benefit but I have no idea how to replace
_bitArray[_random.Next(_bitSize)] = true;
With some non-retarded line of code that doesn't take thousands of CPU
cycles for every single bit.
I know there are lots of other problems with the code that can make it
faster/safer.I have them(mostly) fixed and just got stuck on the last one
before pushing my changes.
Any help is really appreciated.
Subscribe to:
Posts (Atom)