How to generate specific Ids for usb port in java?
I am developing an application using java. I am connecting 10 usb devices
through external usb port. I want a pecific ID when I connect a device
with specific port so that If I connect device on 10th port I should get a
specific Id for that port. Which will help me in showing that device in
10th position only. I tried Jusb and other similar third party APIs but
didn't working out. Please suggest some technique to it.
Wednesday, 21 August 2013
How to start CSS3 animation when it is in view port
How to start CSS3 animation when it is in view port
I have a bar chart that animates with CSS3 and the animation currently
activates as the page loads.
Since the bar chart isn't in view when page loads, you'd have to scroll
down to see it and by the time you get to it, the animation has already
loaded. So what I am trying to do is, have the CSS3 animation activate
when someone scrolls to it by using js.
Here is a sample of what I am trying to do:
jsfiddle.net
I think I am miss something or doing something wrong in .js and .css.
// Check if it's time to start the animation.
function checkAnimation() {
var $elem = $('.skiller #skill');
// If the animation has already been started
if ($elem.hasClass('html5')) return;
if (isElementInViewport($elem)) {
// Start the animation
$elem.addClass('html5');
}
}
Thank you guys in advance!
I have a bar chart that animates with CSS3 and the animation currently
activates as the page loads.
Since the bar chart isn't in view when page loads, you'd have to scroll
down to see it and by the time you get to it, the animation has already
loaded. So what I am trying to do is, have the CSS3 animation activate
when someone scrolls to it by using js.
Here is a sample of what I am trying to do:
jsfiddle.net
I think I am miss something or doing something wrong in .js and .css.
// Check if it's time to start the animation.
function checkAnimation() {
var $elem = $('.skiller #skill');
// If the animation has already been started
if ($elem.hasClass('html5')) return;
if (isElementInViewport($elem)) {
// Start the animation
$elem.addClass('html5');
}
}
Thank you guys in advance!
Tuesday, 20 August 2013
Are short-lived files flushed to disk? [migrated]
Are short-lived files flushed to disk? [migrated]
My program creates many small short-lived files. They are typically
deleted within a second after creation. The files are in an ext4 file
system backed by a real hard disk. I know that Linux periodically flushes
(pdflush) dirty pages to disk. Since my files are short-lived, most likely
they are not cached by pdflush. My question is, does my program cause a
lot of disk writes? My concern is my hard disk's life.
Since the files are small, let's assume the sum of their size is smaller
than dirty_bytes and dirty_background_bytes.
Ext4 has default journal turned on, i.e. metadata journal. I also want to
know whether the metadata or the data is written to disk.
My program creates many small short-lived files. They are typically
deleted within a second after creation. The files are in an ext4 file
system backed by a real hard disk. I know that Linux periodically flushes
(pdflush) dirty pages to disk. Since my files are short-lived, most likely
they are not cached by pdflush. My question is, does my program cause a
lot of disk writes? My concern is my hard disk's life.
Since the files are small, let's assume the sum of their size is smaller
than dirty_bytes and dirty_background_bytes.
Ext4 has default journal turned on, i.e. metadata journal. I also want to
know whether the metadata or the data is written to disk.
Markov Chain discarding balls from urn
Markov Chain discarding balls from urn
The following question has me stumped. Any ideas on how to get started?
An urn contains $n$ green balls and $n+2$ red balls. A ball is picked at
random: if it is green then a red balls is also removed and both are
discarded; if it is red, then it is replaced together with an extra red
and an extra green ball. This is repeated until there are no green balls
in the urn. Show that the probability the process terminates is $1/(n+1)$.
The following question has me stumped. Any ideas on how to get started?
An urn contains $n$ green balls and $n+2$ red balls. A ball is picked at
random: if it is green then a red balls is also removed and both are
discarded; if it is red, then it is replaced together with an extra red
and an extra green ball. This is repeated until there are no green balls
in the urn. Show that the probability the process terminates is $1/(n+1)$.
How to load modal dialog with layout content?
How to load modal dialog with layout content?
How and where should I define region or function with modal dialog
functionality so that I can load it in one or two specified cases in views
e.g. like through MyApp.modal.show(content)?
Example:
var ModalRegion = Backbone.Marionette.Region.extend({
el: "#modal",
constructor: function(){
_.bindAll(this);
Backbone.Marionette.Region.prototype.constructor.apply(this, arguments);
this.on("view:show", this.showModal, this);
},
getEl: function(selector){
var $el = $(selector);
$el.on("hidden", this.close);
return $el;
},
showModal: function(view){
view.on("close", this.hideModal, this);
this.$el.modal('show');
},
hideModal: function(){
this.$el.modal('hide');
}
});
How to use it in this view?
MyApp.Views.Layouts.Unauthenticated = Backbone.Marionette.Layout.extend({
template: 'layouts/unauthenticated',
regions: {
//modal: ModalRegion, //Region must be specified as a selector string
or an object with selector property
tabContent: '#tab-content'
},
events: {
'click #showLogin': 'showLogin'
},
views: {},
showLogin: function(){
this.views.login = BD.Views.Unauthenticated.Login;
MyApp.modal.show(new this.views.login);
},
How and where should I define region or function with modal dialog
functionality so that I can load it in one or two specified cases in views
e.g. like through MyApp.modal.show(content)?
Example:
var ModalRegion = Backbone.Marionette.Region.extend({
el: "#modal",
constructor: function(){
_.bindAll(this);
Backbone.Marionette.Region.prototype.constructor.apply(this, arguments);
this.on("view:show", this.showModal, this);
},
getEl: function(selector){
var $el = $(selector);
$el.on("hidden", this.close);
return $el;
},
showModal: function(view){
view.on("close", this.hideModal, this);
this.$el.modal('show');
},
hideModal: function(){
this.$el.modal('hide');
}
});
How to use it in this view?
MyApp.Views.Layouts.Unauthenticated = Backbone.Marionette.Layout.extend({
template: 'layouts/unauthenticated',
regions: {
//modal: ModalRegion, //Region must be specified as a selector string
or an object with selector property
tabContent: '#tab-content'
},
events: {
'click #showLogin': 'showLogin'
},
views: {},
showLogin: function(){
this.views.login = BD.Views.Unauthenticated.Login;
MyApp.modal.show(new this.views.login);
},
finding occurrence of all words in text
finding occurrence of all words in text
I want to find occurrences of words in a string. Currently, I'm doing this
by splitting the string on space and finding all occurrences from a given
list of words. However, this obviously fails when the strings don't have
any whitespace in them. My strings could be of various kind and I would
like to know one way which captures everything.
Below is my code
mytext = "this is just a test for foo bar"
words = ["foo", "test", "awesome"]
mytextwords = mytext.toLowerCase().split(/\s+/)
assert ["foo", "test"] == words.findAll{it.toLowerCase() in mytextwords}
The above works fine, however, it won't work when mytext is any of the below:
mytext = "/this/is/just/a/test/for/foo/bar" //foo and test should be found
mytext = "this is just a+test for foo+bar" //foo and test should be found
mytext = "this is just (atest) for /foo //only foo and not test should be
found
Question
I guess it would be best if the string can be split on white space and all
other special characters.
I want to find occurrences of words in a string. Currently, I'm doing this
by splitting the string on space and finding all occurrences from a given
list of words. However, this obviously fails when the strings don't have
any whitespace in them. My strings could be of various kind and I would
like to know one way which captures everything.
Below is my code
mytext = "this is just a test for foo bar"
words = ["foo", "test", "awesome"]
mytextwords = mytext.toLowerCase().split(/\s+/)
assert ["foo", "test"] == words.findAll{it.toLowerCase() in mytextwords}
The above works fine, however, it won't work when mytext is any of the below:
mytext = "/this/is/just/a/test/for/foo/bar" //foo and test should be found
mytext = "this is just a+test for foo+bar" //foo and test should be found
mytext = "this is just (atest) for /foo //only foo and not test should be
found
Question
I guess it would be best if the string can be split on white space and all
other special characters.
How X11/Qt/Gtk/ implements scrolling
How X11/Qt/Gtk/ implements scrolling
I hope someone can help me with this: how X11/Qt/Gtk implements scrolling?
I do not want to know how to use their APIs to use scroll on a program,
but how the APIs implements scrolling.
For instance, the program receives a request to redraw itself because the
user had scrolled only a single line down/up. Do the program redraw only
this single line?
Does it uses blit operations? 3D and/or 2D acceleration? Most important:
where can I find references about this subject?
This question could also be: how to implement scrolling in your homemade
windowing system.
If someone needs to know: - custom operating system made from scratch with
assembly/C - video using VGA
I hope someone can help me with this: how X11/Qt/Gtk implements scrolling?
I do not want to know how to use their APIs to use scroll on a program,
but how the APIs implements scrolling.
For instance, the program receives a request to redraw itself because the
user had scrolled only a single line down/up. Do the program redraw only
this single line?
Does it uses blit operations? 3D and/or 2D acceleration? Most important:
where can I find references about this subject?
This question could also be: how to implement scrolling in your homemade
windowing system.
If someone needs to know: - custom operating system made from scratch with
assembly/C - video using VGA
Subscribe to:
Posts (Atom)